avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/launcher DaemonLauncher.java
Date Sat, 02 Feb 2002 11:50:11 GMT
donaldp     02/02/02 03:50:10

  Modified:    src/java/org/apache/avalon/phoenix/components/embeddor
                        DefaultEmbeddor.java Resources.properties
               src/java/org/apache/avalon/phoenix/launcher
                        DaemonLauncher.java
  Log:
  Get rid of ugly ActionListener hack and replace it with a less ugly Observer/Observable
hack.
  
  Revision  Changes    Path
  1.43      +25 -15    jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/embeddor/DefaultEmbeddor.java
  
  Index: DefaultEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/embeddor/DefaultEmbeddor.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- DefaultEmbeddor.java	2 Feb 2002 09:42:12 -0000	1.42
  +++ DefaultEmbeddor.java	2 Feb 2002 11:50:10 -0000	1.43
  @@ -7,8 +7,8 @@
    */
   package org.apache.avalon.phoenix.components.embeddor;
   
  -import java.awt.event.ActionEvent;
  -import java.awt.event.ActionListener;
  +import java.util.Observable;
  +import java.util.Observer;
   import java.io.File;
   import java.util.Date;
   import org.apache.avalon.excalibur.i18n.ResourceManager;
  @@ -70,7 +70,7 @@
       private final static String DEFAULT_FORMAT =
           "%{time} [%7.7{priority}] (%{category}): %{message}\\n%{throwable}";
   
  -    private Context m_context;
  +    private EmbeddorObservable m_observable = new EmbeddorObservable();
       private Parameters m_parameters;
       private String m_phoenixHome;
   
  @@ -98,7 +98,16 @@
       public void contextualize( final Context context )
           throws ContextException
       {
  -        m_context = context;
  +        try
  +        {
  +            final Observer observer = (Observer)context.get( Observer.class.getName() );
  +            m_observable.addObserver( observer );
  +        }
  +        catch( final ContextException ce )
  +        {
  +            final String message = REZ.getString( "embeddor.notice.no-restart" );
  +            getLogger().warn( message );
  +        }
       }
   
       /**
  @@ -279,18 +288,10 @@
       {
           try
           {
  -            //Pass a message back to original invoker.
  -            //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
  -            final ActionListener listener =
  -                (ActionListener)m_context.get( ActionListener.class.getName() );
  -            final ActionEvent action =
  -                new ActionEvent( new Object(), ActionEvent.ACTION_PERFORMED, "restart"
);
  -            listener.actionPerformed( action );
  +            m_observable.change();
  +            m_observable.notifyObservers( "restart" );
           }
  -        catch( final ContextException ce )
  +        catch( final Exception e )
           {
               throw new UnsupportedOperationException();
           }
  @@ -658,5 +659,14 @@
       {
           final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
           return builder.buildFromFile( location );
  +    }
  +}
  +
  +class EmbeddorObservable
  +    extends Observable
  +{
  +    public void change()
  +    {
  +        super.setChanged();
       }
   }
  
  
  
  1.4       +1 -0      jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/embeddor/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/embeddor/Resources.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Resources.properties	25 Sep 2001 10:54:59 -0000	1.3
  +++ Resources.properties	2 Feb 2002 11:50:10 -0000	1.4
  @@ -1,5 +1,6 @@
   embeddor.error.start.failed=There was a fatal error while starting Embeddor.
   embeddor.error.shutdown.failed=There was an unexpected error while shutting down Embeddor.
  +embeddor.notice.no-restart=Phoenix was not started by the daemon thus it will not be possible
to restart the JVM via the Management interface.
   bad-type.error=Object {0} is not an instance of {1}.
   bad-ctor.error=Non-public constructor for {0} {1}.
   no-instantiate.error=Error instantiating class for {0} {1}.
  
  
  
  1.6       +8 -8      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DaemonLauncher.java	15 Dec 2001 23:04:13 -0000	1.5
  +++ DaemonLauncher.java	2 Feb 2002 11:50:10 -0000	1.6
  @@ -9,8 +9,8 @@
   
   import com.silveregg.wrapper.WrapperListener;
   import com.silveregg.wrapper.WrapperManager;
  -import java.awt.event.ActionEvent;
  -import java.awt.event.ActionListener;
  +import java.util.Observer;
  +import java.util.Observable;
   import java.util.Hashtable;
   
   /**
  @@ -20,7 +20,7 @@
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    */
   public class DaemonLauncher
  -    implements WrapperListener, ActionListener
  +    implements WrapperListener, Observer
   {
       public Integer start( final String[] args )
       {
  @@ -28,7 +28,7 @@
           WrapperManager.signalStarting( 45000 );
   
           final Hashtable data = new Hashtable();
  -        data.put( ActionListener.class.getName(), this );
  +        data.put( Observer.class.getName(), this );
   
           if ( WrapperManager.isDebugEnabled() )
           {
  @@ -85,14 +85,14 @@
       }
   
       /**
  -     * We use an ActionListener rather than operating on some more meaningful
  -     * event system as ActionListener and friends can be loaded from system
  +     * We use an Observer rather than operating on some more meaningful
  +     * event system as Observer 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 )
  +    public void update( final Observable observable, final Object arg )
       {
  -        final String command = action.getActionCommand();
  +        final String command = ( null != arg ) ? arg.toString() : "";
           if( command.equals( "restart" ) )
           {
               if ( WrapperManager.isDebugEnabled() )
  
  
  

--
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