类 RmiServiceExporter
- 所有已实现的接口:
Aware
,BeanClassLoaderAware
,DisposableBean
,InitializingBean
public class RmiServiceExporter extends RmiBasedExporter 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 viaRmiProxyFactoryBean
. Also supports exposing any non-RMI service via RMI invokers, to be accessed viaRmiClientInterceptor
/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 extendjava.rmi.Remote
or throwjava.rmi.RemoteException
on all methods, but in and out parameters have to be serializable.The major advantage of RMI, compared to Hessian, is serialization. Effectively, any serializable Java object can be transported without hassle. Hessian has its own (de-)serialization mechanisms, but is HTTP-based and thus much easier to setup than RMI. Alternatively, consider Spring's HTTP invoker to combine Java serialization with HTTP-based transport.
Note: RMI makes a best-effort attempt to obtain the fully qualified host name. If one cannot be determined, it will fall back and use the IP address. Depending on your network configuration, in some cases it will resolve the IP to the loopback address. To ensure that RMI will use the host name bound to the correct network interface, you should pass the
java.rmi.server.hostname
property to the JVM that will export the registry and/or the service using the "-D" JVM argument. For example:-Djava.rmi.server.hostname=myserver.com
- 从以下版本开始:
- 13.05.2003
- 作者:
- Juergen Hoeller
- 另请参阅:
RmiClientInterceptor
,RmiProxyFactoryBean
,Remote
,RemoteException
,HessianServiceExporter
,HttpInvokerServiceExporter
字段概要
从类继承的字段 org.springframework.remoting.support.RemotingSupport
logger
构造器概要
构造器 构造器 说明 RmiServiceExporter()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.void
destroy()
Unbind the RMI service from the registry on bean factory shutdown.protected Registry
getRegistry(int registryPort)
Locate or create the RMI registry for this exporter.protected Registry
getRegistry(int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory)
Locate or create the RMI registry for this exporter.protected Registry
getRegistry(String registryHost, int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory)
Locate or create the RMI registry for this exporter.void
prepare()
Initialize this service exporter, registering the service as RMI object.void
setAlwaysCreateRegistry(boolean alwaysCreateRegistry)
Set whether to always create the registry in-process, not attempting to locate an existing registry at the specified port.void
setClientSocketFactory(RMIClientSocketFactory clientSocketFactory)
Set a custom RMI client socket factory to use for exporting the service.void
setRegistry(Registry registry)
Specify the RMI registry to register the exported service with.void
setRegistryClientSocketFactory(RMIClientSocketFactory registryClientSocketFactory)
Set a custom RMI client socket factory to use for the RMI registry.void
setRegistryHost(String registryHost)
Set the host of the registry for the exported RMI service, i.e.void
setRegistryPort(int registryPort)
Set the port of the registry for the exported RMI service, i.e.void
setRegistryServerSocketFactory(RMIServerSocketFactory registryServerSocketFactory)
Set a custom RMI server socket factory to use for the RMI registry.void
setReplaceExistingBinding(boolean replaceExistingBinding)
Set whether to replace an existing binding in the RMI registry, that is, whether to simply override an existing binding with the specified service in case of a naming conflict in the registry.void
setServerSocketFactory(RMIServerSocketFactory serverSocketFactory)
Set a custom RMI server socket factory to use for exporting the service.void
setServiceName(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.protected void
testRegistry(Registry registry)
Test the given RMI registry, calling some operation on it to check whether it is still active.从类继承的方法 org.springframework.remoting.rmi.RmiBasedExporter
getObjectToExport, invoke
从类继承的方法 org.springframework.remoting.support.RemoteInvocationBasedExporter
getRemoteInvocationExecutor, invokeAndCreateResult, setRemoteInvocationExecutor
从类继承的方法 org.springframework.remoting.support.RemoteExporter
checkService, checkServiceInterface, getExporterName, getProxyForService, getService, getServiceInterface, setInterceptors, setRegisterTraceInterceptor, setService, setServiceInterface
从类继承的方法 org.springframework.remoting.support.RemotingSupport
getBeanClassLoader, overrideThreadContextClassLoader, resetThreadContextClassLoader, setBeanClassLoader
构造器详细资料
RmiServiceExporter
public RmiServiceExporter()
方法详细资料
setServiceName
public void setServiceName(String serviceName)
Set the name of the exported RMI service, i.e.rmi://host:port/NAME
setServicePort
public void setServicePort(int servicePort)
Set the port that the exported RMI service will use.Default is 0 (anonymous port).
setClientSocketFactory
public void setClientSocketFactory(RMIClientSocketFactory clientSocketFactory)
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.
setServerSocketFactory
public void setServerSocketFactory(RMIServerSocketFactory serverSocketFactory)
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.
setRegistry
public void setRegistry(Registry registry)
Specify the RMI registry to register the exported service with. Typically used in combination with RmiRegistryFactoryBean.Alternatively, you can specify all registry properties locally. This exporter will then try to locate the specified registry, automatically creating a new local one if appropriate.
Default is a local registry at the default port (1099), created on the fly if necessary.
setRegistryHost
public void setRegistryHost(String registryHost)
Set the host of the registry for the exported RMI service, i.e.rmi://HOST:port/name
Default is localhost.
setRegistryPort
public void setRegistryPort(int registryPort)
Set the port of the registry for the exported RMI service, i.e.rmi://host:PORT/name
Default is
Registry.REGISTRY_PORT
(1099).
setRegistryClientSocketFactory
public void setRegistryClientSocketFactory(RMIClientSocketFactory registryClientSocketFactory)
Set a custom RMI client socket factory to use for the RMI registry.If the given object also implements
java.rmi.server.RMIServerSocketFactory
, it will automatically be registered as server socket factory too.
setRegistryServerSocketFactory
public void setRegistryServerSocketFactory(RMIServerSocketFactory registryServerSocketFactory)
Set a custom RMI server socket factory to use for the RMI registry.Only needs to be specified when the client socket factory does not implement
java.rmi.server.RMIServerSocketFactory
already.
setAlwaysCreateRegistry
public void setAlwaysCreateRegistry(boolean alwaysCreateRegistry)
Set whether to always create the registry in-process, not attempting to locate an existing registry at the specified port.Default is "false". Switch this flag to "true" in order to avoid the overhead of locating an existing registry when you always intend to create a new registry in any case.
setReplaceExistingBinding
public void setReplaceExistingBinding(boolean replaceExistingBinding)
Set whether to replace an existing binding in the RMI registry, that is, whether to simply override an existing binding with the specified service in case of a naming conflict in the registry.Default is "true", assuming that an existing binding for this exporter's service name is an accidental leftover from a previous execution. Switch this to "false" to make the exporter fail in such a scenario, indicating that there was already an RMI object bound.
afterPropertiesSet
public void afterPropertiesSet() throws RemoteException
从接口复制的说明:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- 指定者:
afterPropertiesSet
在接口中InitializingBean
- 抛出:
RemoteException
prepare
public void prepare() throws RemoteException
Initialize this service exporter, registering the service as RMI object.Creates an RMI registry on the specified port if none exists.
- 抛出:
RemoteException
- if service registration failed
getRegistry
protected Registry getRegistry(String registryHost, int registryPort, @Nullable RMIClientSocketFactory clientSocketFactory, @Nullable RMIServerSocketFactory serverSocketFactory) throws RemoteException
Locate or create the RMI registry for this exporter.- 参数:
registryHost
- the registry host to use (if this is specified, no implicit creation of a RMI registry will happen)registryPort
- the registry port to useclientSocketFactory
- the RMI client socket factory for the registry (if any)serverSocketFactory
- the RMI server socket factory for the registry (if any)- 返回:
- the RMI registry
- 抛出:
RemoteException
- if the registry couldn't be located or created
getRegistry
protected Registry getRegistry(int registryPort, @Nullable RMIClientSocketFactory clientSocketFactory, @Nullable RMIServerSocketFactory serverSocketFactory) throws RemoteException
Locate or create the RMI registry for this exporter.- 参数:
registryPort
- the registry port to useclientSocketFactory
- the RMI client socket factory for the registry (if any)serverSocketFactory
- the RMI server socket factory for the registry (if any)- 返回:
- the RMI registry
- 抛出:
RemoteException
- if the registry couldn't be located or created
getRegistry
protected Registry getRegistry(int registryPort) throws RemoteException
Locate or create the RMI registry for this exporter.- 参数:
registryPort
- the registry port to use- 返回:
- the RMI registry
- 抛出:
RemoteException
- if the registry couldn't be located or created
testRegistry
protected void testRegistry(Registry registry) throws RemoteException
Test the given RMI registry, calling some operation on it to check whether it is still active.Default implementation calls
Registry.list()
.- 参数:
registry
- the RMI registry to test- 抛出:
RemoteException
- if thrown by registry methods- 另请参阅:
Registry.list()
destroy
public void destroy() throws RemoteException
Unbind the RMI service from the registry on bean factory shutdown.- 指定者:
destroy
在接口中DisposableBean
- 抛出:
RemoteException