directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r372793 - /directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/
Date Fri, 27 Jan 2006 09:11:52 GMT
Author: akarasulu
Date: Fri Jan 27 01:11:48 2006
New Revision: 372793

URL: http://svn.apache.org/viewcvs?rev=372793&view=rev
Log:
refactored daemon code so dynamics are clear

Added:
    directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/BootstrappedApplication.java
    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
      - copied, changed from r372723, directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/Bootstrapper.java
    directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ProcrunBootstrapper.java
Removed:
    directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/Bootstrapper.java

Added: directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/BootstrappedApplication.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/BootstrappedApplication.java?rev=372793&view=auto
==============================================================================
--- directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/BootstrappedApplication.java
(added)
+++ directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/BootstrappedApplication.java
Fri Jan 27 01:11:48 2006
@@ -0,0 +1,296 @@
+/*
+ *   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;
+
+
+import java.io.FileInputStream;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The bootstrapped application is managed by this class.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BootstrappedApplication
+{
+    private static Logger log = LoggerFactory.getLogger( BootstrappedApplication.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 String startClassName;
+    private String stopClassName;
+    private final ClassLoader application;
+    private final InstallationLayout layout;
+
+
+    public BootstrappedApplication( String installationBase, ClassLoader parent )
+    {
+        layout = new InstallationLayout( installationBase );
+        
+        // -------------------------------------------------------------------
+        // Verify correct installation layout
+        // -------------------------------------------------------------------
+
+        try
+        {
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "Verifying installation layout:\n" + installationBase );
+            }
+            layout.verifyInstallation();
+        }
+        catch( Throwable t )
+        {
+            log.error( "Installation verification failure!", t );
+            System.exit( ExitCodes.VERIFICATION );
+        }
+        
+        // -------------------------------------------------------------------
+        // Load the properties from the bootstrap configuration file
+        // -------------------------------------------------------------------
+
+        try
+        {
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "Loading bootstrap configuration:\n" + layout.getBootstrapperConfigurationFile()
);
+            }
+            Properties props = new Properties();
+            props.load( new FileInputStream( layout.getBootstrapperConfigurationFile() )
);
+
+            startClassName = props.getProperty( BOOTSTRAP_START_CLASS_PROP );
+            if ( startClassName == null )
+            {
+                log.error( "Start class not found in " + layout.getBootstrapperConfigurationFile()
);
+                System.exit( ExitCodes.PROPLOAD );
+            }
+            else if ( log.isDebugEnabled() )
+            {
+                log.debug( "Start class set to: " + startClassName );
+            }
+
+            stopClassName = props.getProperty( BOOTSTRAP_STOP_CLASS_PROP );
+            if ( stopClassName == null )
+            {
+                log.error( "Stop class not found in " + layout.getBootstrapperConfigurationFile()
);
+                System.exit( ExitCodes.PROPLOAD );
+            }
+            else if ( log.isDebugEnabled() )
+            {
+                log.debug( "Stop class set to: " + stopClassName );
+            }
+        }
+        catch ( Exception e )
+        {
+            log.error( "Failed while loading: " + layout.getBootstrapperConfigurationFile(),
e );
+            System.exit( ExitCodes.PROPLOAD );
+        }
+
+        // -------------------------------------------------------------------
+        // Setup the application ClassLoader using the dependencies in layout
+        // -------------------------------------------------------------------
+
+        URL[] jars = layout.getAllJars();
+        this.application = new URLClassLoader( jars, parent );
+        if ( log.isDebugEnabled() )
+        {
+            StringBuffer buf = new StringBuffer();
+            buf.append( "Depenencies in application ClassLoader: \n" );
+            for ( int ii = 0; ii < jars.length; ii++ )
+            {
+                buf.append( "\t" ).append( jars[ii] ).append( "\n" );
+            }
+            log.debug( buf.toString() );
+        }
+    }
+
+
+    /**
+     * Invokes the init(InstallationLayout) method of the start class via reflection 
+     * using the application ClassLoader.  The application ClassLoader is set as the 
+     * context ClassLoader then the method is invoked.
+     */
+    public void callInit()
+    {
+        Class clazz = null;
+        Method op = null;
+        
+        Thread.currentThread().setContextClassLoader( application );
+        try
+        {
+            clazz = application.loadClass( startClassName );
+        }
+        catch ( ClassNotFoundException e )
+        {
+            log.error( "Could not find " + startClassName, e );
+            System.exit( ExitCodes.CLASS_LOOKUP );
+        }
+        
+        try
+        {
+            startObject = 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 } );
+        }
+        catch ( Exception e )
+        {
+            log.error( "Failed on " + startClassName + ".init(InstallationLayout)", e );
+            System.exit( ExitCodes.INITIALIZATION );
+        }
+    }
+
+
+    public void callStart()
+    {
+        Thread.currentThread().setContextClassLoader( application );
+        Class clazz = startObject.getClass();
+        Method op = null;
+        
+        try
+        {
+            op = clazz.getMethod( "start", null );
+        }
+        catch ( Exception e )
+        {
+            log.error( "Could not find start() method for " + clazz.getName(), e );
+            System.exit( ExitCodes.METHOD_LOOKUP );
+        }
+        
+        try
+        {
+            op.invoke( startObject, null );
+        }
+        catch ( Exception e )
+        {
+            log.error( "Failed on " + clazz.getName() + ".start()", e );
+            System.exit( ExitCodes.START );
+        }
+    }
+    
+
+    public void callStop()
+    {
+        Thread.currentThread().setContextClassLoader( application );
+        Class clazz = null;
+        Method op = null;
+
+        // Reuse the startObject if it is the same class
+        if ( ! startClassName.equals( stopClassName ) )
+        {
+            try
+            {
+                clazz = application.loadClass( stopClassName );
+            }
+            catch ( ClassNotFoundException e )
+            {
+                log.error( "Could not find " + stopClassName, e );
+                System.exit( ExitCodes.CLASS_LOOKUP );
+            }
+            
+            try
+            {
+                stopObject = clazz.newInstance();
+            }
+            catch ( Exception e )
+            {
+                log.error( "Could not instantiate " + stopClassName, e );
+                System.exit( ExitCodes.INSTANTIATION );
+            }
+        }
+        else
+        {
+            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 );
+        }
+        catch ( Exception e )
+        {
+            log.error( "Failed on " + stopClassName + ".stop()", e );
+            System.exit( ExitCodes.STOP );
+        }
+    }
+
+    
+    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 );
+        }
+    }
+}

Added: 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=372793&view=auto
==============================================================================
--- directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ExitCodes.java
(added)
+++ directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ExitCodes.java
Fri Jan 27 01:11:48 2006
@@ -0,0 +1,40 @@
+/*
+ *   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;
+
+
+/**
+ * Exit codes for the bootstrappers.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface ExitCodes
+{
+    int CLASS_LOOKUP = 1;
+    int INSTANTIATION = 2;
+    int METHOD_LOOKUP = 3;
+    int INITIALIZATION = 4;
+    int START = 5;
+    int STOP = 6;
+    int PROPLOAD = 7;
+    int VERIFICATION = 8;
+    int DESTROY = 9;
+    int BAD_ARGUMENTS = 10;
+    int BAD_COMMAND = 11;
+    int UNKNOWN = 12;
+}

Added: 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=372793&view=auto
==============================================================================
--- directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/JsvcBootstrapper.java
(added)
+++ directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/JsvcBootstrapper.java
Fri Jan 27 01:11:48 2006
@@ -0,0 +1,103 @@
+/*
+ *   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;
+
+
+import org.apache.commons.daemon.Daemon;
+import org.apache.commons.daemon.DaemonContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The bootstrapper used by the 
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class JsvcBootstrapper implements Daemon
+{
+    private final static Logger log = LoggerFactory.getLogger( JsvcBootstrapper.class );
+    private BootstrappedApplication application;
+    
+    
+    public void init( DaemonContext arg ) throws Exception
+    {
+        if ( log.isDebugEnabled() )
+        {
+            StringBuffer buf = new StringBuffer();
+            buf.append( "init(DaemonContext) called with args: \n" );
+            for ( int ii = 0; ii < arg.getArguments().length; ii++ )
+            {
+                buf.append( "\t" ).append( arg.getArguments()[ii] ).append( "\n" );
+            }
+            log.debug( buf.toString() );
+        }
+
+        if ( application == null )
+        {
+            application = new BootstrappedApplication( arg.getArguments()[0], 
+                Thread.currentThread().getContextClassLoader() );
+        }
+        
+        application.callInit();
+    }
+    
+
+    public void init( String[] args )
+    {
+        if ( log.isDebugEnabled() )
+        {
+            StringBuffer buf = new StringBuffer();
+            buf.append( "init(String[]) called with args: \n" );
+            for ( int ii = 0; ii < args.length; ii++ )
+            {
+                buf.append( "\t" ).append( args[ii] ).append( "\n" );
+            }
+            log.debug( buf.toString() );
+        }
+
+        if ( application == null )
+        {
+            application = new BootstrappedApplication( args[0], Thread.currentThread().getContextClassLoader()
);
+        }
+        
+        application.callInit();
+    }
+    
+    
+    public void start()
+    {
+        log.debug( "start() called" );
+        application.callStart();
+    }
+
+
+    public void stop() throws Exception
+    {
+        log.debug( "stop() called" );
+        application.callStop();
+    }
+
+
+    public void destroy()
+    {
+        log.debug( "destroy() called" );
+        application.callDestroy();
+    }
+}

Copied: directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/MainBootstrapper.java
(from r372723, directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/Bootstrapper.java)
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/MainBootstrapper.java?p2=directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/MainBootstrapper.java&p1=directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/Bootstrapper.java&r1=372723&r2=372793&rev=372793&view=diff
==============================================================================
--- directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/Bootstrapper.java
(original)
+++ directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/MainBootstrapper.java
Fri Jan 27 01:11:48 2006
@@ -17,304 +17,20 @@
 package org.apache.directory.server.standalone.daemon;
 
 
-import java.io.FileInputStream;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Properties;
-
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
 
 /**
+ * The main() based application bootstrapper used as the entry point for the 
+ * executable bootstrapper.jar so it can be launched as a simple java application.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class Bootstrapper
+public class MainBootstrapper
 {
-    private static final Logger log = LoggerFactory.getLogger( Bootstrapper.class );
-    private static final int CLASS_LOOKUP_FAILURE_EXITCODE = -1;
-    private static final int INSTANTIATION_FAILURE_EXITCODE = -2;
-    private static final int METHOD_LOOKUP_FAILURE_EXITCODE = -3;
-    private static final int INITIALIZATION_FAILURE_EXITCODE = -4;
-    private static final int START_FAILURE_EXITCODE = -5;
-    private static final int STOP_FAILURE_EXITCODE = -6;
-    private static final int BOOTSTRAP_PROPLOAD_FAILURE_EXITCODE = -7;
-    private static final String BOOTSTRAP_START_CLASS_PROP = "bootstrap.start.class";
-    private static final String BOOTSTRAP_STOP_CLASS_PROP = "bootstrap.stop.class";
-
-    private static Bootstrapper instance;
-    
-    private final Properties bootstrapProperties = new Properties();
-    private InstallationLayout install;
-    private ClassLoader appLoader;
-    private ClassLoader parentLoader;
-    private Object bootstrapped;
-
-    
-    public void setInstallationLayout( String installationBase )
-    {
-    	log.debug( "Setting layout in Bootstrapper using base: " + installationBase );
-        install = new InstallationLayout( installationBase );
-        
-        try
-        {
-        	install.verifyInstallation();
-        }
-        catch( Throwable t )
-        {
-        	log.error( "Installation verification failure!", t );
-        }
-        
-        try
-        {
-            bootstrapProperties.load( new FileInputStream( install.getBootstrapperConfigurationFile()
) );
-        }
-        catch ( Exception e )
-        {
-            log.error( "Failed while loading: " + install.getBootstrapperConfigurationFile(),
e );
-            System.exit( BOOTSTRAP_PROPLOAD_FAILURE_EXITCODE );
-        }
-    }
-    
-    
-    public void setParentLoader( ClassLoader parentLoader )
-    {
-        this.parentLoader = parentLoader;
-        URL[] jars = install.getAllJars();
-        this.appLoader = new URLClassLoader( jars, parentLoader );
-        
-        if ( log.isDebugEnabled() )
-        {
-            StringBuffer buf = new StringBuffer();
-            buf.append( "urls in app loader: \n" );
-            for ( int ii = 0; ii < jars.length; ii++ )
-            {
-                buf.append( "\t" ).append( jars[ii] ).append( "\n" );
-            }
-            log.debug( buf.toString() );
-        }
-    }
-
-
-    public void callInit( String className )
-    {
-        Class clazz = null;
-        Method op = null;
-        
-        Thread.currentThread().setContextClassLoader( appLoader );
-        try
-        {
-            clazz = appLoader.loadClass( className );
-        }
-        catch ( ClassNotFoundException e )
-        {
-            log.error( "Could not find " + className, e );
-            System.exit( CLASS_LOOKUP_FAILURE_EXITCODE );
-        }
-        
-        try
-        {
-            bootstrapped = clazz.newInstance();
-        }
-        catch ( Exception e )
-        {
-            log.error( "Could not instantiate " + className, e );
-            System.exit( INSTANTIATION_FAILURE_EXITCODE );
-        }
-        
-        try
-        {
-            op = clazz.getMethod( "init", new Class[] { InstallationLayout.class } );
-        }
-        catch ( Exception e )
-        {
-            log.error( "Could not find init(InstallationLayout) method for " + className,
e );
-            System.exit( METHOD_LOOKUP_FAILURE_EXITCODE );
-        }
-        
-        try
-        {
-            op.invoke( bootstrapped, new Object[] { this.install } );
-        }
-        catch ( Exception e )
-        {
-            log.error( "Failed on " + className + ".init(InstallationLayout)", e );
-            System.exit( INITIALIZATION_FAILURE_EXITCODE );
-        }
-    }
-
-    
-    public void callStart()
-    {
-        Class clazz = bootstrapped.getClass();
-        Method op = null;
-        
-        try
-        {
-            op = clazz.getMethod( "start", null );
-        }
-        catch ( Exception e )
-        {
-            log.error( "Could not find start() method for " + clazz.getName(), e );
-            System.exit( METHOD_LOOKUP_FAILURE_EXITCODE );
-        }
-        
-        try
-        {
-            op.invoke( bootstrapped, null );
-        }
-        catch ( Exception e )
-        {
-            log.error( "Failed on " + clazz.getName() + ".start()", e );
-            System.exit( START_FAILURE_EXITCODE );
-        }
-    }
-    
-
-    public void callStop( String className )
-    {
-        Class clazz = null;
-        Method op = null;
-        
-        try
-        {
-            clazz = appLoader.loadClass( className );
-        }
-        catch ( ClassNotFoundException e )
-        {
-            log.error( "Could not find " + className, e );
-            System.exit( CLASS_LOOKUP_FAILURE_EXITCODE );
-        }
-        
-        try
-        {
-            bootstrapped = clazz.newInstance();
-        }
-        catch ( Exception e )
-        {
-            log.error( "Could not instantiate " + className, e );
-            System.exit( INSTANTIATION_FAILURE_EXITCODE );
-        }
-        
-        try
-        {
-            op = clazz.getMethod( "stop", null );
-        }
-        catch ( Exception e )
-        {
-            log.error( "Could not find stop() method for " + className, e );
-            System.exit( METHOD_LOOKUP_FAILURE_EXITCODE );
-        }
-        
-        try
-        {
-            op.invoke( bootstrapped, null );
-        }
-        catch ( Exception e )
-        {
-            log.error( "Failed on " + className + ".stop()", e );
-            System.exit( STOP_FAILURE_EXITCODE );
-        }
-    }
-
-    
-    // -----------------------------------------------------------------------
-    
-    
-    public void init( String[] args )
-    {
-        if ( log.isDebugEnabled() )
-        {
-            StringBuffer buf = new StringBuffer();
-            buf.append( "init(String[]) called with args: \n" );
-            for ( int ii = 0; ii < args.length; ii++ )
-            {
-                buf.append( "\t" ).append( args[ii] ).append( "\n" );
-            }
-            log.debug( buf.toString() );
-        }
-
-        if ( install == null )
-        {
-            log.debug( "install was null: initializing it using first argument" );
-            setInstallationLayout( args[0] );
-            log.debug( "install initialized" );
-        }
-        else
-        {
-            log.debug( "install was not null" );
-        }
-
-        if ( parentLoader == null )
-        {
-            log.info( "Trying to get handle on system classloader as the parent" );
-            setParentLoader( Thread.currentThread().getContextClassLoader() );
-            log.info( "parentLoader = " + parentLoader );
-        }
-        
-        callInit( bootstrapProperties.getProperty( BOOTSTRAP_START_CLASS_PROP, null ) );
-
-        // This is only needed for procrun but does not harm jsvc or runs 
-        // Leads me to think that we need to differentiate somehow between
-        // different daemon frameworks.  We can do this via command line args,
-        // system properties or by making them call different methods to start
-        // the process.  However not every framework may support calling 
-        // different methods which may also be somewhat error prone.
-        
-        while( true )
-        {
-            try
-            {
-                Thread.sleep( 2000 );
-            }
-            catch ( InterruptedException e )
-            {
-                e.printStackTrace();
-            }
-        }
-    }
-    
-    
-    public void stop() throws Exception
-    {
-        log.debug( "stop() called" );
-        callStop( bootstrapProperties.getProperty( BOOTSTRAP_STOP_CLASS_PROP, null )  );
-    }
-
-
-    public void destroy()
-    {
-        log.debug( "destroy() called" );
-    }
-
-
-    public void start()
-    {
-        log.debug( "start() called" );
-        Thread.currentThread().setContextClassLoader( parentLoader );
-        callStart();
-    }
-
-
-    public void start( String[] args )
-    {
-        log.debug( "start(String[]) called" );
-        Thread.currentThread().setContextClassLoader( this.parentLoader );
-        
-        if ( install == null && args.length > 0 )
-        {
-            setInstallationLayout( args[0] );
-            setParentLoader( Thread.currentThread().getContextClassLoader() );
-        }
-    }
-
-    
-    // ------------------------------------------------------------------------
-    // The main()
-    // ------------------------------------------------------------------------
+    private static final Logger log = LoggerFactory.getLogger( MainBootstrapper.class );
 
 
     public static void main( String[] args )
@@ -327,7 +43,7 @@
             System.err.println( "Arguements are null - how come?" );
             log.error( "main() args were null shutting down!" );
             printHelp();
-            System.exit( 1 );
+            System.exit( ExitCodes.BAD_ARGUMENTS );
         }
 
         if ( log.isDebugEnabled() )
@@ -335,20 +51,15 @@
             log.debug( "main() recieved args:" );
             for ( int ii = 0; ii < args.length; ii++ )
             {
-                log.debug( "args[" + ii + "] = " + args[ii] );
+                log.debug( "\targs[" + ii + "] = " + args[ii] );
             }
         }
 
+        BootstrappedApplication application = null;
         if ( args.length > 1 )
         {
-            if ( instance == null )
-            {
-            	log.debug( "main(String[]) initializing Bootstrapper ... )" );
-                instance = new Bootstrapper();
-                instance.setInstallationLayout( args[0] );
-                instance.setParentLoader( Bootstrapper.class.getClassLoader() );
-                log.debug( "Bootstrapper initialized" );
-            }
+        	log.debug( "main(String[]) creating BootstrappedApplication ... )" );
+            application = new BootstrappedApplication( args[0], Thread.currentThread().getContextClassLoader()
);
         }
         else
         {
@@ -364,36 +75,36 @@
         {
             if ( command.equalsIgnoreCase( "start" ) )
             {
-                log.debug( "calling init(String[]) from main(String[])" );
-                instance.init( args );
+                log.debug( "calling application.callInit(String[]) from main(String[])" );
+                application.callInit();
 
-                log.debug( "calling start(String[]) from main(String[])" );
-                instance.start( args );
+                log.debug( "calling application.callStart(String[]) from main(String[])"
);
+                application.callStart();
             }
             else if ( command.equalsIgnoreCase( "stop" ) )
             {
-                log.debug( "calling stop() from main(String[])" );
-                instance.stop();
-                instance.destroy();
+                log.debug( "calling application.callStop() from main(String[])" );
+                application.callStop();
+                log.debug( "calling application.callDestroy() from main(String[])" );
+                application.callDestroy();
             }
             else
             {
                 log.error( "Unrecognized command " + command );
                 printHelp();
-                System.exit( 3 );
+                System.exit( ExitCodes.BAD_COMMAND );
             }
         }
         catch ( Throwable t )
         {
-        	log.error( "Encountered error while processing command: " + command );
-            t.printStackTrace();
-            System.exit( 4 );
+        	log.error( "Encountered error while processing command: " + command, t );
+            System.exit( ExitCodes.UNKNOWN );
         }
     }
 
 
     private static void printHelp()
     {
-        System.err.println("java -jar bootstrap.jar <app.home> <command.name>");
+        System.err.println("java -jar bootstrapper.jar <install.home> [start|stop]");
     }
 }

Added: 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=372793&view=auto
==============================================================================
--- directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ProcrunBootstrapper.java
(added)
+++ directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/ProcrunBootstrapper.java
Fri Jan 27 01:11:48 2006
@@ -0,0 +1,104 @@
+/*
+ *   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;
+
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The bootstrapper used for procrun services on windows platforms.  This
+ * class contains static methods invoked by the prunsrv service manager.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ProcrunBootstrapper
+{
+    private final static Logger log = LoggerFactory.getLogger( ProcrunBootstrapper.class
);
+    
+
+    public static void prunsrvStart( String[] args )
+    {
+        if ( log.isDebugEnabled() )
+        {
+            StringBuffer buf = new StringBuffer();
+            buf.append( "ENTERING ==> prunsrvStart(String[]):\n" );
+            for ( int ii = 0; ii < args.length; ii++ )
+            {
+                buf.append( "\targs[" ).append( ii ).append( "] = " ).append( args[ii] ).append(
"\n" );
+            }
+        }
+
+        if ( args == null || args.length < 1 )
+        {
+            log.error( "Args were null or less than 1: need home directory.  Shutting down!"
);
+            System.exit( ExitCodes.BAD_ARGUMENTS );
+        }
+
+        log.debug( "prunsrvStart(String[]) creating BootstrappedApplication ... )" );
+        BootstrappedApplication application = new BootstrappedApplication( args[0], 
+            Thread.currentThread().getContextClassLoader() );
+
+        log.debug( "prunsrvStart(String[]) invoking application.callInit())" );
+        application.callInit();
+        log.debug( "prunsrvStart(String[]) invoking bootstrapper.callStart())" );
+        application.callStart();
+        
+        while( true )
+        {
+            try
+            {
+                Thread.sleep( 2000 );
+            }
+            catch ( InterruptedException e )
+            {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    
+    public static void prunsrvStop( String[] args )
+    {
+        if ( log.isDebugEnabled() )
+        {
+            StringBuffer buf = new StringBuffer();
+            buf.append( "ENTERING ==> prunsrvStop(String[]):\n" );
+            for ( int ii = 0; ii < args.length; ii++ )
+            {
+                buf.append( "\targs[" ).append( ii ).append( "] = " ).append( args[ii] ).append(
"\n" );
+            }
+        }
+        
+        if ( args == null || args.length < 1 )
+        {
+            log.error( "Args were null or less than 1: need home directory.  Shutting down!"
);
+            System.exit( ExitCodes.BAD_ARGUMENTS );
+        }
+
+        log.debug( "prunsrvStop(String[]) creating BootstrappedApplication ... )" );
+        BootstrappedApplication application = new BootstrappedApplication( args[0], 
+            Thread.currentThread().getContextClassLoader() );
+        
+        log.debug( "prunsrvStop(String[]) invoking application.callStop())" );
+        application.callStop();
+        log.debug( "prunsrvStop(String[]) invoking application.callDestroy())" );
+        application.callDestroy();
+    }
+}



Mime
View raw message