1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server;
18
19
20 import java.io.File;
21 import java.util.Properties;
22
23 import javax.naming.Context;
24 import javax.naming.NamingException;
25 import javax.naming.directory.InitialDirContext;
26
27 import org.apache.ldap.common.util.PropertiesUtils;
28 import org.apache.ldap.server.jndi.EnvKeys;
29
30
31 /***
32 * The command line main for the server. Warning this used to be a simple test
33 * case so there really is not much here.
34 *
35 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
36 * @version $Rev$
37 */
38 public class ServerMain
39 {
40 /*** the default LDAP port to use */
41 private static final int LDAP_PORT = 389;
42
43 /***
44 * Takes a single argument, an optional properties file to load with server
45 * startup settings.
46 *
47 * @param args the arguments
48 */
49 public static void main( String[] args )
50 {
51 long startTime = System.currentTimeMillis();
52 Properties env;
53
54 if ( args.length > 0 )
55 {
56 System.out.println( "server: loading properties from " + args[0] );
57 env = PropertiesUtils.getProperties( new File( args[0] ) );
58 }
59 else
60 {
61 System.out.println( "server: using default properties ..." );
62 env = new Properties();
63 }
64
65 if ( ! env.containsKey( EnvKeys.LDAP_PORT ) )
66 {
67 int port = LDAP_PORT;
68 env.setProperty( EnvKeys.LDAP_PORT, String.valueOf( port ) );
69 }
70
71 env.setProperty( Context.PROVIDER_URL, "ou=system" );
72 env.setProperty( Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.ServerContextFactory" );
73
74 try
75 {
76 new InitialDirContext( env );
77 }
78 catch ( NamingException e )
79 {
80 e.printStackTrace();
81 }
82
83 System.out.println( "server: started in "
84 + ( System.currentTimeMillis() - startTime )
85 + " milliseconds");
86
87 while ( true )
88 {
89 try
90 {
91
92 Thread.sleep( 20000 );
93
94 try
95 {
96 env.setProperty( EnvKeys.SYNC, "true" );
97 new InitialDirContext( env );
98 }
99 catch ( NamingException e )
100 {
101 e.printStackTrace();
102 }
103 }
104 catch ( InterruptedException e )
105 {
106 e.printStackTrace();
107 }
108 }
109 }
110 }