org.softamis.cluster4spring.rmi
Class AbstractRmiServiceExporter

java.lang.Object
  extended by org.springframework.remoting.support.RemoteExporter
      extended by org.springframework.remoting.support.RemoteInvocationBasedExporter
          extended by org.softamis.cluster4spring.rmi.AbstractRmiServiceExporter
All Implemented Interfaces:
AutoDiscoveredServiceExporter, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
MultihomeRmiServiceExporter, RmiServiceExporter

public abstract class AbstractRmiServiceExporter
extends org.springframework.remoting.support.RemoteInvocationBasedExporter
implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean, AutoDiscoveredServiceExporter, org.springframework.beans.factory.BeanFactoryAware

Abstract implementation of Service Exporter to export remote services via RMI


Field Summary
static java.lang.String ATTRIBUTE_OWN_PROXY_SERVICE_NAME
           
protected  boolean fAllowsAutoDiscovering
           
protected  org.springframework.beans.factory.BeanFactory fBeanFactory
           
protected  java.rmi.server.RMIClientSocketFactory fClientSocketFactory
           
protected  java.rmi.Remote fExportedObject
           
protected  java.lang.String[] fInterceptorNames
           
protected  java.rmi.registry.Registry fRegistry
           
protected  java.rmi.server.RMIClientSocketFactory fRegistryClientSocketFactory
           
protected  java.lang.String fRegistryHost
           
protected  int fRegistryPort
           
protected  java.rmi.server.RMIServerSocketFactory fRegistryServerSocketFactory
           
protected  org.aopalliance.intercept.MethodInterceptor fRemoteInvocationTraceInterceptor
           
protected  java.rmi.server.RMIServerSocketFactory fServerSocketFactory
           
protected  java.lang.String fServiceGroup
           
protected  java.lang.String fServiceName
           
protected  int fServicePort
           
 
Fields inherited from class org.springframework.remoting.support.RemoteExporter
logger
 
Fields inherited from interface org.softamis.cluster4spring.AutoDiscoveredServiceExporter
DEFAULT_SERVICES_GROUP_PREFIX
 
Constructor Summary
AbstractRmiServiceExporter()
           
 
Method Summary
 void afterPropertiesSet()
           
protected  org.aopalliance.intercept.MethodInterceptor createDefaultRemoteInvocationTraceInterceptor()
           
protected  java.lang.String createServiceUrl(java.lang.String aServiceAddress, int aServicePort)
           
 void destroy()
          Unbind the RMI service from the fRegistry on bean factory shutdown.
protected  void exportObject()
           
 java.lang.String[] getInterceptorNames()
           
protected  java.rmi.Remote getObjectToExport()
           
protected  java.lang.Object getProxyForService()
          Get a proxy for the given service object, implementing the specified service interface.
 java.rmi.registry.Registry getRegistry()
          Returns RMI registry used for exporting remote objects
protected  java.rmi.registry.Registry getRegistry(int aRegistryPort)
          Locate or create the RMI fRegistry for this exporter.
protected  java.rmi.registry.Registry getRegistry(int aRegistryPort, java.rmi.server.RMIClientSocketFactory aClientSocketFactory, java.rmi.server.RMIServerSocketFactory aServerSocketFactory)
          Locate or create the RMI fRegistry for this exporter.
protected  java.rmi.registry.Registry getRegistry(java.lang.String aRegistryHost, int aRegistryPort, java.rmi.server.RMIClientSocketFactory aClientSocketFactory, java.rmi.server.RMIServerSocketFactory aServerSocketFactory)
          Locate or create the RMI fRegistry for this exporter.
 java.lang.String getRegistryHost()
          Returns host where RMI Registry is located
 int getRegistryPort()
          Returns port for RMI Registry
 java.lang.String getServiceGroup()
          Services exporter by exporters may belong to serveral groups.
 java.lang.String getServiceName()
          Returns name of the service
 int getServicePort()
           
 boolean isAllowsAutoDiscovering()
          Indicates whether particular exporter is available for publishing in auto-discoverable services.
protected  org.aopalliance.intercept.MethodInterceptor obtainRemoteInvocationTraceInterceptor()
           
protected  void prepare()
           
protected  void prepareRegistry()
           
 void setAllowsAutoDiscovering(boolean aAllowsAutoDiscovering)
           
 void setBeanFactory(org.springframework.beans.factory.BeanFactory aBeanFactory)
           
 void setClientSocketFactory(java.rmi.server.RMIClientSocketFactory aClientSocketFactory)
          Set a custom RMI client socket factory to use for exporting the service.
 void setInterceptorNames(java.lang.String[] aInterceptorNames)
           
 void setRegistry(java.rmi.registry.Registry aRegistry)
          Specify the RMI fRegistry to register the exported service with.
 void setRegistryClientSocketFactory(java.rmi.server.RMIClientSocketFactory aRegistryClientSocketFactory)
          Set a custom RMI client socket factory to use for the RMI fRegistry.
 void setRegistryHost(java.lang.String aRegistryHost)
          Set the port of the fRegistry for the exported RMI service, i.e.
 void setRegistryPort(int aRegistryPort)
          Set the port of the fRegistry for the exported RMI service, i.e.
 void setRegistryServerSocketFactory(java.rmi.server.RMIServerSocketFactory aRegistryServerSocketFactory)
          Set a custom RMI server socket factory to use for the RMI fRegistry.
 void setRemoteInvocationTraceInterceptor(org.aopalliance.intercept.MethodInterceptor aRemoteInvocationTraceInterceptor)
           
 void setServerSocketFactory(java.rmi.server.RMIServerSocketFactory aServerSocketFactory)
          Set a custom RMI server socket factory to use for exporting the service.
 void setServiceGroup(java.lang.String aServiceGroup)
           
 void setServiceName(java.lang.String aServiceName)
          Set the name of the exported RMI service, i.e.
 void setServicePort(int aServicePort)
          Set the port that the exported RMI service will use.
protected  void testRegistry(java.rmi.registry.Registry aRegistry)
          Test the given RMI fRegistry, calling some operation on it to check whether it is still active.
protected  void unexportObjectSilently(java.rmi.Remote aRemote)
          Unexport the registered RMI object, logging any exception that arises.
protected  void unexportServiceObject(java.rmi.registry.Registry aRegistry, java.lang.String aServiceName, int aRegistryPort, java.rmi.Remote aExportedObject)
           
 
Methods inherited from class org.springframework.remoting.support.RemoteInvocationBasedExporter
getRemoteInvocationExecutor, invoke, invokeAndCreateResult, setRemoteInvocationExecutor
 
Methods inherited from class org.springframework.remoting.support.RemoteExporter
checkService, checkServiceInterface, getExporterName, getService, getServiceInterface, isRegisterTraceInterceptor, setBeanClassLoader, setRegisterTraceInterceptor, setService, setServiceInterface
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.softamis.cluster4spring.AutoDiscoveredServiceExporter
provideExportedServiceURLs
 

Field Detail

fServiceName

protected java.lang.String fServiceName

fClientSocketFactory

protected java.rmi.server.RMIClientSocketFactory fClientSocketFactory

fServerSocketFactory

protected java.rmi.server.RMIServerSocketFactory fServerSocketFactory

fAllowsAutoDiscovering

protected boolean fAllowsAutoDiscovering

fServiceGroup

protected java.lang.String fServiceGroup

fBeanFactory

protected org.springframework.beans.factory.BeanFactory fBeanFactory

fInterceptorNames

protected java.lang.String[] fInterceptorNames

fRegistryClientSocketFactory

protected java.rmi.server.RMIClientSocketFactory fRegistryClientSocketFactory

fRemoteInvocationTraceInterceptor

protected org.aopalliance.intercept.MethodInterceptor fRemoteInvocationTraceInterceptor

fRegistryServerSocketFactory

protected java.rmi.server.RMIServerSocketFactory fRegistryServerSocketFactory

fServicePort

protected int fServicePort

fRegistryPort

protected int fRegistryPort

fRegistry

protected java.rmi.registry.Registry fRegistry

fRegistryHost

protected java.lang.String fRegistryHost

fExportedObject

protected java.rmi.Remote fExportedObject

ATTRIBUTE_OWN_PROXY_SERVICE_NAME

public static final java.lang.String ATTRIBUTE_OWN_PROXY_SERVICE_NAME
See Also:
Constant Field Values
Constructor Detail

AbstractRmiServiceExporter

public AbstractRmiServiceExporter()
Method Detail

setBeanFactory

public void setBeanFactory(org.springframework.beans.factory.BeanFactory aBeanFactory)
                    throws org.springframework.beans.BeansException
Specified by:
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
Throws:
org.springframework.beans.BeansException

getProxyForService

protected java.lang.Object getProxyForService()
Get a proxy for the given service object, implementing the specified service interface.

Used to export a proxy that does not expose any internals but just a specific interface intended for remote access. Furthermore, a RemoteInvocationTraceInterceptor gets registered (by default).

Overrides:
getProxyForService in class org.springframework.remoting.support.RemoteExporter
Returns:
the proxy
See Also:
RemoteExporter.setServiceInterface(java.lang.Class), RemoteExporter.setRegisterTraceInterceptor(boolean), RemoteInvocationTraceInterceptor

obtainRemoteInvocationTraceInterceptor

protected org.aopalliance.intercept.MethodInterceptor obtainRemoteInvocationTraceInterceptor()

createDefaultRemoteInvocationTraceInterceptor

protected org.aopalliance.intercept.MethodInterceptor createDefaultRemoteInvocationTraceInterceptor()

testRegistry

protected void testRegistry(java.rmi.registry.Registry aRegistry)
                     throws java.rmi.RemoteException
Test the given RMI fRegistry, calling some operation on it to check whether it is still active.

Default implementation calls Registry.list().

Parameters:
aRegistry - the RMI fRegistry to test
Throws:
java.rmi.RemoteException - if thrown by fRegistry methods
See Also:
Registry.list()

unexportServiceObject

protected void unexportServiceObject(java.rmi.registry.Registry aRegistry,
                                     java.lang.String aServiceName,
                                     int aRegistryPort,
                                     java.rmi.Remote aExportedObject)

unexportObjectSilently

protected void unexportObjectSilently(java.rmi.Remote aRemote)
Unexport the registered RMI object, logging any exception that arises.

Parameters:
aRemote - remote object to unexport

setAllowsAutoDiscovering

public void setAllowsAutoDiscovering(boolean aAllowsAutoDiscovering)

getServiceGroup

public java.lang.String getServiceGroup()
Description copied from interface: AutoDiscoveredServiceExporter
Services exporter by exporters may belong to serveral groups. In general, the groups of services are intended to support auto-discovering services and are less important if client uses one or more predefined services' URL's.

Groups could be used by ServicePublishers to select which services should be published and also allows to precisly control discovered services visibility on the client side.

Specified by:
getServiceGroup in interface AutoDiscoveredServiceExporter
Returns:
name of group which exported service belong to.

setServiceGroup

public void setServiceGroup(java.lang.String aServiceGroup)

setServiceName

public void setServiceName(java.lang.String aServiceName)
Set the name of the exported RMI service, i.e. rmi://host:port/NAME


getServiceName

public java.lang.String getServiceName()
Description copied from interface: AutoDiscoveredServiceExporter
Returns name of the service

Specified by:
getServiceName in interface AutoDiscoveredServiceExporter
Returns:
service name

setClientSocketFactory

public void setClientSocketFactory(java.rmi.server.RMIClientSocketFactory aClientSocketFactory)
Set a custom RMI client socket factory to use for exporting the service.

If the given object also implements java.rmi.server.RMIServerSocketFactory, it will automatically be registered as server socket factory too.

See Also:
setServerSocketFactory(java.rmi.server.RMIServerSocketFactory), RMIClientSocketFactory, RMIServerSocketFactory, UnicastRemoteObject.exportObject(java.rmi.Remote,int,java.rmi.server.RMIClientSocketFactory,java.rmi.server.RMIServerSocketFactory)

setServerSocketFactory

public void setServerSocketFactory(java.rmi.server.RMIServerSocketFactory aServerSocketFactory)
Set a custom RMI server socket factory to use for exporting the service.

Only needs to be specified when the client socket factory does not implement java.rmi.server.RMIServerSocketFactory already.

See Also:
setClientSocketFactory(java.rmi.server.RMIClientSocketFactory), RMIClientSocketFactory, RMIServerSocketFactory, UnicastRemoteObject.exportObject(java.rmi.Remote,int,java.rmi.server.RMIClientSocketFactory,java.rmi.server.RMIServerSocketFactory)

getInterceptorNames

public java.lang.String[] getInterceptorNames()

setInterceptorNames

public void setInterceptorNames(java.lang.String[] aInterceptorNames)

setRemoteInvocationTraceInterceptor

public void setRemoteInvocationTraceInterceptor(org.aopalliance.intercept.MethodInterceptor aRemoteInvocationTraceInterceptor)

setRegistryClientSocketFactory

public void setRegistryClientSocketFactory(java.rmi.server.RMIClientSocketFactory aRegistryClientSocketFactory)
Set a custom RMI client socket factory to use for the RMI fRegistry.

If the given object also implements java.rmi.server.RMIServerSocketFactory, it will automatically be registered as server socket factory too.

See Also:
setRegistryServerSocketFactory(java.rmi.server.RMIServerSocketFactory), RMIClientSocketFactory, RMIServerSocketFactory, LocateRegistry.getRegistry(String,int,java.rmi.server.RMIClientSocketFactory)

setRegistryServerSocketFactory

public void setRegistryServerSocketFactory(java.rmi.server.RMIServerSocketFactory aRegistryServerSocketFactory)
Set a custom RMI server socket factory to use for the RMI fRegistry.

Only needs to be specified when the client socket factory does not implement java.rmi.server.RMIServerSocketFactory already.

See Also:
setRegistryClientSocketFactory(java.rmi.server.RMIClientSocketFactory), RMIClientSocketFactory, RMIServerSocketFactory, LocateRegistry.createRegistry(int,java.rmi.server.RMIClientSocketFactory,java.rmi.server.RMIServerSocketFactory)

getRegistry

protected java.rmi.registry.Registry getRegistry(java.lang.String aRegistryHost,
                                                 int aRegistryPort,
                                                 java.rmi.server.RMIClientSocketFactory aClientSocketFactory,
                                                 java.rmi.server.RMIServerSocketFactory aServerSocketFactory)
                                          throws java.rmi.RemoteException
Locate or create the RMI fRegistry for this exporter.

Parameters:
aRegistryHost - the fRegistry host to use (if this is specified, no implicit creation of a RMI fRegistry will happen)
aRegistryPort - the fRegistry port to use
aClientSocketFactory - the RMI client socket factory for the fRegistry (if any)
aServerSocketFactory - the RMI server socket factory for the fRegistry (if any)
Returns:
the RMI fRegistry
Throws:
java.rmi.RemoteException - if the fRegistry couldn't be located or created

getRegistry

protected java.rmi.registry.Registry getRegistry(int aRegistryPort,
                                                 java.rmi.server.RMIClientSocketFactory aClientSocketFactory,
                                                 java.rmi.server.RMIServerSocketFactory aServerSocketFactory)
                                          throws java.rmi.RemoteException
Locate or create the RMI fRegistry for this exporter.

Parameters:
aRegistryPort - the fRegistry port to use
aClientSocketFactory - the RMI client socket factory for the fRegistry (if any)
aServerSocketFactory - the RMI server socket factory for the fRegistry (if any)
Returns:
the RMI fRegistry
Throws:
java.rmi.RemoteException - if the fRegistry couldn't be located or created

getRegistry

protected java.rmi.registry.Registry getRegistry(int aRegistryPort)
                                          throws java.rmi.RemoteException
Locate or create the RMI fRegistry for this exporter.

Parameters:
aRegistryPort - the fRegistry port to use
Returns:
the RMI fRegistry
Throws:
java.rmi.RemoteException - if the fRegistry couldn't be located or created

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.rmi.RemoteException
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.rmi.RemoteException

prepare

protected void prepare()
                throws java.rmi.RemoteException
Throws:
java.rmi.RemoteException

createServiceUrl

protected java.lang.String createServiceUrl(java.lang.String aServiceAddress,
                                            int aServicePort)

getServicePort

public int getServicePort()

setServicePort

public void setServicePort(int aServicePort)
Set the port that the exported RMI service will use.

Default is 0 (anonymous port).


setRegistryPort

public void setRegistryPort(int aRegistryPort)
Set the port of the fRegistry for the exported RMI service, i.e. rmi://host:PORT/name

Default is Registry.REGISTRY_PORT (1099).

See Also:
Registry.REGISTRY_PORT

getRegistryPort

public int getRegistryPort()
Returns port for RMI Registry

Returns:
registry port

isAllowsAutoDiscovering

public boolean isAllowsAutoDiscovering()
Description copied from interface: AutoDiscoveredServiceExporter
Indicates whether particular exporter is available for publishing in auto-discoverable services. In general, the final solution about including particular exporter into list of services available for autodiscovered is delegated to appropriate implementation of ExporterAcceptor, however, this methods (if implementation of Exporter is aware of it) allows to disable automatic service publishing.

Specified by:
isAllowsAutoDiscovering in interface AutoDiscoveredServiceExporter
Returns:
true if exporter could be published for auto-discovering
See Also:
ExporterAcceptor

prepareRegistry

protected void prepareRegistry()
                        throws java.rmi.RemoteException
Throws:
java.rmi.RemoteException

setRegistry

public void setRegistry(java.rmi.registry.Registry aRegistry)
Specify the RMI fRegistry to register the exported service with. Typically used in combination with RmiRegistryFactoryBean.

Alternatively, you can specify all fRegistry properties locally. This exporter will then try to locate the specified fRegistry, automatically creating a new local one if appropriate.

Default is a local fRegistry at the default port (1099), created on the fly if necessary.

See Also:
RmiRegistryFactoryBean, setRegistryHost(java.lang.String), setRegistryPort(int), setRegistryClientSocketFactory(java.rmi.server.RMIClientSocketFactory), setRegistryServerSocketFactory(java.rmi.server.RMIServerSocketFactory)

setRegistryHost

public void setRegistryHost(java.lang.String aRegistryHost)
Set the port of the fRegistry for the exported RMI service, i.e. rmi://HOST:port/name

Default is localhost.

Parameters:
aRegistryHost -

getRegistry

public java.rmi.registry.Registry getRegistry()
Returns RMI registry used for exporting remote objects

Returns:
registry

getRegistryHost

public java.lang.String getRegistryHost()
Returns host where RMI Registry is located

Returns:
host address

destroy

public void destroy()
             throws java.rmi.RemoteException
Unbind the RMI service from the fRegistry on bean factory shutdown.

Specified by:
destroy in interface org.springframework.beans.factory.DisposableBean
Throws:
java.rmi.RemoteException

exportObject

protected void exportObject()
                     throws java.rmi.RemoteException
Throws:
java.rmi.RemoteException

getObjectToExport

protected java.rmi.Remote getObjectToExport()