colus 02/01/14 02:36:27
Modified: src/java/org/apache/avalon/cornerstone/services/rmification
RMIficationListener.java
Log:
Some javadoc. Variable and method renaming.
Revision Changes Path
1.3 +45 -35
jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/services/rmification/RMIficationListener.java
Index: RMIficationListener.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/services/rmification/RMIficationListener.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RMIficationListener.java 11 Jan 2002 14:03:18 -0000 1.2
+++ RMIficationListener.java 14 Jan 2002 10:36:27 -0000 1.3
@@ -17,28 +17,36 @@
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.phoenix.Block;
import org.apache.avalon.phoenix.BlockEvent;
import org.apache.avalon.phoenix.BlockListener;
/**
* FIXME: INPROGRESS and NOT TESTED
+ * Publish blocks via RMI.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Eung-ju Park</a>
- * @version $Revision: 1.2 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Eung-ju Park</a>
+ * @version $Revision: 1.3 $
*/
public class RMIficationListener
+ extends AbstractLogEnabled
implements Configurable, BlockListener
{
- private String m_publisherName;
- private RMIfication m_publisher;
- private Map m_publications;
- private List m_queue;
+ /** <code>RMIfication</code> block's name */
+ private String m_publisherName;
+ /** <code>RMIfication</code> block */
+ private RMIfication m_publisher;
+ /** publications */
+ private Map m_publications;
+ /** delayed events */
+ private List m_delayedEvents;
public void configure( final Configuration configuration )
throws ConfigurationException
{
- m_publisherName = configuration.getChild( "publisher" ).getValue(
"rmification" );
+ m_publisherName =
+ configuration.getChild( "publisher" ).getValue( "rmification" );
m_publications = new HashMap();
final Configuration[] confs = configuration.getChildren( "publish" );
@@ -52,45 +60,29 @@
m_publications.put( name, blockName );
}
- m_queue = new ArrayList();
+ m_delayedEvents = new ArrayList();
}
public void blockAdded( final BlockEvent event )
{
- System.out.println( "Block " + event.getName() + " added" );
-
if ( m_publisherName.equals( event.getName() ) )
{
- System.out.println( "Found publisher" );
+ getLogger().debug( "Found publisher block: " + event.getName() );
m_publisher = (RMIfication)event.getBlock();
- for ( int i = 0; i < m_queue.size(); i++ )
- {
- final BlockEvent queued = (BlockEvent)m_queue.get( i );
- publishBlock( event );
- }
- m_queue.clear();
- m_queue = null;
+
+ processDelayedEvents();
}
if ( m_publications.containsValue( event.getName() ) )
{
- if ( event.getBlock() instanceof Remote )
- {
- publishBlock( event );
- }
- else
- {
- //FIXME: throw exception
- }
+ publishBlock( event );
}
}
public void blockRemoved( final BlockEvent event )
{
- System.out.println( "Block " + event.getName() + " added" );
-
- if ( event.getBlock() instanceof Remote )
+ if ( m_publications.containsValue( event.getName() ) )
{
unpublishBlock( event );
}
@@ -101,11 +93,22 @@
return null != m_publisher;
}
+ private void processDelayedEvents()
+ {
+ final Iterator delayedEvents = m_delayedEvents.iterator();
+ while ( delayedEvents.hasNext() )
+ {
+ publishBlock( (BlockEvent)delayedEvents.next() );
+ }
+ m_delayedEvents.clear();
+ m_delayedEvents = null;
+ }
+
private void publishBlock( final BlockEvent event )
{
if ( ! isPublisherReady() )
{
- m_queue.add( event );
+ m_delayedEvents.add( event );
return;
}
@@ -116,16 +119,20 @@
while ( entries.hasNext() )
{
final Map.Entry entry = (Map.Entry)entries.next();
+ final String publicationName = (String)entry.getKey();
if ( entry.getValue().equals( blockName ) )
{
try
{
- m_publisher.publish( (Remote)block,
(String)entry.getKey() );
+ m_publisher.publish( (Remote)block, publicationName );
+
}
catch ( final Exception e )
{
- throw new CascadingRuntimeException( "Unable to publish
" + entry.getKey(), e );
+ final String message =
+ "Fail to publish " + publicationName;
+ throw new CascadingRuntimeException( message, e );
}
}
}
@@ -140,18 +147,21 @@
while ( entries.hasNext() )
{
final Map.Entry entry = (Map.Entry)entries.next();
+ final String publicationName = (String)entry.getKey();
if ( entry.getValue().equals( blockName ) )
{
try
{
- m_publisher.unpublish( (String)entry.getKey() );
+ m_publisher.unpublish( publicationName );
}
catch ( final Exception e )
{
- throw new CascadingRuntimeException( "Fail to unpublish
" + entry.getKey(), e );
+ final String message =
+ "Fail to unpublish " + publicationName;
+ throw new CascadingRuntimeException( message, e );
}
}
}
}
-}
\ No newline at end of file
+}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>