donaldp     01/12/15 14:51:35

  Modified:    src/java/org/apache/avalon/phoenix/launcher Main.java
               src/java/org/apache/avalon/phoenix/frontends CLIMain.java
  Log:
  Converted Main so that it can launch phoenix in a thread that blocks and only 
returns when Phoenix is completed (if called from command line) or can launch a 
new thread to montor Phoenix and shutdown it appropriately but the thread will 
return imediately (when called from DaemonLauncher).
  
  Submitted By: Leif Mortenson <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.8       +7 -2      
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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Main.java 2001/12/11 10:13:35     1.7
  +++ Main.java 2001/12/15 22:51:34     1.8
  @@ -35,6 +35,9 @@
       ///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.
        *
  @@ -44,6 +47,7 @@
       public final static void main( final String[] args )
           throws Exception
       {
  +        c_blocking = true;
           startup( args, new Hashtable() );
           System.exit( c_exitCode );
       }
  @@ -75,13 +79,14 @@
   
               //Create main launcher
               final Class clazz = classLoader.loadClass( MAIN_CLASS );
  -            final Class[] paramTypes = new Class[] { args.getClass(), 
Hashtable.class };
  +            final Class[] paramTypes = 
  +                new Class[] { args.getClass(), Hashtable.class, Boolean.TYPE 
};
               final Method method = clazz.getMethod( "main", paramTypes );
               c_frontend = clazz.newInstance();
               
               //kick the tires and light the fires....
               final Integer integer = 
  -                (Integer)method.invoke( c_frontend, new Object[] { args, 
data } );
  +                (Integer)method.invoke( c_frontend, new Object[] { args, 
data, new Boolean( c_blocking ) } );
               c_exitCode = integer.intValue();
           }
           catch( final Exception e )
  
  
  
  1.19      +22 -3     
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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- CLIMain.java      2001/12/11 10:13:34     1.18
  +++ CLIMain.java      2001/12/15 22:51:34     1.19
  @@ -25,6 +25,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Leo Simons</a>
    */
   public final class CLIMain
  +    implements Runnable
   {
       private static final Resources REZ =
           ResourceManager.getPackageResources( CLIMain.class );
  @@ -42,7 +43,9 @@
        *
        * @param args[] the command line arguments
        */
  -    public int main( final String args[], final Hashtable data )
  +    public int main( final String args[], 
  +                     final Hashtable data,
  +                     final boolean blocking )
       {
           try
           {
  @@ -61,7 +64,7 @@
               final Parameters parameters = setup.getParameters();
               final String phoenixHome = System.getProperty( "phoenix.home", 
".." );
               parameters.setParameter( "phoenix.home", phoenixHome );
  -            execute( parameters, data );
  +            execute( parameters, data, blocking );
           }
           catch( final Throwable throwable )
           {
  @@ -76,7 +79,9 @@
        *
        * @exception Exception if an error occurs
        */
  -    private void execute( final Parameters parameters, final Hashtable data )
  +    private void execute( final Parameters parameters, 
  +                          final Hashtable data,
  +                          final boolean blocking )
           throws Exception
       {
           if( false == startup( parameters, data ) )
  @@ -91,6 +96,20 @@
               Runtime.getRuntime().addShutdownHook( m_hook );
           }
   
  +        if( blocking )
  +        {
  +            run();
  +        }
  +        else
  +        {
  +            final Thread thread = new Thread( this, "Phoenix-Monitor" );
  +            thread.setDaemon( false );
  +            thread.start();
  +        }
  +    }
  +
  +    public void run()
  +    {
           try
           {
               m_embeddor.execute();
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to