You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by co...@apache.org on 2002/01/11 06:58:42 UTC
cvs commit: jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/services/rmification RMIfication.java
colus 02/01/10 21:58:42
Added: src/java/org/apache/avalon/cornerstone/blocks/rmification
DefaultRMIfication.java DefaultRMIfication.xinfo
src/java/org/apache/avalon/cornerstone/listeners
RMIficationListener.java
src/java/org/apache/avalon/cornerstone/services/rmification
RMIfication.java
Log:
Initial implementation of RMI publisher and RMI publishing block listener.
Revision Changes Path
1.1 jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/rmification/DefaultRMIfication.java
Index: DefaultRMIfication.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 file.
*/
package org.apache.avalon.cornerstone.blocks.rmification;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.HashMap;
import java.util.Map;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
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.cornerstone.services.rmification.RMIfication;
/**
* FIXME: INPROGRESS
* Default implementation of <code>RMIfication</code>.
*
* @author <a href="mailto:colus@apache.org">Eung-ju Park</a>
*/
public class DefaultRMIfication
extends AbstractLogEnabled
implements Configurable, Initializable, Disposable, RMIfication, Block
{
private int m_port;
private Registry m_registry;
private Map m_remoteObjects;
public void configure( final Configuration configuration )
throws ConfigurationException
{
m_port = configuration.getChild( "port" ).getValueAsInteger();
}
public void initialize()
throws Exception
{
m_remoteObjects = new HashMap();
m_registry = LocateRegistry.createRegistry( m_port );
}
public void dispose()
{
m_registry = null;
m_remoteObjects.clear();
m_remoteObjects = null;
}
public void publish( final Remote remote, final String publicationName )
throws RemoteException, MalformedURLException
{
synchronized ( m_remoteObjects )
{
UnicastRemoteObject.exportObject( remote );
m_registry.rebind( publicationName, remote );
m_remoteObjects.put( publicationName, remote );
}
}
public void unpublish( final String publicationName )
throws RemoteException, NotBoundException, MalformedURLException
{
synchronized ( m_remoteObjects )
{
final Remote remote = (Remote)m_remoteObjects.get( publicationName );
m_registry.unbind( publicationName );
UnicastRemoteObject.unexportObject( remote, true );
m_remoteObjects.remove( publicationName );
}
}
}
1.1 jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/rmification/DefaultRMIfication.xinfo
Index: DefaultRMIfication.xinfo
===================================================================
<?xml version="1.0"?>
<blockinfo>
<!-- section to describe block -->
<block>
<version>1.0</version>
</block>
<!-- services that are offered by this block -->
<services>
<service name="org.apache.avalon.cornerstone.services.rmification.RMIfication" version="1.0" />
</services>
</blockinfo>
1.1 jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/listeners/RMIficationListener.java
Index: RMIficationListener.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 file.
*/
package org.apache.avalon.cornerstone.listeners;
import java.rmi.Remote;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.avalon.framework.CascadingRuntimeException;
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.phoenix.Block;
import org.apache.avalon.phoenix.BlockEvent;
import org.apache.avalon.phoenix.BlockListener;
import org.apache.avalon.cornerstone.services.rmification.RMIfication;
/**
* FIXME: INPROGRESS
*
* @author <a href="mailto:colus@isoft.co.kr">Eung-ju Park</a>
*/
public class RMIficationListener
implements Configurable, BlockListener
{
private String m_publisherName;
private RMIfication m_publisher;
private Map m_publications;
private List m_queue;
public void configure( final Configuration configuration )
throws ConfigurationException
{
m_publisherName = configuration.getChild( "publisher" ).getValue( "rmification" );
m_publications = new HashMap();
final Configuration[] confs = configuration.getChildren( "publish" );
for ( int i = 0; i < confs.length; i++ )
{
final Configuration conf = confs[ i ];
final String blockName = conf.getAttribute( "remote" );
final String name = conf.getAttribute( "name", blockName );
m_publications.put( name, blockName );
}
}
public void blockAdded( final BlockEvent event )
{
if ( m_publisherName.equals( 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;
}
if ( m_publications.containsKey( event.getName() ) )
{
if ( event.getBlock() instanceof Remote )
{
publishBlock( event );
}
else
{
//FIXME: throw exception
}
}
}
public void blockRemoved( final BlockEvent event )
{
if ( event.getBlock() instanceof Remote )
{
unpublishBlock( event );
}
}
private boolean isPublisherReady()
{
return null != m_publisher;
}
private void publishBlock( final BlockEvent event )
{
if ( !isPublisherReady() )
{
m_queue.add( event );
return;
}
final Block block = event.getBlock();
final String blockName = event.getName();
final Iterator entries = m_publications.entrySet().iterator();
while ( entries.hasNext() )
{
final Map.Entry entry = (Map.Entry)entries.next();
if ( entry.getValue().equals( blockName ) )
{
try
{
m_publisher.publish( (Remote)block, (String)entry.getKey() );
}
catch ( final Exception e )
{
throw new CascadingRuntimeException( "", e );
}
}
}
}
private void unpublishBlock( final BlockEvent event )
{
final Block block = event.getBlock();
final String blockName = event.getName();
final Iterator entries = m_publications.entrySet().iterator();
while ( entries.hasNext() )
{
final Map.Entry entry = (Map.Entry)entries.next();
if ( entry.getValue().equals( blockName ) )
{
try
{
m_publisher.unpublish( (String)entry.getKey() );
}
catch ( final Exception e )
{
throw new CascadingRuntimeException( "", e );
}
}
}
}
}
1.1 jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/services/rmification/RMIfication.java
Index: RMIfication.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 file.
*/
package org.apache.avalon.cornerstone.services.rmification;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
* FIXME: INPROGRESS
* This service provides a way to publish an <code>Remote<code> object via RMI.
*
* @author <a href="mailto:colus@apache.org">Eung-ju Park</a>
*/
public interface RMIfication
{
String ROLE = "org.apache.avalon.cornerstone.services.rmification.RMIfication";
/**
* Publish a set of interfaces
*
* @param remote the remote object to publish
* @param publicationName The name to publish it as.
*/
void publish( Remote remote, String publicationName )
throws RemoteException, MalformedURLException;
/**
* Unpublish
*
* @param publicationName the name of the object to unpublish
*/
public void unpublish( final String publicationName )
throws RemoteException, NotBoundException, MalformedURLException;
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>