org.springframework.remoting.rmi
Class RmiServiceExporter

java.lang.Object
  extended byorg.springframework.remoting.support.RemoteExporter
      extended byorg.springframework.remoting.rmi.RmiServiceExporter
All Implemented Interfaces:
DisposableBean, InitializingBean

public class RmiServiceExporter
extends RemoteExporter
implements InitializingBean, DisposableBean

RMI exporter that exposes the specified service as RMI object with the specified name. Such services can be accessed via plain RMI or via RmiProxyFactoryBean. Also supports exposing any non-RMI service via RMI invokers, to be accessed via RmiClientInterceptor/RmiProxyFactoryBean's automatic detection of such invokers.

With an RMI invoker, RMI communication works on the RmiInvocationHandler level, needing only one stub for any service. Service interfaces do not have to extend java.rmi.Remote or throw RemoteException on all methods, but in and out parameters have to be serializable.

The major advantage of RMI, compared to Hessian and Burlap, is serialization. Effectively, any serializable Java object can be transported without hassle. Hessian and Burlap have their own (de-)serialization mechanisms, but are HTTP-based and thus much easier to setup than RMI.

Since:
13.05.2003
Author:
Juergen Hoeller
See Also:
RmiClientInterceptor, RmiProxyFactoryBean, HessianServiceExporter, BurlapServiceExporter

Field Summary
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
RmiServiceExporter()
           
 
Method Summary
 void afterPropertiesSet()
          Register the service as RMI object.
 void destroy()
          Invoked by a BeanFactory on destruction of a singleton.
protected  java.lang.Object invoke(RemoteInvocation invocation, java.lang.Object targetObject)
          Apply the given remote invocation to the given target object.
 void setClientSocketFactory(java.rmi.server.RMIClientSocketFactory clientSocketFactory)
          Set a custom RMI client socket factory to use for exporting.
 void setRegistryPort(int registryPort)
          Set the port of the registry for the exported RMI service, i.e.
 void setServerSocketFactory(java.rmi.server.RMIServerSocketFactory serverSocketFactory)
          Set a custom RMI server socket factory to use for exporting.
 void setServiceName(java.lang.String serviceName)
          Set the name of the exported RMI service, i.e.
 void setServicePort(int servicePort)
          Set the port that the exported RMI service will use.
 
Methods inherited from class org.springframework.remoting.support.RemoteExporter
getProxyForService, getService, getServiceInterface, setService, setServiceInterface
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

RmiServiceExporter

public RmiServiceExporter()
Method Detail

setServiceName

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


setServicePort

public void setServicePort(int servicePort)
Set the port that the exported RMI service will use. Default is 0 (anonymous port).


setRegistryPort

public void setRegistryPort(int registryPort)
Set the port of the registry for the exported RMI service, i.e. rmi://localhost:PORT/name Default is Registry.REGISTRY_PORT (1099).


setClientSocketFactory

public void setClientSocketFactory(java.rmi.server.RMIClientSocketFactory clientSocketFactory)
Set a custom RMI client socket factory to use for exporting. If the given object also implement RMIServerSocketFactory, it will automatically be registered as server socket factory too.

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

setServerSocketFactory

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

See Also:
setClientSocketFactory(java.rmi.server.RMIClientSocketFactory)

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Register the service as RMI object. Creates an RMI registry on the specified port if none exists.

Specified by:
afterPropertiesSet in interface InitializingBean
Overrides:
afterPropertiesSet in class RemoteExporter
Throws:
java.lang.Exception

invoke

protected java.lang.Object invoke(RemoteInvocation invocation,
                                  java.lang.Object targetObject)
                           throws java.lang.NoSuchMethodException,
                                  java.lang.IllegalAccessException,
                                  java.lang.reflect.InvocationTargetException
Apply the given remote invocation to the given target object. The default implementation performs a plain method invocation.

Can be overridden in subclasses for custom invocation behavior, possibly for applying additional invocation parameters from a custom RemoteInvocation subclass. Will typically match a corresponding custom invoke implementation in RmiClientInterceptor/RmiProxyFactoryBean.

Parameters:
invocation - the remote invocation
targetObject - the target object to apply the invocation to
Returns:
the invocation result
Throws:
java.lang.NoSuchMethodException - if the method name could not be resolved
java.lang.IllegalAccessException - if the method could not be accessed
java.lang.reflect.InvocationTargetException - if the method invocation resulted in an exception
See Also:
RmiClientInterceptor.invoke(org.aopalliance.intercept.MethodInvocation)

destroy

public void destroy()
             throws java.rmi.RemoteException,
                    java.rmi.NotBoundException
Description copied from interface: DisposableBean
Invoked by a BeanFactory on destruction of a singleton.

Specified by:
destroy in interface DisposableBean
Throws:
java.rmi.RemoteException
java.rmi.NotBoundException


Copyright (C) 2003-2004 The Spring Framework Project.