KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ldap > server > ServerMain


1 /*
2  * Copyright 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package org.apache.ldap.server;
18
19
20 import java.io.File JavaDoc;
21 import java.util.Properties JavaDoc;
22
23 import javax.naming.Context JavaDoc;
24 import javax.naming.NamingException JavaDoc;
25 import javax.naming.directory.InitialDirContext JavaDoc;
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 JavaDoc[] args )
50     {
51         long startTime = System.currentTimeMillis();
52         Properties JavaDoc env;
53
54         if ( args.length > 0 )
55         {
56             System.out.println( "server: loading properties from " + args[0] );
57             env = PropertiesUtils.getProperties( new File JavaDoc( args[0] ) );
58         }
59         else
60         {
61             System.out.println( "server: using default properties ..." );
62             env = new Properties JavaDoc();
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 JavaDoc( env );
77         }
78         catch ( NamingException JavaDoc 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                 // this is a big time cludge for now to just play
92
Thread.sleep( 20000 );
93
94                 try
95                 {
96                     env.setProperty( EnvKeys.SYNC, "true" );
97                     new InitialDirContext JavaDoc( env );
98                 }
99                 catch ( NamingException JavaDoc e )
100                 {
101                     e.printStackTrace();
102                 }
103             }
104             catch ( InterruptedException JavaDoc e )
105             {
106                 e.printStackTrace();
107             }
108         }
109     }
110 }
111
Popular Tags