You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2001/12/08 12:45:25 UTC

cvs commit: jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/launcher DaemonLauncher.java Main.java

donaldp     01/12/08 03:45:25

  Modified:    src/java/org/apache/avalon/phoenix/frontends CLIMain.java
                        Resources.properties
               src/java/org/apache/avalon/phoenix/launcher
                        DaemonLauncher.java Main.java
  Log:
  Upgrade launching so that an embeddor can ask for the JVM to be restarted. This required moving around a few methods (especially where we called System.exit()) and a bit of refactoring.
  
  We communicate between launcher and embeddor via an ActionListebner. This may seem strange but it makes it possible for each part not to be aware of ClassLoader of other component and they no need to have a user supplied common classloader ancestor (as ActionListener is defined in System classloader).
  
  Revision  Changes    Path
  1.17      +20 -12    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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- CLIMain.java	2001/12/08 04:57:43	1.16
  +++ CLIMain.java	2001/12/08 11:45:24	1.17
  @@ -9,17 +9,20 @@
   
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  +import org.apache.avalon.framework.context.Contextualizable;
  +import org.apache.avalon.framework.context.DefaultContext;
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.phoenix.Constants;
   import org.apache.avalon.phoenix.components.embeddor.DefaultEmbeddor;
   import org.apache.avalon.phoenix.interfaces.Embeddor;
  +import java.util.Hashtable;
   
   /**
    * The class to load the kernel and start it running.
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  - * @author <a href="mail@leosimons.com">Leo Simons</a>
  + * @author <a href="mailto:mail@leosimons.com">Leo Simons</a>
    */
   public final class CLIMain
   {
  @@ -39,7 +42,7 @@
        *
        * @param args[] the command line arguments
        */
  -    public void main( final String args[] )
  +    public int main( final String args[], final Hashtable data )
       {
           try
           {
  @@ -48,7 +51,7 @@
   
               if( false == setup.parseCommandLineOptions( args ) )
               {
  -                return;
  +                return 0;
               }
   
               System.out.println();
  @@ -58,14 +61,14 @@
               final Parameters parameters = setup.getParameters();
               final String phoenixHome = System.getProperty( "phoenix.home", ".." );
               parameters.setParameter( "phoenix.home", phoenixHome );
  -            execute( parameters );
  +            execute( parameters, data );
           }
           catch( final Throwable throwable )
           {
               handleException( throwable );
           }
   
  -        System.exit( m_exitCode );
  +        return m_exitCode;
       }
   
       /**
  @@ -73,10 +76,10 @@
        *
        * @exception Exception if an error occurs
        */
  -    private void execute( final Parameters parameters )
  +    private void execute( final Parameters parameters, final Hashtable data )
           throws Exception
       {
  -        if( false == startup( parameters ) )
  +        if( false == startup( parameters, data ) )
           {
               return;
           }
  @@ -109,14 +112,18 @@
       /**
        * Startup the embeddor.
        */
  -    protected synchronized boolean startup( final Parameters parameters )
  +    protected synchronized boolean startup( final Parameters parameters, final Hashtable data )
       {
           try
           {
               m_embeddor = new DefaultEmbeddor();
  -            //m_embeddor = new SingleAppEmbeddor();
  -            //parameters.setParameter( "application-location", "../apps/avalon-demo.sar" );
   
  +            if( m_embeddor instanceof Contextualizable )
  +            {
  +                final DefaultContext context = new DefaultContext( data );
  +                ( (Contextualizable)m_embeddor ).contextualize( context );
  +            }
  +
               if( m_embeddor instanceof Parameterizable )
               {
                   ( (Parameterizable)m_embeddor ).parameterize( parameters );
  @@ -142,14 +149,15 @@
       {
           if( null == m_hook || null == m_embeddor )
           {
  -            //We were shutdown gracefully but the shutdown hook 
  +            //We were shutdown gracefully but the shutdown hook
               //thread was not removed. This can occur when an earlier
               //shutdown hook caused a shutdown() request to be processed
               return;
           }
   
           final String message = REZ.getString( "main.abnormal-exit.notice" );
  -        System.out.println( message );
  +        System.out.print( message );
  +        System.out.print( " " );
           System.out.flush();
   
           shutdown();
  
  
  
  1.7       +1 -1      jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/frontends/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/frontends/Resources.properties,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Resources.properties	2001/12/08 04:31:47	1.6
  +++ Resources.properties	2001/12/08 11:45:24	1.7
  @@ -16,5 +16,5 @@
   
   main.exception.header=There was an uncaught exception:
   main.exception.footer=The log file may contain further details of error.\nPlease check the configuration files and restart Phoenix.\nIf the problem persists, contact the Avalon project.  See\nhttp://jakarta.apache.org/avalon for more information.
  -main.abnormal-exit.notice=JVM exiting abnormally. Shutting down Phoenix.
  +main.abnormal-exit.notice=JVM exiting abnormally.
   main.exit.notice=Shutting down Phoenix.
  
  
  
  1.2       +33 -3     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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DaemonLauncher.java	2001/12/08 04:39:01	1.1
  +++ DaemonLauncher.java	2001/12/08 11:45:25	1.2
  @@ -9,6 +9,9 @@
   
   import com.silveregg.wrapper.WrapperListener;
   import com.silveregg.wrapper.WrapperManager;
  +import java.awt.event.ActionEvent;
  +import java.awt.event.ActionListener;
  +import java.util.Hashtable;
   
   /**
    * A frontend for Phoenix that starts it as a native service
  @@ -17,7 +20,7 @@
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    */
   public class DaemonLauncher
  -    implements WrapperListener, Runnable
  +    implements WrapperListener, Runnable, ActionListener
   {
       private String[] m_args;
   
  @@ -36,10 +39,13 @@
   
           return null;
       }
  -    
  +
       public void run()
       {
  -        try { Main.main( m_args ); }
  +        final Hashtable data = new Hashtable();
  +        data.put( ActionListener.class.getName(), this );
  +
  +        try { Main.startup( m_args, data ); }
           catch( final Exception e )
           {
               e.printStackTrace();
  @@ -62,6 +68,30 @@
           else
           {
               WrapperManager.stop( 0 );
  +        }
  +    }
  +
  +    /**
  +     * We use an ActionListener rather than operating on some more meaningful
  +     * event system as ActionListener and friends can be loaded from system
  +     * ClassLoader and thus the Embeddor does not have to share a common
  +     * classloader ancestor with invoker
  +     */
  +    public void actionPerformed( final ActionEvent action )
  +    {
  +        final String command = action.getActionCommand();
  +        if( command.equals( "restart" ) )
  +        {
  +            System.out.println( "Pre-restart()" );
  +            System.out.flush();
  +            WrapperManager.restart();
  +            System.out.println( "Post-restart()" );
  +            System.out.flush();
  +
  +        }
  +        else
  +        {
  +            throw new IllegalArgumentException( "Unknown action " + command );
           }
       }
   
  
  
  
  1.6       +37 -3     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Main.java	2001/12/08 04:27:10	1.5
  +++ Main.java	2001/12/08 11:45:25	1.6
  @@ -15,6 +15,7 @@
   import java.security.PermissionCollection;
   import java.security.Permissions;
   import java.security.Policy;
  +import java.util.Hashtable;
   import java.util.StringTokenizer;
   
   /**
  @@ -31,7 +32,32 @@
   
       private static Object c_frontend;
   
  -    public final static void main( final String args[] )
  +    ///The code to return to system using exit code
  +    private static int c_exitCode;
  +
  +    /**
  +     * Main entry point for Phoenix.
  +     *
  +     * @param args the command line arguments
  +     * @exception Exception if an error occurs
  +     */
  +    public final static void main( final String[] args )
  +        throws Exception
  +    {
  +        startup( args, new Hashtable() );
  +        System.exit( c_exitCode );
  +    }
  +
  +    /**
  +     * Method to call to startup Phoenix from an 
  +     * external (calling) application. Protected to allow
  +     * access from DaemonLauncher.
  +     *
  +     * @param args the command line arg array
  +     * @param data a set of extra parameters to pass to embeddor
  +     * @exception Exception if an error occurs
  +     */
  +    protected final static void startup( final String[] args, final Hashtable data )
           throws Exception
       {
           try
  @@ -49,11 +75,14 @@
   
               //Create main launcher
               final Class clazz = classLoader.loadClass( MAIN_CLASS );
  -            final Method method = clazz.getMethod( "main", new Class[]{ args.getClass() } );
  +            final Class[] paramTypes = new Class[] { args.getClass(), Hashtable.class };
  +            final Method method = clazz.getMethod( "main", paramTypes );
               c_frontend = clazz.newInstance();
               
               //kick the tires and light the fires....
  -            method.invoke( c_frontend, new Object[]{ args } );
  +            final Integer integer = 
  +                (Integer)method.invoke( c_frontend, new Object[] { args, data } );
  +            c_exitCode = integer.intValue();
           }
           catch( final Exception e )
           {
  @@ -61,6 +90,11 @@
           }
       }
   
  +    /**
  +     * Method to call to shutdown Phoenix from an 
  +     * external (calling) application. Protected to allow
  +     * access from DaemonLauncher.
  +     */
       protected final static void shutdown()
       {
           if( null == c_frontend ) return;
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>