directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r372980 - in /directory/trunks/apacheds/standalone: daemon/src/main/java/org/apache/directory/server/standalone/daemon/ installers/plugin/src/main/resources/org/apache/directory/server/standalone/installers/ installers/plugin/src/main/resou...
Date Fri, 27 Jan 2006 20:47:46 GMT
Author: akarasulu
Date: Fri Jan 27 12:47:33 2006
New Revision: 372980

URL: http://svn.apache.org/viewcvs?rev=372980&view=rev
Log:
Refactored the daemon bootstrapper ...

 o factored out invocation of lifecycle methods to LifecycleInvoker
 o separated jsvc entry points, procrun entry points and main() entry point
   from bootstrapper for clarity using the following classes respectively:
     - JsvcBootstrapper
     - ProcrunBootstrapper
     - MainBootstrapper
 o updated bootstrapper.jar pom to make MainBootstrapper the target for 
   executable jar file
 o created new DaemonApplication interface used by LCInvoker which takes
   different arguments for methods
 o now arguments are passed to the DaemonApplication shifted with home 
   directory and command removed when calling the DaemonApplication
 o updated simple/main to account for these refactorings


Added:
    directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/DaemonApplication.java
    directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/LifecycleInvoker.java
      - copied, changed from r372795, directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ApplicationLifecycleInvoker.java
Removed:
    directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ApplicationLifecycleInvoker.java
Modified:
    directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ExitCodes.java
    directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/JsvcBootstrapper.java
    directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/MainBootstrapper.java
    directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ProcrunBootstrapper.java
    directory/trunks/apacheds/standalone/installers/plugin/src/main/resources/org/apache/directory/server/standalone/installers/inno/install.iss
    directory/trunks/apacheds/standalone/installers/plugin/src/main/resources/org/apache/directory/server/standalone/installers/template.init
    directory/trunks/apacheds/standalone/simple/main/src/main/java/org/apache/ldap/server/DirectoryServer.java
    directory/trunks/apacheds/standalone/simple/main/src/main/java/org/apache/ldap/server/ServerMain.java

Added: directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/DaemonApplication.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/DaemonApplication.java?rev=372980&view=auto
==============================================================================
--- directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/DaemonApplication.java
(added)
+++ directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/DaemonApplication.java
Fri Jan 27 12:47:33 2006
@@ -0,0 +1,58 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.directory.server.standalone.daemon;
+
+
+/**
+ * Interface used by DaemonApplications.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface DaemonApplication
+{
+    /**
+     * Threads should be created, along with sockets.  
+     * 
+     * @param layout the application's installation home layout 
+     * @param args the shifted arguments after the installation home path and 
+     * the command arguments are removed
+     */
+    void init( InstallationLayout layout, String[] args ) throws Exception;
+    
+    /**
+     * Start threads and bind sockets here.  If nowait is toggled this method 
+     * should not return until the server is ready to be shutdown.
+     * 
+     * @param nowait true if this method should return control immediately, false
+     * if it should block until it is ready to be shutdown
+     */
+    void start( boolean nowait );
+    
+    /**
+     * Stop threads and close sockets opened in start() here.
+     * 
+     * @param args shifted arguments without installation path or stop command
+     * @throws Exception 
+     */
+    void stop( String[] args ) throws Exception;
+    
+    /**
+     * The application should destroy resources created in init() here.
+     */
+    void destroy();
+}

Modified: directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ExitCodes.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ExitCodes.java?rev=372980&r1=372979&r2=372980&view=diff
==============================================================================
--- directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ExitCodes.java
(original)
+++ directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ExitCodes.java
Fri Jan 27 12:47:33 2006
@@ -37,4 +37,5 @@
     int BAD_ARGUMENTS = 10;
     int BAD_COMMAND = 11;
     int UNKNOWN = 12;
+    int INVOCATION = 13;
 }

Modified: directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/JsvcBootstrapper.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/JsvcBootstrapper.java?rev=372980&r1=372979&r2=372980&view=diff
==============================================================================
--- directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/JsvcBootstrapper.java
(original)
+++ directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/JsvcBootstrapper.java
Fri Jan 27 12:47:33 2006
@@ -33,7 +33,8 @@
 public class JsvcBootstrapper implements Daemon
 {
     private final static Logger log = LoggerFactory.getLogger( JsvcBootstrapper.class );
-    private ApplicationLifecycleInvoker application;
+    private static final String[] EMPTY_STRARRAY = new String[0];
+    private LifecycleInvoker invoker;
     
     
     public void init( DaemonContext arg ) throws Exception
@@ -49,13 +50,22 @@
             log.debug( buf.toString() );
         }
 
-        if ( application == null )
+        if ( invoker == null )
         {
-            application = new ApplicationLifecycleInvoker( arg.getArguments()[0], 
+            invoker = new LifecycleInvoker( arg.getArguments()[0], 
                 Thread.currentThread().getContextClassLoader() );
         }
         
-        application.callInit();
+        if ( arg.getArguments().length > 1 )
+        {
+            String[] shifted = new String[arg.getArguments().length-1];
+            System.arraycopy( arg.getArguments(), 1, shifted, 0, shifted.length );
+            invoker.callInit( shifted );
+        }
+        else
+        {
+            invoker.callInit( EMPTY_STRARRAY );
+        }
     }
     
 
@@ -72,32 +82,41 @@
             log.debug( buf.toString() );
         }
 
-        if ( application == null )
+        if ( invoker == null )
         {
-            application = new ApplicationLifecycleInvoker( args[0], Thread.currentThread().getContextClassLoader()
);
+            invoker = new LifecycleInvoker( args[0], Thread.currentThread().getContextClassLoader()
);
         }
         
-        application.callInit();
+        if ( args.length > 1 )
+        {
+            String[] shifted = new String[args.length-1];
+            System.arraycopy( args, 1, shifted, 0, shifted.length );
+            invoker.callInit( shifted );
+        }
+        else
+        {
+            invoker.callInit( EMPTY_STRARRAY );
+        }
     }
     
     
     public void start()
     {
         log.debug( "start() called" );
-        application.callStart( true );
+        invoker.callStart( true );
     }
 
 
     public void stop() throws Exception
     {
         log.debug( "stop() called" );
-        application.callStop();
+        invoker.callStop( EMPTY_STRARRAY );
     }
 
 
     public void destroy()
     {
         log.debug( "destroy() called" );
-        application.callDestroy();
+        invoker.callDestroy();
     }
 }

Copied: directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/LifecycleInvoker.java
(from r372795, directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ApplicationLifecycleInvoker.java)
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/LifecycleInvoker.java?p2=directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/LifecycleInvoker.java&p1=directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ApplicationLifecycleInvoker.java&r1=372795&r2=372980&rev=372980&view=diff
==============================================================================
--- directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ApplicationLifecycleInvoker.java
(original)
+++ directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/LifecycleInvoker.java
Fri Jan 27 12:47:33 2006
@@ -18,7 +18,6 @@
 
 
 import java.io.FileInputStream;
-import java.lang.reflect.Method;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.Properties;
@@ -33,21 +32,21 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class ApplicationLifecycleInvoker
+public class LifecycleInvoker
 {
-    private static Logger log = LoggerFactory.getLogger( ApplicationLifecycleInvoker.class
);
+    private static Logger log = LoggerFactory.getLogger( LifecycleInvoker.class );
     private static final String BOOTSTRAP_START_CLASS_PROP = "bootstrap.start.class";
     private static final String BOOTSTRAP_STOP_CLASS_PROP = "bootstrap.stop.class";
 
-    private Object startObject;
-    private Object stopObject;
+    private DaemonApplication startObject;
+    private DaemonApplication stopObject;
     private String startClassName;
     private String stopClassName;
     private final ClassLoader application;
     private final InstallationLayout layout;
 
 
-    public ApplicationLifecycleInvoker( String installationBase, ClassLoader parent )
+    public LifecycleInvoker( String installationBase, ClassLoader parent )
     {
         layout = new InstallationLayout( installationBase );
         
@@ -134,11 +133,9 @@
      * using the application ClassLoader.  The application ClassLoader is set as the 
      * context ClassLoader then the method is invoked.
      */
-    public void callInit()
+    public void callInit( String[] args )
     {
         Class clazz = null;
-        Method op = null;
-        
         Thread.currentThread().setContextClassLoader( application );
         try
         {
@@ -152,32 +149,22 @@
         
         try
         {
-            startObject = clazz.newInstance();
+            startObject = ( DaemonApplication ) clazz.newInstance();
         }
         catch ( Exception e )
         {
             log.error( "Could not instantiate " + startClassName, e );
             System.exit( ExitCodes.INSTANTIATION );
         }
-        
-        try
-        {
-            op = clazz.getMethod( "init", new Class[] { InstallationLayout.class } );
-        }
-        catch ( Exception e )
-        {
-            log.error( "Could not find init(InstallationLayout) method for " + startClassName,
e );
-            System.exit( ExitCodes.METHOD_LOOKUP );
-        }
-        
+
         try
         {
-            op.invoke( startObject, new Object[] { layout } );
+            startObject.init( layout, args );
         }
         catch ( Exception e )
         {
-            log.error( "Failed on " + startClassName + ".init(InstallationLayout)", e );
-            System.exit( ExitCodes.INITIALIZATION );
+            log.error( "Could not instantiate " + startClassName, e );
+            System.exit( ExitCodes.INVOCATION );
         }
     }
 
@@ -185,36 +172,14 @@
     public void callStart( boolean nowait )
     {
         Thread.currentThread().setContextClassLoader( application );
-        Class clazz = startObject.getClass();
-        Method op = null;
-        
-        try
-        {
-            op = clazz.getMethod( "start", new Class[] { Boolean.class } );
-        }
-        catch ( Exception e )
-        {
-            log.error( "Could not find start() method for " + clazz.getName(), e );
-            System.exit( ExitCodes.METHOD_LOOKUP );
-        }
-        
-        try
-        {
-            op.invoke( startObject, new Object[] { new Boolean( nowait ) } );
-        }
-        catch ( Exception e )
-        {
-            log.error( "Failed on " + clazz.getName() + ".start()", e );
-            System.exit( ExitCodes.START );
-        }
+        startObject.start( nowait );
     }
     
 
-    public void callStop()
+    public void callStop( String[] args )
     {
         Thread.currentThread().setContextClassLoader( application );
         Class clazz = null;
-        Method op = null;
 
         // Reuse the startObject if it is the same class
         if ( ! startClassName.equals( stopClassName ) )
@@ -231,7 +196,7 @@
             
             try
             {
-                stopObject = clazz.newInstance();
+                stopObject = ( DaemonApplication ) clazz.newInstance();
             }
             catch ( Exception e )
             {
@@ -244,25 +209,15 @@
             stopObject = startObject;
             clazz = startObject.getClass();
         }
-        
-        try
-        {
-            op = clazz.getMethod( "stop", null );
-        }
-        catch ( Exception e )
-        {
-            log.error( "Could not find stop() method for " + stopClassName, e );
-            System.exit( ExitCodes.METHOD_LOOKUP );
-        }
-        
+
         try
         {
-            op.invoke( stopObject, null );
+            stopObject.stop( args );
         }
         catch ( Exception e )
         {
-            log.error( "Failed on " + stopClassName + ".stop()", e );
-            System.exit( ExitCodes.STOP );
+            log.error( "Could not instantiate " + startClassName, e );
+            System.exit( ExitCodes.INVOCATION );
         }
     }
 
@@ -270,27 +225,6 @@
     public void callDestroy()
     {
         Thread.currentThread().setContextClassLoader( application );
-        Class clazz = stopObject.getClass();
-        Method op = null;
-        
-        try
-        {
-            op = clazz.getMethod( "destroy", null );
-        }
-        catch ( Exception e )
-        {
-            log.error( "Could not find destroy() method for " + clazz.getName(), e );
-            System.exit( ExitCodes.METHOD_LOOKUP );
-        }
-        
-        try
-        {
-            op.invoke( stopObject, null );
-        }
-        catch ( Exception e )
-        {
-            log.error( "Failed on " + clazz.getName() + ".destroy()", e );
-            System.exit( ExitCodes.DESTROY );
-        }
+        stopObject.destroy();
     }
 }

Modified: directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/MainBootstrapper.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/MainBootstrapper.java?rev=372980&r1=372979&r2=372980&view=diff
==============================================================================
--- directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/MainBootstrapper.java
(original)
+++ directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/MainBootstrapper.java
Fri Jan 27 12:47:33 2006
@@ -31,6 +31,7 @@
 public class MainBootstrapper
 {
     private static final Logger log = LoggerFactory.getLogger( MainBootstrapper.class );
+    private static final String[] EMPTY_STRARRAY = new String[0];
 
 
     public static void main( String[] args )
@@ -55,11 +56,11 @@
             }
         }
 
-        ApplicationLifecycleInvoker application = null;
+        LifecycleInvoker invoker = null;
         if ( args.length > 1 )
         {
-        	log.debug( "main(String[]) creating ApplicationLifecycleInvoker ... )" );
-            application = new ApplicationLifecycleInvoker( args[0], Thread.currentThread().getContextClassLoader()
);
+        	log.debug( "main(String[]) creating LifecycleInvoker ... )" );
+            invoker = new LifecycleInvoker( args[0], Thread.currentThread().getContextClassLoader()
);
         }
         else
         {
@@ -76,17 +77,35 @@
             if ( command.equalsIgnoreCase( "start" ) )
             {
                 log.debug( "calling application.callInit(String[]) from main(String[])" );
-                application.callInit();
+                if ( args.length > 2 )
+                {
+                    String[] shifted = new String[args.length-2];
+                    System.arraycopy( args, 2, shifted, 0, shifted.length );
+                    invoker.callInit( shifted );
+                }
+                else
+                {
+                    invoker.callInit( EMPTY_STRARRAY );
+                }
 
                 log.debug( "calling application.callStart(String[]) from main(String[])"
);
-                application.callStart( true );
+                invoker.callStart( true );
             }
             else if ( command.equalsIgnoreCase( "stop" ) )
             {
-                log.debug( "calling application.callStop() from main(String[])" );
-                application.callStop();
+                log.debug( "calling application.callStop(String[]) from main(String[])" );
+                if ( args.length > 2 )
+                {
+                    String[] shifted = new String[args.length-2];
+                    System.arraycopy( args, 2, shifted, 0, shifted.length );
+                    invoker.callStop( shifted );
+                }
+                else
+                {
+                    invoker.callStop( EMPTY_STRARRAY );
+                }
                 log.debug( "calling application.callDestroy() from main(String[])" );
-                application.callDestroy();
+                invoker.callDestroy();
             }
             else
             {
@@ -105,6 +124,6 @@
 
     private static void printHelp()
     {
-        System.err.println("java -jar bootstrapper.jar <install.home> [start|stop]");
+        System.err.println("java -jar bootstrapper.jar <install.home> [start|stop]
[apparg0 apparg1 ... appargN]");
     }
 }

Modified: directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ProcrunBootstrapper.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ProcrunBootstrapper.java?rev=372980&r1=372979&r2=372980&view=diff
==============================================================================
--- directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ProcrunBootstrapper.java
(original)
+++ directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ProcrunBootstrapper.java
Fri Jan 27 12:47:33 2006
@@ -31,6 +31,7 @@
 public class ProcrunBootstrapper
 {
     private final static Logger log = LoggerFactory.getLogger( ProcrunBootstrapper.class
);
+    private static final String[] EMPTY_STRARRAY = new String[0];
     
 
     public static void prunsrvStart( String[] args )
@@ -51,14 +52,23 @@
             System.exit( ExitCodes.BAD_ARGUMENTS );
         }
 
-        log.debug( "prunsrvStart(String[]) creating ApplicationLifecycleInvoker ... )" );
-        ApplicationLifecycleInvoker application = new ApplicationLifecycleInvoker( args[0],

+        log.debug( "prunsrvStart(String[]) creating LifecycleInvoker ... )" );
+        LifecycleInvoker invoker = new LifecycleInvoker( args[0], 
             Thread.currentThread().getContextClassLoader() );
 
-        log.debug( "prunsrvStart(String[]) invoking application.callInit())" );
-        application.callInit();
+        log.debug( "prunsrvStart(String[]) invoking application.callInit(String[]))" );
+        if ( args.length > 1 )
+        {
+            String[] shifted = new String[args.length-1];
+            System.arraycopy( args, 1, shifted, 0, shifted.length );
+            invoker.callInit( shifted );
+        }
+        else
+        {
+            invoker.callInit( EMPTY_STRARRAY );
+        }
         log.debug( "prunsrvStart(String[]) invoking bootstrapper.callStart())" );
-        application.callStart( false ); // must block on start (let the app decide how)
+        invoker.callStart( false ); // must block on start (let the app decide how)
     }
 
     
@@ -80,12 +90,21 @@
             System.exit( ExitCodes.BAD_ARGUMENTS );
         }
 
-        log.debug( "prunsrvStop(String[]) creating ApplicationLifecycleInvoker ... )" );
-        ApplicationLifecycleInvoker application = new ApplicationLifecycleInvoker( args[0],

+        log.debug( "prunsrvStop(String[]) creating LifecycleInvoker ... )" );
+        LifecycleInvoker application = new LifecycleInvoker( args[0], 
             Thread.currentThread().getContextClassLoader() );
         
-        log.debug( "prunsrvStop(String[]) invoking application.callStop())" );
-        application.callStop();
+        log.debug( "prunsrvStop(String[]) invoking application.callStop(String[]))" );
+        if ( args.length > 1 )
+        {
+            String[] shifted = new String[args.length-1];
+            System.arraycopy( args, 1, shifted, 0, shifted.length );
+            application.callStop( shifted );
+        }
+        else
+        {
+            application.callStop( EMPTY_STRARRAY );
+        }
         log.debug( "prunsrvStop(String[]) invoking application.callDestroy())" );
         application.callDestroy();
     }

Modified: directory/trunks/apacheds/standalone/installers/plugin/src/main/resources/org/apache/directory/server/standalone/installers/inno/install.iss
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/standalone/installers/plugin/src/main/resources/org/apache/directory/server/standalone/installers/inno/install.iss?rev=372980&r1=372979&r2=372980&view=diff
==============================================================================
--- directory/trunks/apacheds/standalone/installers/plugin/src/main/resources/org/apache/directory/server/standalone/installers/inno/install.iss
(original)
+++ directory/trunks/apacheds/standalone/installers/plugin/src/main/resources/org/apache/directory/server/standalone/installers/inno/install.iss
Fri Jan 27 12:47:33 2006
@@ -69,7 +69,7 @@
 Name: {group}\Test Service; Filename: {app}\bin\${app}.exe; IconIndex: 0
 
 [Run]
-Filename: {app}\bin\${app}.exe; WorkingDir: {app}\bin; Tasks: ; Languages: ; Parameters:
"//IS//${app.displayname} --Description=""${app.description} Service ${app.version} - ${app.url}""
--DisplayName=${app.displayname} --Install=""{app}\bin\${app}.exe"" --StartMode=jvm --StopMode=jvm
--StartClass=org.apache.directory.server.standalone.daemon.Bootstrapper --StartParams=""{app}#start""
--StopClass=org.apache.directory.server.standalone.daemon.Bootstrapper --StopParams=""{app}#stop""
--Startup=manual --JvmOptions=""-D${app}.home={app}"" --Classpath=""{app}\bin\bootstrapper.jar;{app}\conf;{app}\bin\logger.jar;{app}\bin\daemon.jar""
--LogPath=""{app}\var\log"" --LogPrefix=${app}.log --LogLevel=debug --StdOutput=""{app}\var\log\${app}-stdout.log""
--StdError=""{app}\var\log\${app}-stderr.log"""; Flags: runhidden
+Filename: {app}\bin\${app}.exe; WorkingDir: {app}\bin; Tasks: ; Languages: ; Parameters:
"//IS//${app.displayname} --Description=""${app.description} Service ${app.version} - ${app.url}""
--DisplayName=${app.displayname} --Install=""{app}\bin\${app}.exe"" --StartMode=jvm --StopMode=jvm
--StartClass=org.apache.directory.server.standalone.daemon.ProcrunBootstrapper --StartMethod
prunsrvStart --StartParams=""{app}"" --StopClass=org.apache.directory.server.standalone.daemon.ProcrunBootstrapper
--StopMethod prunsrvStop --StopParams=""{app}"" --Startup=manual --JvmOptions=""-D${app}.home={app}""
--Classpath=""{app}\bin\bootstrapper.jar;{app}\conf;{app}\bin\logger.jar;{app}\bin\daemon.jar""
--LogPath=""{app}\var\log"" --LogPrefix=${app}.log --LogLevel=debug --StdOutput=""{app}\var\log\${app}-stdout.log""
--StdError=""{app}\var\log\${app}-stderr.log"""; Flags: runhidden
 Filename: {app}\bin\${app}w.exe; Parameters: //ES//${app.displayname}; WorkingDir: {app}\bin;
Flags: postinstall nowait; Description: Runs the configuration manager for the ${app} windows
service
 
 [Registry]

Modified: directory/trunks/apacheds/standalone/installers/plugin/src/main/resources/org/apache/directory/server/standalone/installers/template.init
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/standalone/installers/plugin/src/main/resources/org/apache/directory/server/standalone/installers/template.init?rev=372980&r1=372979&r2=372980&view=diff
==============================================================================
--- directory/trunks/apacheds/standalone/installers/plugin/src/main/resources/org/apache/directory/server/standalone/installers/template.init
(original)
+++ directory/trunks/apacheds/standalone/installers/plugin/src/main/resources/org/apache/directory/server/standalone/installers/template.init
Fri Jan 27 12:47:33 2006
@@ -142,8 +142,8 @@
     -outfile $SERVER_HOME/var/log/${app}-stdout.log \
     -errfile $SERVER_HOME/var/log/${app}-stderr.log \
     -cp $CLASSPATH \
-    org.apache.directory.server.standalone.daemon.Bootstrapper \
-    $_${app.caps}_HOME start
+    org.apache.directory.server.standalone.daemon.JsvcBootstrapper \
+    $_${app.caps}_HOME
 
     if [ `uname` = "Darwin" ] ; then
         [ "$RETVAL" -eq 0 ] && echo successful ${app} server startup || \
@@ -174,7 +174,7 @@
     -stop \
     -pidfile $PID_FILE \
     -Dlog4j.configuration=file://$SERVER_HOME/conf/log4j.properties\
-    org.apache.directory.server.standalone.daemon.Bootstrapper 
+    org.apache.directory.server.standalone.daemon.JsvcBootstrapper 
 
     if [ `uname` = "Darwin" ] ; then
         [ "$RETVAL" -eq 0 ] && echo successful ${app} server shutdown || \

Modified: directory/trunks/apacheds/standalone/simple/main/src/main/java/org/apache/ldap/server/DirectoryServer.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/standalone/simple/main/src/main/java/org/apache/ldap/server/DirectoryServer.java?rev=372980&r1=372979&r2=372980&view=diff
==============================================================================
--- directory/trunks/apacheds/standalone/simple/main/src/main/java/org/apache/ldap/server/DirectoryServer.java
(original)
+++ directory/trunks/apacheds/standalone/simple/main/src/main/java/org/apache/ldap/server/DirectoryServer.java
Fri Jan 27 12:47:33 2006
@@ -22,8 +22,10 @@
 import javax.naming.Context;
 import javax.naming.directory.InitialDirContext;
 
+import org.apache.directory.server.standalone.daemon.DaemonApplication;
 import org.apache.directory.server.standalone.daemon.InstallationLayout;
 import org.apache.ldap.server.configuration.MutableServerStartupConfiguration;
+import org.apache.ldap.server.configuration.ShutdownConfiguration;
 import org.apache.ldap.server.configuration.SyncConfiguration;
 import org.apache.ldap.server.jndi.ServerContextFactory;
 
@@ -40,13 +42,18 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class DirectoryServer
+public class DirectoryServer implements DaemonApplication
 {
     private static final Logger log = LoggerFactory.getLogger( DirectoryServer.class );
     private Properties env;
+    private Thread workerThread = null;
+    private SynchWorker worker = new SynchWorker();
+    private boolean startNoWait = false;
+    private boolean initialized = false;
+    private boolean started = false;
 
 
-    public void init( InstallationLayout install ) throws Exception
+    public void init( InstallationLayout install, String[] args ) throws Exception
     {
         long startTime = System.currentTimeMillis();
         MutableServerStartupConfiguration cfg;
@@ -72,6 +79,10 @@
         env.putAll( cfg.toJndiEnvironment() );
         new InitialDirContext( env );
 
+        workerThread = new Thread( worker, "SynchWorkerThread" );
+        initialized = true;
+
+
         if (log.isInfoEnabled())
         {
             log.info( "server: started in {} milliseconds", ( System.currentTimeMillis()
- startTime ) + "");
@@ -86,12 +97,83 @@
     }
     
 
-    public void stop() throws Exception
+    public void start( boolean nowait ) 
     {
+        startNoWait = nowait;
+        
+        if ( nowait )
+        {
+            workerThread.start();
+            started = true;
+            return;
+        }
+
+        started = true;
+        worker.run();  // - blocks here 
     }
     
 
-    public void start() throws Exception
+    public void stop( String[] args ) throws Exception
+    {
+        if ( ! initialized || ! started )
+        {
+            log.warn( "stop(String[]) called without calling init() and start()" );
+            log.info( "Might be a procrun invocation as opposed to jsvc so we'll initiate
external shutdown procedure" );
+        }
+        
+        worker.stop = true;
+        synchronized ( worker.lock )
+        {
+            worker.lock.notify();
+        }
+        
+        while ( startNoWait && workerThread.isAlive() )
+        {
+            log.info( "Waiting for SynchWorkerThread to die." );
+            workerThread.join( 500 );
+        }
+        
+        env.putAll( new ShutdownConfiguration().toJndiEnvironment() );
+        new InitialDirContext( env );
+    }
+
+
+    public void destroy() 
     {
+    }
+
+
+    class SynchWorker implements Runnable
+    {
+        Object lock = new Object();
+        boolean stop = false;
+        
+        public void run()
+        {
+            while ( ! stop )
+            {
+                synchronized( lock )
+                {
+                    try
+                    {
+                        lock.wait( 20000 );
+                        log.debug( "[Delete me] Woke up! Time = " + System.currentTimeMillis()
);
+                    }
+                    catch ( InterruptedException e )
+                    {
+                        log.error( "SynchWorker failed to wait on lock.", e );
+                    }
+                }
+                
+                try
+                {
+                    synch();
+                }
+                catch ( Exception e )
+                {
+                    log.error( "SynchWorker failed to synch directory.", e );
+                }
+            }
+        }
     }
 }

Modified: directory/trunks/apacheds/standalone/simple/main/src/main/java/org/apache/ldap/server/ServerMain.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/standalone/simple/main/src/main/java/org/apache/ldap/server/ServerMain.java?rev=372980&r1=372979&r2=372980&view=diff
==============================================================================
--- directory/trunks/apacheds/standalone/simple/main/src/main/java/org/apache/ldap/server/ServerMain.java
(original)
+++ directory/trunks/apacheds/standalone/simple/main/src/main/java/org/apache/ldap/server/ServerMain.java
Fri Jan 27 12:47:33 2006
@@ -41,17 +41,13 @@
 
         if ( args.length > 0 )
         {
-            server.init( new InstallationLayout( args[0] ) );
+            server.init( new InstallationLayout( args[0] ), null );
+            server.start( false );
         }
         else
         {
-            server.init( null );
-        }
-
-        while ( true )
-        {
-            Thread.sleep( 20000 );
-            server.synch();
+            server.init( null, null );
+            server.start( false );
         }
     }
 }



Mime
View raw message