directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r414289 - /directory/branches/apacheds/noback-experiment/server-main/src/main/java/org/apache/directory/server/Service.java
Date Wed, 14 Jun 2006 15:25:53 GMT
Author: akarasulu
Date: Wed Jun 14 08:25:53 2006
New Revision: 414289

URL: http://svn.apache.org/viewvc?rev=414289&view=rev
Log:
making sure the backend subsystem is not even started at all

Modified:
    directory/branches/apacheds/noback-experiment/server-main/src/main/java/org/apache/directory/server/Service.java

Modified: directory/branches/apacheds/noback-experiment/server-main/src/main/java/org/apache/directory/server/Service.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/noback-experiment/server-main/src/main/java/org/apache/directory/server/Service.java?rev=414289&r1=414288&r2=414289&view=diff
==============================================================================
--- directory/branches/apacheds/noback-experiment/server-main/src/main/java/org/apache/directory/server/Service.java
(original)
+++ directory/branches/apacheds/noback-experiment/server-main/src/main/java/org/apache/directory/server/Service.java
Wed Jun 14 08:25:53 2006
@@ -17,25 +17,31 @@
 package org.apache.directory.server;
 
 
-import java.io.File;
-import java.util.Properties;
-
-import javax.naming.Context;
-import javax.naming.directory.InitialDirContext;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
 
 import org.apache.directory.daemon.DaemonApplication;
 import org.apache.directory.daemon.InstallationLayout;
-import org.apache.directory.server.configuration.MutableServerStartupConfiguration;
-import org.apache.directory.server.core.configuration.ShutdownConfiguration;
-import org.apache.directory.server.core.configuration.SyncConfiguration;
-import org.apache.directory.server.jndi.ServerContextFactory;
+import org.apache.directory.server.ldap.LdapProtocolProvider;
+import org.apache.directory.shared.ldap.exception.LdapConfigurationException;
+import org.apache.directory.shared.ldap.message.extended.NoticeOfDisconnect;
+import org.apache.mina.common.DefaultIoFilterChainBuilder;
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.IoFilter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteFuture;
+import org.apache.mina.filter.ThreadPoolFilter;
+import org.apache.mina.transport.socket.nio.DatagramAcceptor;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
+import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.FileSystemXmlApplicationContext;
-
 
 /**
  * DirectoryServer bean used by both the daemon code and by the ServerMain here.
@@ -45,92 +51,66 @@
  */
 public class Service implements DaemonApplication
 {
-    private static final Logger log = LoggerFactory.getLogger( Service.class );
-    private Properties env;
-    private Thread workerThread = null;
-    private SynchWorker worker = new SynchWorker();
-    private boolean startNoWait = false;
+    public static final String BANNER = "Experimental ApacheDS without backend for profiling\n";
+    private static final Logger log = LoggerFactory.getLogger( Service.class.getName() );
 
+    protected static final IoAcceptor tcpAcceptor = new SocketAcceptor();
+    protected static final IoAcceptor udpAcceptor = new DatagramAcceptor();
 
-    public void init( InstallationLayout install, String[] args ) throws Exception
+    static
     {
-        printBanner();
-        long startTime = System.currentTimeMillis();
-        MutableServerStartupConfiguration cfg;
+        IoFilter threadPool = new ThreadPoolFilter();
+        tcpAcceptor.getFilterChain().addFirst( "threadPool", threadPool );
+        udpAcceptor.getFilterChain().addFirst( "threadPool", threadPool );
+    }
 
-        if ( install != null )
-        {
-            log.info( "server: loading settings from ", install.getConfigurationFile() );
-            ApplicationContext factory = null;
-            factory = new FileSystemXmlApplicationContext( install.getConfigurationFile().toURL().toString()
);
-            cfg = ( MutableServerStartupConfiguration ) factory.getBean( "configuration"
);
-            env = ( Properties ) factory.getBean( "environment" );
-        }
-        else if ( args.length > 0 && new File( args[0] ).exists() ) // hack that
takes server.xml file argument
-        {
-            log.info( "server: loading settings from ", args[0] );
-            ApplicationContext factory = null;
-            factory = new FileSystemXmlApplicationContext( new File( args[0] ).toURL().toString()
);
-            cfg = ( MutableServerStartupConfiguration ) factory.getBean( "configuration"
);
-            env = ( Properties ) factory.getBean( "environment" );
-        }
-        else
-        {
-            log.info( "server: using default settings ..." );
-            env = new Properties();
-            cfg = new MutableServerStartupConfiguration();
-        }
+    private static boolean ldapStarted;
 
-        env.setProperty( Context.PROVIDER_URL, "ou=system" );
-        env.setProperty( Context.INITIAL_CONTEXT_FACTORY, ServerContextFactory.class.getName()
);
 
-        if ( install != null )
-        {
-            cfg.setWorkingDirectory( install.getPartitionsDirectory() );
-        }
+    public void init( InstallationLayout install, String[] args ) throws Exception
+    {
+        System.out.println( BANNER );
+        // Register all extended operation handlers.
+        LdapProtocolProvider protocolProvider = new LdapProtocolProvider( new Hashtable()
);
 
-        env.putAll( cfg.toJndiEnvironment() );
-        new InitialDirContext( env );
+        try
+        {
+            // Disable the disconnection of the clients on unbind
+            SocketAcceptorConfig acceptorCfg = new SocketAcceptorConfig();
+            acceptorCfg.setDisconnectOnUnbind( false );
+            acceptorCfg.setReuseAddress( true );
+            acceptorCfg.setFilterChainBuilder( new DefaultIoFilterChainBuilder() );
 
-        workerThread = new Thread( worker, "SynchWorkerThread" );
+            tcpAcceptor.bind( new InetSocketAddress( 10389 ), protocolProvider.getHandler(),
acceptorCfg );
 
-        if ( log.isInfoEnabled() )
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "Successful bind of an LDAP Service (" + 10389 + ") is complete."
);
+            }
+        }
+        catch ( IOException e )
         {
-            log.info( "server: started in {} milliseconds", ( System.currentTimeMillis()
- startTime ) + "" );
+            String msg = "Failed to bind an LDAP service (" + 10389 + ") to the service registry.";
+            LdapConfigurationException lce = new LdapConfigurationException( msg );
+            lce.setRootCause( e );
+            log.error( msg, e );
+            throw lce;
         }
     }
 
 
-    public void synch() throws Exception
-    {
-        env.putAll( new SyncConfiguration().toJndiEnvironment() );
-        new InitialDirContext( env );
-    }
-
-
     public void start()
     {
-        workerThread.start();
-        return;
     }
 
 
     public void stop( String[] args ) throws Exception
     {
-        worker.stop = true;
-        synchronized ( worker.lock )
-        {
-            worker.lock.notify();
-        }
-
-        while ( startNoWait && workerThread.isAlive() )
+        if ( ldapStarted )
         {
-            log.info( "Waiting for SynchWorkerThread to die." );
-            workerThread.join( 500 );
+            stopLDAP0( 10389 );
+            ldapStarted = false;
         }
-
-        env.putAll( new ShutdownConfiguration().toJndiEnvironment() );
-        new InitialDirContext( env );
     }
 
 
@@ -138,50 +118,59 @@
     {
     }
 
-    class SynchWorker implements Runnable
+
+    private void stopLDAP0( int port )
     {
-        Object lock = new Object();
-        boolean stop = false;
+        try
+        {
+            // we should unbind the service before we begin sending the notice 
+            // of disconnect so new connections are not formed while we process
+            List writeFutures = new ArrayList();
+
+            // If the socket has already been unbound as with a successful 
+            // GracefulShutdownRequest then this will complain that the service
+            // is not bound - this is ok because the GracefulShutdown has already
+            // sent notices to to the existing active sessions
+            List sessions = null;
+            try
+            {
+                sessions = new ArrayList( tcpAcceptor.getManagedSessions( new InetSocketAddress(
port ) ) );
+            }
+            catch ( IllegalArgumentException e )
+            {
+                log.warn( "Seems like the LDAP service (" + port + ") has already been unbound."
);
+                return;
+            }
 
+            tcpAcceptor.unbind( new InetSocketAddress( port ) );
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "Unbind of an LDAP service (" + port + ") is complete." );
+                log.info( "Sending notice of disconnect to existing clients sessions." );
+            }
 
-        public void run()
-        {
-            while ( !stop )
+            // Send Notification of Disconnection messages to all connected clients.
+            if ( sessions != null )
             {
-                synchronized ( lock )
+                for ( Iterator i = sessions.iterator(); i.hasNext(); )
                 {
-                    try
-                    {
-                        lock.wait( 20000 );
-                    }
-                    catch ( InterruptedException e )
-                    {
-                        log.warn( "SynchWorker failed to wait on lock.", e );
-                    }
+                    IoSession session = ( IoSession ) i.next();
+                    writeFutures.add( session.write( NoticeOfDisconnect.UNAVAILABLE ) );
                 }
+            }
 
-                try
-                {
-                    synch();
-                }
-                catch ( Exception e )
-                {
-                    log.error( "SynchWorker failed to synch directory.", e );
-                }
+            // And close the connections when the NoDs are sent.
+            Iterator sessionIt = sessions.iterator();
+            for ( Iterator i = writeFutures.iterator(); i.hasNext(); )
+            {
+                WriteFuture future = ( WriteFuture ) i.next();
+                future.join( 1000 );
+                ( ( IoSession ) sessionIt.next() ).close();
             }
         }
-    }
-
-    public static final String BANNER = "           _                     _          ____
 ____   \n"
-        + "          / \\   _ __   __ _  ___| |__   ___|  _ \\/ ___|  \n"
-        + "         / _ \\ | '_ \\ / _` |/ __| '_ \\ / _ \\ | | \\___ \\   \n"
-        + "        / ___ \\| |_) | (_| | (__| | | |  __/ |_| |___) |  \n"
-        + "       /_/   \\_\\ .__/ \\__,_|\\___|_| |_|\\___|____/|____/   \n"
-        + "               |_|                                                           
   \n";
-
-
-    public static void printBanner()
-    {
-        System.out.println( BANNER );
+        catch ( Exception e )
+        {
+            log.warn( "Failed to sent NoD.", e );
+        }
     }
 }



Mime
View raw message