avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@apache.org
Subject cvs commit: jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/launcher DaemonLauncher.java Main.java
Date Thu, 07 Feb 2002 07:06:02 GMT
leif        02/02/06 23:06:02

  Modified:    src/java/org/apache/avalon/phoenix/frontends CLIMain.java
               src/java/org/apache/avalon/phoenix/launcher
                        DaemonLauncher.java Main.java
  Log:
  Added some code so that the Wrapper will shutdown Phoenix correctly
  when the shutdown process initiated from within Phoenix.
  
  Revision  Changes    Path
  1.21      +15 -2     jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/frontends/CLIMain.java
  
  Index: CLIMain.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/frontends/CLIMain.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- CLIMain.java	4 Feb 2002 09:57:55 -0000	1.20
  +++ CLIMain.java	7 Feb 2002 07:06:02 -0000	1.21
  @@ -22,6 +22,8 @@
   import org.apache.avalon.phoenix.components.embeddor.DefaultEmbeddor;
   import org.apache.avalon.phoenix.interfaces.Embeddor;
   import java.util.Hashtable;
  +import java.util.Observable;
  +import java.util.Observer;
   import java.io.File;
   import org.apache.log.Hierarchy;
   import org.apache.log.LogTarget;
  @@ -35,6 +37,7 @@
    * @author <a href="mailto:mail@leosimons.com">Leo Simons</a>
    */
   public final class CLIMain
  +    extends Observable
       implements Runnable
   {
       private static final Resources REZ =
  @@ -45,8 +48,6 @@
       private final static String DEFAULT_FORMAT =
           "%{time} [%7.7{priority}] (%{category}): %{message}\\n%{throwable}";
   
  -
  -
       ///The embeddor attached to frontend
       private Embeddor m_embeddor;
   
  @@ -112,6 +113,14 @@
               m_hook = new ShutdownHook( this );
               Runtime.getRuntime().addShutdownHook( m_hook );
           }
  +        
  +        // If an Observer is present in the data object, then add it as an observer for
  +        //  m_observable
  +        Observer observer = (Observer)data.get( Observer.class.getName() );
  +        if ( null != observer )
  +        {
  +            addObserver( observer );
  +        }
   
           if( blocking )
           {
  @@ -265,6 +274,10 @@
                   m_embeddor = null;
               }
           }
  +        
  +        // Notify any observers that Phoenix is shutting down
  +        setChanged();
  +        notifyObservers( "shutdown" );
       }
   
       /**
  
  
  
  1.7       +35 -7     jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/launcher/DaemonLauncher.java
  
  Index: DaemonLauncher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/launcher/DaemonLauncher.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DaemonLauncher.java	2 Feb 2002 11:50:10 -0000	1.6
  +++ DaemonLauncher.java	7 Feb 2002 07:06:02 -0000	1.7
  @@ -18,12 +18,15 @@
    * using the Java Service Wrapper at http://wrapper.sourceforge.net
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  + * @author <a href="mailto:leif@silveregg.co.jp">Leif Mortenson</a>
    */
   public class DaemonLauncher
       implements WrapperListener, Observer
   {
       public Integer start( final String[] args )
       {
  +        Integer exitCodeInteger = null;
  +        
           // This startup could take a while, so tell the wrapper to be patient.
           WrapperManager.signalStarting( 45000 );
   
  @@ -35,21 +38,29 @@
               System.out.println( "DaemonLauncher: Starting up Phoenix" );
           }
   
  -        try { Main.startup( args, data ); }
  -        catch( final Exception e )
  +        try
           {
  -            e.printStackTrace();
  -        }
  +            int exitCode = Main.startup( args, data, false );
  +            if ( exitCode != 0 )
  +            {
  +                exitCodeInteger = new Integer( exitCode );
  +            }
   
  -        if ( WrapperManager.isDebugEnabled() )
  +            if ( WrapperManager.isDebugEnabled() )
  +            {
  +                System.out.println( "DaemonLauncher: Phoenix startup completed" );
  +            }
  +        }
  +        catch( final Exception e )
           {
  -            System.out.println( "DaemonLauncher: Phoenix startup completed" );
  +            e.printStackTrace();
  +            exitCodeInteger = new Integer( 1 );
           }
   
           // We are almost up now, so reset the wait time
           WrapperManager.signalStarting( 2000 );
   
  -        return null;
  +        return exitCodeInteger;
       }
   
       public int stop( final int exitCode )
  @@ -107,6 +118,23 @@
               {
                   //Should never get here???
                   System.out.println( "DaemonLauncher: restart completed." );
  +                System.out.flush();
  +            }
  +        }
  +        else if ( command.equals( "shutdown" ) )
  +        {
  +            if ( WrapperManager.isDebugEnabled() )
  +            {
  +                System.out.println( "DaemonLauncher: shutdown requested." );
  +                System.out.flush();
  +            }
  +
  +            WrapperManager.stop( 0 );
  +
  +            if ( WrapperManager.isDebugEnabled() )
  +            {
  +                //Should never get here???
  +                System.out.println( "DaemonLauncher: shutdown completed." );
                   System.out.flush();
               }
           }
  
  
  
  1.9       +15 -13    jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/launcher/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/launcher/Main.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Main.java	15 Dec 2001 22:51:34 -0000	1.8
  +++ Main.java	7 Feb 2002 07:06:02 -0000	1.9
  @@ -32,12 +32,6 @@
   
       private static Object c_frontend;
   
  -    ///The code to return to system using exit code
  -    private static int c_exitCode;
  -
  -    ///The code to return to system using exit code
  -    private static boolean c_blocking;
  -
       /**
        * Main entry point for Phoenix.
        *
  @@ -47,9 +41,8 @@
       public final static void main( final String[] args )
           throws Exception
       {
  -        c_blocking = true;
  -        startup( args, new Hashtable() );
  -        System.exit( c_exitCode );
  +        int exitCode = startup( args, new Hashtable(), true );
  +        System.exit( exitCode );
       }
   
       /**
  @@ -59,11 +52,18 @@
        *
        * @param args the command line arg array
        * @param data a set of extra parameters to pass to embeddor
  +     * @param blocking false if the current thread is expected to return.
  +     *
  +     * @returns the exit code which should be used to exit the JVM
  +     *
        * @exception Exception if an error occurs
        */
  -    protected final static void startup( final String[] args, final Hashtable data )
  +    protected final static int startup( final String[] args, 
  +                                        final Hashtable data, 
  +                                        final boolean blocking )
           throws Exception
       {
  +        int exitCode;
           try
           {
               //setup new Policy manager
  @@ -85,14 +85,16 @@
               c_frontend = clazz.newInstance();
               
               //kick the tires and light the fires....
  -            final Integer integer = 
  -                (Integer)method.invoke( c_frontend, new Object[] { args, data, new Boolean(
c_blocking ) } );
  -            c_exitCode = integer.intValue();
  +            final Integer integer = (Integer)method.invoke(
  +                c_frontend, new Object[] { args, data, new Boolean( blocking ) } );
  +            exitCode = integer.intValue();
           }
           catch( final Exception e )
           {
               e.printStackTrace();
  +            exitCode = 1;
           }
  +        return exitCode;
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message