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 2002/05/19 04:44:33 UTC
cvs commit: jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application ApplicationListenerSupport.java AppLifecycleHelper.java BlockListenerSupport.java
donaldp 02/05/18 19:44:33
Modified: src/java/org/apache/avalon/phoenix/components/application
ApplicationListenerSupport.java
AppLifecycleHelper.java
Removed: src/java/org/apache/avalon/phoenix/components/application
BlockListenerSupport.java
Log:
Merge BlockListenerSupport into ApplicaitonListenerSupport.
Revision Changes Path
1.5 +135 -5 jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/ApplicationListenerSupport.java
Index: ApplicationListenerSupport.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/ApplicationListenerSupport.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ApplicationListenerSupport.java 19 May 2002 02:15:58 -0000 1.4
+++ ApplicationListenerSupport.java 19 May 2002 02:44:33 -0000 1.5
@@ -9,7 +9,10 @@
import org.apache.avalon.phoenix.ApplicationEvent;
import org.apache.avalon.phoenix.ApplicationListener;
+import org.apache.avalon.phoenix.BlockEvent;
+import org.apache.avalon.phoenix.BlockListener;
import org.apache.avalon.phoenix.metadata.SarMetaData;
+import org.apache.avalon.phoenix.metadata.BlockMetaData;
/**
* Manage a set of <code>ApplicationListener</code> objects and propogate
@@ -21,10 +24,66 @@
*/
final class ApplicationListenerSupport
{
+ //Set of block listeners. Must be accessed from synchronized code
+ private BlockListener[] m_blockListeners = new BlockListener[ 0 ];
+
//Set of listeners. Must be accessed from synchronized code
private ApplicationListener[] m_listeners = new ApplicationListener[ 0 ];
/**
+ * fire Event indicating that the Application represented
+ * by specified metaData is starting.
+ *
+ * @param metaData the metaData
+ */
+ void fireApplicationStartingEvent( final SarMetaData metaData )
+ throws Exception
+ {
+ final ApplicationEvent event =
+ new ApplicationEvent( metaData.getName(), metaData );
+ applicationStarting( event );
+ }
+
+ /**
+ * fire Event indicating that Block represented by
+ * specific entry has been added.
+ *
+ * @param entry the entry
+ */
+ void fireBlockAddedEvent( final BlockEntry entry )
+ {
+ blockAdded( createEvent( entry ) );
+ }
+
+ /**
+ * fire Event indicating that Block represented by
+ * specific entry is being removed.
+ *
+ * @param entry the entry
+ */
+ void fireBlockRemovedEvent( final BlockEntry entry )
+ {
+ blockRemoved( createEvent( entry ) );
+ }
+
+ /**
+ * Utility method to create an event for a
+ * specific entry.
+ *
+ * @param entry the entry
+ * @return the new event
+ */
+ private BlockEvent createEvent( final BlockEntry entry )
+ {
+ final BlockMetaData metaData = entry.getMetaData();
+ final BlockEvent event =
+ new BlockEvent( metaData.getName(),
+ entry.getProxy(),
+ metaData.getBlockInfo() );
+ return event;
+ }
+
+ /**
* Add a ApplicationListener to those requiring notification of
* <code>ApplicationEvent</code>s.
*
@@ -62,15 +121,47 @@
}
}
- void fireApplicationStartingEvent( final SarMetaData metaData )
- throws Exception
+
+ /**
+ * Add a BlockListener to those requiring notification of
+ * <code>BlockEvent</code>s.
+ *
+ * @param listener the BlockListener
+ */
+ public synchronized void addBlockListener( final BlockListener listener )
{
- final ApplicationEvent event =
- new ApplicationEvent( metaData.getName(), metaData );
- applicationStarting( event );
+ final BlockListener[] listeners = new BlockListener[ 1 + m_blockListeners.length ];
+ System.arraycopy( m_blockListeners, 0, listeners, 0, m_blockListeners.length );
+ listeners[ m_listeners.length ] = listener;
+ m_blockListeners = listeners;
}
/**
+ * Remove a BlockListener from those requiring notification of
+ * <code>BlockEvent</code>s.
+ *
+ * @param listener the BlockListener
+ */
+ public synchronized void removeBlockListener( final BlockListener listener )
+ {
+ int index = 0;
+ while( index < m_blockListeners.length )
+ {
+ if( m_blockListeners[ index ] == listener ) break;
+ index++;
+ }
+
+ if( m_blockListeners.length != index )
+ {
+ final BlockListener[] listeners = new BlockListener[ m_blockListeners.length - 1 ];
+ System.arraycopy( m_blockListeners, 0, listeners, 0, index );
+ final int length = m_blockListeners.length - index - 1;
+ System.arraycopy( m_blockListeners, index + 1, listeners, index, length );
+ }
+ }
+
+
+ /**
* Notification that the application is starting
*
* @param event the ApplicationEvent
@@ -132,4 +223,43 @@
}
}
+ /**
+ * Notification that a block has just been added
+ * to Server Application.
+ *
+ * @param event the BlockEvent
+ */
+ public synchronized void blockAdded( final BlockEvent event )
+ {
+ for( int i = 0; i < m_listeners.length; i++ )
+ {
+ m_listeners[ i ].blockAdded( event );
+ }
+
+ //Now notify the plain BlockListeners
+ for( int i = 0; i < m_blockListeners.length; i++ )
+ {
+ m_blockListeners[ i ].blockAdded( event );
+ }
+ }
+
+ /**
+ * Notification that a block is just about to be
+ * removed from Server Application.
+ *
+ * @param event the BlockEvent
+ */
+ public synchronized void blockRemoved( final BlockEvent event )
+ {
+ for( int i = 0; i < m_listeners.length; i++ )
+ {
+ m_listeners[ i ].blockRemoved( event );
+ }
+
+ //Now notify the plain BlockListeners
+ for( int i = 0; i < m_blockListeners.length; i++ )
+ {
+ m_blockListeners[ i ].blockRemoved( event );
+ }
+ }
}
1.3 +9 -13 jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/AppLifecycleHelper.java
Index: AppLifecycleHelper.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/AppLifecycleHelper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AppLifecycleHelper.java 19 May 2002 02:35:26 -0000 1.2
+++ AppLifecycleHelper.java 19 May 2002 02:44:33 -0000 1.3
@@ -41,14 +41,9 @@
private ApplicationContext m_context;
/**
- * Object to support notification of BlockListeners.
- */
- private BlockListenerSupport m_blockListenerSupport = new BlockListenerSupport();
-
- /**
* Object to support notification of ApplicationListeners.
*/
- private ApplicationListenerSupport m_applicationListenerSupport =
+ private ApplicationListenerSupport m_listenerSupport =
new ApplicationListenerSupport();
private final LifecycleHelper m_lifecycleHelper = new LifecycleHelper();
@@ -113,16 +108,17 @@
ContainerUtil.configure( listener, configuration );
}
- // As ApplicationListners are BlockListeners then this is applicable for all
- m_blockListenerSupport.addBlockListener( (BlockListener)listener );
-
// However onky ApplicationListners can avail of block events.
if( listener instanceof ApplicationListener )
{
- m_applicationListenerSupport.addApplicationListener( (ApplicationListener)listener );
+ m_listenerSupport.addApplicationListener( (ApplicationListener)listener );
}
else
{
+ // As ApplicationListners are BlockListeners then
+ //this is applicable for all
+ m_listenerSupport.addBlockListener( (BlockListener)listener );
+
final String message =
REZ.getString( "helper.isa-blocklistener.error",
name,
@@ -134,7 +130,7 @@
ApplicationListenerSupport getAppListenerSupport()
{
- return m_applicationListenerSupport;
+ return m_listenerSupport;
}
/**
@@ -158,7 +154,7 @@
m_exportHelper.exportBlock( m_context, entry.getMetaData(), block );
entry.setObject( block );
- m_blockListenerSupport.fireBlockAddedEvent( entry );
+ m_listenerSupport.fireBlockAddedEvent( entry );
}
/**
@@ -172,7 +168,7 @@
*/
public void shutdown( final BlockEntry entry )
{
- m_blockListenerSupport.fireBlockRemovedEvent( entry );
+ m_listenerSupport.fireBlockRemovedEvent( entry );
//Remove block from Management system
m_exportHelper.unexportBlock( m_context, entry.getMetaData(), entry.getObject() );
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>