You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ha...@apache.org on 2002/01/26 09:22:43 UTC

cvs commit: jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/assembler Assembler.java

hammant     02/01/26 00:22:43

  Modified:    src/java/org/apache/avalon/phoenix/components/application
                        DefaultApplication.java LifecycleHelper.java
               src/java/org/apache/avalon/phoenix/components/kernel
                        DefaultKernel.java
               src/java/org/apache/avalon/phoenix/tools/assembler
                        Assembler.java
  Added:       src/java/org/apache/avalon/phoenix/components/application
                        ApplicationListenerSupport.java
  Log:
  Application Listener support added
  
  Revision  Changes    Path
  1.8       +36 -0     jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/DefaultApplication.java
  
  Index: DefaultApplication.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/DefaultApplication.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DefaultApplication.java	11 Dec 2001 10:13:33 -0000	1.7
  +++ DefaultApplication.java	26 Jan 2002 08:22:43 -0000	1.8
  @@ -15,10 +15,12 @@
   import org.apache.avalon.excalibur.lang.ThreadContext;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.phoenix.Block;
  +import org.apache.avalon.phoenix.ApplicationEvent;
   import org.apache.avalon.phoenix.interfaces.Application;
   import org.apache.avalon.phoenix.interfaces.ApplicationContext;
   import org.apache.avalon.phoenix.metadata.BlockListenerMetaData;
   import org.apache.avalon.phoenix.metadata.BlockMetaData;
  +import org.apache.avalon.phoenix.metadata.SarMetaData;
   
   /**
    * This is the basic container of blocks. A server application
  @@ -40,6 +42,12 @@
       private ApplicationContext m_context;
       private LifecycleHelper m_lifecycle;
       private HashMap m_entrys = new HashMap();
  +    private SarMetaData m_sarMetaData;
  +
  +    public DefaultApplication(SarMetaData sarMetaData)
  +    {
  +        m_sarMetaData = sarMetaData;
  +    }
   
       public void setApplicationContext( final ApplicationContext context )
       {
  @@ -159,6 +167,20 @@
           //Setup thread context for calling visitors
           ThreadContext.setThreadContext( m_context.getThreadContext() );
   
  +        //All blocks about to be processed ...
  +        if( PHASE_STARTUP == name )
  +        {
  +            //... for startup, so indicate to applicable listeners
  +            m_lifecycle.applicationStarting(new ApplicationEvent(m_sarMetaData.getName(), m_sarMetaData));
  +        }
  +        else
  +        {
  +            //... for shutdown, so indicate to applicable listeners
  +            m_lifecycle.applicationStopping();
  +        }
  +
  +        //Process blocks, one by one.
  +
           for( int i = 0; i < order.length; i++ )
           {
               final String block = order[ i ];
  @@ -181,6 +203,7 @@
                   final String message =
                       REZ.getString( "app.error.run-phase", name, block, e.getMessage() );
                   getLogger().error( message, e );
  +                m_lifecycle.applicationFailure(e);
                   throw e;
               }
   
  @@ -191,5 +214,18 @@
                   getLogger().debug( message );
               }
           }
  +
  +        //All blocks processed ...
  +        if( PHASE_STARTUP == name )
  +        {
  +            //... for startup, so indicate to applicable listeners
  +            m_lifecycle.applicationStarted();
  +        }
  +        else
  +        {
  +            //... for shutdown, so indicate to applicable listeners
  +            m_lifecycle.applicationStopped();
  +        }
  +
       }
   }
  
  
  
  1.28      +46 -4     jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/LifecycleHelper.java
  
  Index: LifecycleHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/LifecycleHelper.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- LifecycleHelper.java	25 Jan 2002 22:18:27 -0000	1.27
  +++ LifecycleHelper.java	26 Jan 2002 08:22:43 -0000	1.28
  @@ -33,6 +33,8 @@
   import org.apache.avalon.phoenix.BlockContext;
   import org.apache.avalon.phoenix.BlockEvent;
   import org.apache.avalon.phoenix.BlockListener;
  +import org.apache.avalon.phoenix.ApplicationListener;
  +import org.apache.avalon.phoenix.ApplicationEvent;
   import org.apache.avalon.phoenix.interfaces.Application;
   import org.apache.avalon.phoenix.interfaces.ApplicationContext;
   import org.apache.avalon.phoenix.metadata.BlockListenerMetaData;
  @@ -83,7 +85,12 @@
       /**
        * Object to support notification of BlockListeners.
        */
  -    private BlockListenerSupport m_listenerSupport = new BlockListenerSupport();
  +    private BlockListenerSupport m_blockListenerSupport = new BlockListenerSupport();
  +
  +    /**
  +     * Object to support notification of ApplicationListeners.
  +     */
  +    private ApplicationListenerSupport m_applicationListenerSupport = new ApplicationListenerSupport();
   
       /**
        * Construct helper object for specified application,
  @@ -129,7 +136,42 @@
               ( (Configurable)listener ).configure( configuration );
           }
   
  -        m_listenerSupport.addBlockListener( listener );
  +        // As ApplicationListners are BlockListeners then this is applicable for all
  +        m_blockListenerSupport.addBlockListener( listener );
  +
  +        // However onky ApplicationListners can avail of block events.
  +        if (listener instanceof ApplicationListener)
  +        {
  +            m_applicationListenerSupport.addApplicationListener( (ApplicationListener) listener );
  +        }
  +
  +
  +
  +    }
  +
  +    public void applicationStarting(ApplicationEvent appEvent) throws Exception
  +    {
  +        m_applicationListenerSupport.applicationStarting(appEvent);
  +    }
  +
  +    public void applicationStarted()
  +    {
  +        m_applicationListenerSupport.applicationStarted();
  +    }
  +
  +    public void applicationStopping()
  +    {
  +        m_applicationListenerSupport.applicationStopping();
  +    }
  +
  +    public void applicationStopped()
  +    {
  +        m_applicationListenerSupport.applicationStopped();
  +    }
  +
  +    public void applicationFailure(Exception causeOfFailure)
  +    {
  +        m_applicationListenerSupport.applicationFailure(causeOfFailure);
       }
   
       /**
  @@ -237,7 +279,7 @@
               final Block proxy = entry.getProxy();
               final BlockEvent event =
                   new BlockEvent( name, proxy, metaData.getBlockInfo() );
  -            m_listenerSupport.blockAdded( event );
  +            m_blockListenerSupport.blockAdded( event );
           }
           catch( final Throwable t )
           {
  @@ -262,7 +304,7 @@
   
           final BlockEvent event =
               new BlockEvent( name, entry.getProxy(), metaData.getBlockInfo() );
  -        m_listenerSupport.blockRemoved( event );
  +        m_blockListenerSupport.blockRemoved( event );
   
           final Block block = entry.getBlock();
   
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/ApplicationListenerSupport.java
  
  Index: ApplicationListenerSupport.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.phoenix.components.application;
  
  import org.apache.avalon.phoenix.ApplicationListener;
  import org.apache.avalon.phoenix.ApplicationEvent;
  
  /**
   * Manage a set of <code>ApplicationListener</code> objects and propogate
   * <code>ApplicationEvent</code> notifications to these listeners.  Not all
   * events pass an Applicationevent parameter.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @author <a href="mailto:Paul_Hammant@yahoo.com">Paul Hammant</a>
   */
  final class ApplicationListenerSupport
  {
      //Set of listeners. Must be accessed from synchronized code
      private ApplicationListener[] m_listeners = new ApplicationListener[ 0 ];
  
      /**
       * Add a ApplicationListener to those requiring notification of
       * <code>ApplicationEvent</code>s.
       *
       * @param listener the ApplicationListener
       */
      public synchronized void addApplicationListener( final ApplicationListener listener )
      {
          final ApplicationListener[] listeners = new ApplicationListener[ 1 + m_listeners.length ];
          System.arraycopy( m_listeners, 0, listeners, 0, m_listeners.length );
          listeners[ m_listeners.length ] = listener;
          m_listeners = listeners;
      }
  
      /**
       * Remove a ApplicationListener from those requiring notification of
       * <code>ApplicationEvent</code>s.
       *
       * @param listener the ApplicationListener
       */
      public synchronized void removeApplicationListener( final ApplicationListener listener )
      {
          int index = 0;
          while( index < m_listeners.length )
          {
              if( m_listeners[ index ] == listener ) break;
              index++;
          }
  
          if( m_listeners.length != index )
          {
              final ApplicationListener[] listeners = new ApplicationListener[ m_listeners.length - 1 ];
              System.arraycopy( m_listeners, 0, listeners, 0, index );
              final int length = m_listeners.length - index - 1;
              System.arraycopy( m_listeners, index + 1, listeners, index, length );
          }
      }
  
      /**
       * Notification that the application is starting
       *
       * @param event the ApplicationEvent
       */
      public synchronized void applicationStarting( final ApplicationEvent event ) throws Exception
      {
          for( int i = 0; i < m_listeners.length; i++ )
          {
              m_listeners[ i ].applicationStarting( event );
          }
      }
  
      /**
       * Notification that the application has started.
       *
       */
      public synchronized void applicationStarted()
      {
          for( int i = 0; i < m_listeners.length; i++ )
          {
              m_listeners[ i ].applicationStarted();
          }
      }
  
      /**
       * Notification that the application is stopping
       *
       */
      public synchronized void applicationStopping()
      {
          for( int i = 0; i < m_listeners.length; i++ )
          {
              m_listeners[ i ].applicationStopping();
          }
      }
  
      /**
       * Notification that the application has stopped
       *
       */
      public synchronized void applicationStopped()
      {
          for( int i = 0; i < m_listeners.length; i++ )
          {
              m_listeners[ i ].applicationStopped();
          }
      }
  
      /**
       * Notification that the application has failed
       *
       */
      public synchronized void applicationFailure(Exception causeOfFailure)
      {
          for( int i = 0; i < m_listeners.length; i++ )
          {
              m_listeners[ i ].applicationFailure(causeOfFailure);
          }
      }
  
  }
  
  
  
  1.49      +1 -1      jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/DefaultKernel.java
  
  Index: DefaultKernel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/DefaultKernel.java,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- DefaultKernel.java	12 Jan 2002 02:10:51 -0000	1.48
  +++ DefaultKernel.java	26 Jan 2002 08:22:43 -0000	1.49
  @@ -112,7 +112,7 @@
           {
               try
               {
  -                application = new DefaultApplication();
  +                application = new DefaultApplication(entry.getMetaData());
                   setupLogger( application, name );
   
                   final ApplicationContext context = createApplicationContext( entry );
  
  
  
  1.8       +29 -4     jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/assembler/Assembler.java
  
  Index: Assembler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/tools/assembler/Assembler.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Assembler.java	15 Dec 2001 04:57:07 -0000	1.7
  +++ Assembler.java	26 Jan 2002 08:22:43 -0000	1.8
  @@ -10,6 +10,8 @@
   import java.io.File;
   import java.net.URL;
   import java.util.ArrayList;
  +import java.util.Vector;
  +
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.framework.configuration.Configuration;
  @@ -71,8 +73,31 @@
           final Configuration[] blockConfig = assembly.getChildren( "block" );
           final BlockMetaData[] blocks = buildBlocks( blockConfig, classLoader );
   
  -        final Configuration[] listenerConfig = assembly.getChildren( "block-listener" );
  -        final BlockListenerMetaData[] listeners = buildBlockListeners( listenerConfig );
  +        final Configuration[] listenerConfig = assembly.getChildren( "listener" );
  +        BlockListenerMetaData[] listeners = buildBlockListeners( listenerConfig );
  +
  +        // to be phased out - support for the old block-listener descriptor
  +        final Configuration[] legacyListenerConfig = assembly.getChildren( "block-listener" );
  +        final BlockListenerMetaData[] legacyListeners = buildBlockListeners( legacyListenerConfig );
  +        for (int i = 0; i < legacyListeners.length; i++) {
  +            BlockListenerMetaData data = legacyListeners[i];
  +            boolean matched = false;
  +            for (int j = 0; j < listeners.length; j++) {
  +                BlockListenerMetaData data2 = listeners[j];
  +                if (data.getClassname().equals(data2.getClassname())) {
  +                    matched = true;
  +                }
  +            }
  +            if (!matched) {
  +                getLogger().warn("Listener with old style element name 'block-listener' encounted.  Please change " +
  +                       "this to 'listener' before compatability is imminently removed from Phoenix");
  +                final BlockListenerMetaData[] newListeners = new BlockListenerMetaData[ 1 + listeners.length ];
  +                System.arraycopy( listeners, 0, listeners, 0, listeners.length );
  +                newListeners[ listeners.length ] = data;
  +                listeners = newListeners;
  +            }
  +        }
  +
   
           return new SarMetaData( name, directory, blocks, listeners );
       }
  @@ -175,7 +200,7 @@
   
       /**
        * Create an array of <code>BlockListenerMetaData</code> objects to represent
  -     * the &lt;block-listener .../&gt; sections in <code>assembly.xml</code>.
  +     * the &lt;listener .../&gt; sections in <code>assembly.xml</code>.
        *
        * @param listeners the list of Configuration objects for listeners
        * @return the BlockListenerMetaData array
  @@ -196,7 +221,7 @@
   
       /**
        * Create a <code>BlockListenerMetaData</code> object to represent
  -     * the specified &lt;block-listener .../&gt; section.
  +     * the specified &lt;listener .../&gt; section.
        *
        * @param listener the Configuration object for listener
        * @return the BlockListenerMetaData object
  
  
  

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