1 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 38 public class ServerMain 39 { 40 41 private static final int LDAP_PORT = 389; 42 43 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 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 } 111 | Popular Tags |