站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 1.2.9 API 文档英文版

RmiRegistryFactoryBean (Spring Framework) - Spring Framework 1.2.9 API 文档英文版


org.springframework.remoting.rmi
Class RmiRegistryFactoryBean

java.lang.Object
  extended by org.springframework.remoting.rmi.RmiRegistryFactoryBean
All Implemented Interfaces:
DisposableBean, FactoryBean, InitializingBean

public class RmiRegistryFactoryBean
extends Object
implements FactoryBean, InitializingBean, DisposableBean

FactoryBean that locates a Registry and exposes it for bean references. Can also create a local RMI registry on the fly if none exists already.

Can be used to set up and pass around the actual Registry object to applications objects that need to work with RMI. One example for such an object that needs to work with RMI is Spring's RmiServiceExporter, which either works with a passed-in Registry reference or falls back to the registry as specified by its local properties and defaults.

Also useful to enforce creation of a local RMI registry at a given port, for example for a JMX connector. If used in conjunction with ConnectorServerFactoryBean, it is recommended to mark the connector definition (ConnectorServerFactoryBean) as "depends-on" the registry definition (RmiRegistryFactoryBean), to guarantee starting up the registry first.

Note: The implementation of this class mirrors the corresponding logic in RmiServiceExporter, and also offers the same customization hooks. RmiServiceExporter implements its own registry lookup as a convenience: It is very common to simply rely on the registry defaults.

Since:
1.2.3
Author:
Juergen Hoeller
See Also:
RmiServiceExporter.setRegistry(java.rmi.registry.Registry), ConnectorServerFactoryBean, Registry, LocateRegistry

Field Summary
protected  Log logger
           
 
Constructor Summary
RmiRegistryFactoryBean()
           
 
Method Summary
 void afterPropertiesSet()
          Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
 void destroy()
          Unexport the RMI registry on bean factory shutdown, provided that this bean actually created a registry.
 String getHost()
          Return the host of the registry for the exported RMI service.
 Object getObject()
          Return an instance (possibly shared or independent) of the object managed by this factory.
 Class getObjectType()
          Return the type of object that this FactoryBean creates, or null if not known in advance.
 int getPort()
          Return the port of the registry for the exported RMI service.
protected  Registry getRegistry(int registryPort)
          Locate or create the RMI registry.
protected  Registry getRegistry(int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory)
          Locate or create the RMI registry.
protected  Registry getRegistry(String registryHost, int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory)
          Locate or create the RMI registry.
 boolean isSingleton()
          Is the bean managed by this factory a singleton or a prototype?
 void setClientSocketFactory(RMIClientSocketFactory clientSocketFactory)
          Set a custom RMI client socket factory to use for the RMI registry.
 void setHost(String host)
          Set the host of the registry for the exported RMI service, i.e.
 void setPort(int port)
          Set the port of the registry for the exported RMI service, i.e.
 void setServerSocketFactory(RMIServerSocketFactory serverSocketFactory)
          Set a custom RMI server socket factory to use for the RMI registry.
protected  void testRegistry(Registry registry)
          Test the given RMI registry, calling some operation on it to check whether it is still active.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Log logger
Constructor Detail

RmiRegistryFactoryBean

public RmiRegistryFactoryBean()
Method Detail

setHost

public void setHost(String host)
Set the host of the registry for the exported RMI service, i.e. rmi://HOST:port/name

Default is localhost.


getHost

public String getHost()
Return the host of the registry for the exported RMI service.


setPort

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

Default is Registry.REGISTRY_PORT (1099).


getPort

public int getPort()
Return the port of the registry for the exported RMI service.


setClientSocketFactory

public void setClientSocketFactory(RMIClientSocketFactory clientSocketFactory)
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.

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

setServerSocketFactory

public void setServerSocketFactory(RMIServerSocketFactory serverSocketFactory)
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.

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

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Description copied from interface: InitializingBean
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception - in the event of misconfiguration (such as failure to set an essential property) or if initialization fails.

getRegistry

protected Registry getRegistry(String registryHost,
                               int registryPort,
                               RMIClientSocketFactory clientSocketFactory,
                               RMIServerSocketFactory serverSocketFactory)
                        throws RemoteException
Locate or create the RMI registry.

Parameters:
registryHost - the registry host to use (if this is specified, no implicit creation of a RMI registry will happen)
registryPort - the registry port to use
clientSocketFactory - the RMI client socket factory for the registry (if any)
serverSocketFactory - the RMI server socket factory for the registry (if any)
Returns:
the RMI registry
Throws:
RemoteException - if the registry couldn't be located or created

getRegistry

protected Registry getRegistry(int registryPort,
                               RMIClientSocketFactory clientSocketFactory,
                               RMIServerSocketFactory serverSocketFactory)
                        throws RemoteException
Locate or create the RMI registry.

Parameters:
registryPort - the registry port to use
clientSocketFactory - the RMI client socket factory for the registry (if any)
serverSocketFactory - the RMI server socket factory for the registry (if any)
Returns:
the RMI registry
Throws:
RemoteException - if the registry couldn't be located or created

getRegistry

protected Registry getRegistry(int registryPort)
                        throws RemoteException
Locate or create the RMI registry.

Parameters:
registryPort - the registry port to use
Returns:
the RMI registry
Throws:
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().

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

getObject

public Object getObject()
                 throws Exception
Description copied from interface: FactoryBean
Return an instance (possibly shared or independent) of the object managed by this factory. As with a BeanFactory, this allows support for both the Singleton and Prototype design pattern.

If this method returns null, the factory will consider the FactoryBean as not fully initialized and throw a corresponding FactoryBeanNotInitializedException.

Specified by:
getObject in interface FactoryBean
Returns:
an instance of the bean (should not be null; a null value will be considered as an indication of incomplete initialization)
Throws:
Exception - in case of creation errors
See Also:
FactoryBeanNotInitializedException

getObjectType

public Class getObjectType()
Description copied from interface: FactoryBean
Return the type of object that this FactoryBean creates, or null if not known in advance. This allows to check for specific types of beans without instantiating objects, for example on autowiring.

For a singleton, this should try to avoid singleton creation as far as possible; it should rather estimate the type in advance. For prototypes, returning a meaningful type here is advisable too.

This method can be called before this FactoryBean has been fully initialized. It must not rely on state created during initialization; of course, it can still use such state if available.

NOTE: Autowiring will simply ignore FactoryBeans that return null here. Therefore it is highly recommended to implement this method properly, using the current state of the FactoryBean.

Specified by:
getObjectType in interface FactoryBean
Returns:
the type of object that this FactoryBean creates, or null if not known at the time of the call
See Also:
ListableBeanFactory.getBeansOfType(java.lang.Class)

isSingleton

public boolean isSingleton()
Description copied from interface: FactoryBean
Is the bean managed by this factory a singleton or a prototype? That is, will getObject() always return the same object (a reference that can be cached)?

NOTE: If a FactoryBean indicates to hold a singleton object, the object returned from getObject() might get cached by the owning BeanFactory. Hence, do not return true unless the FactoryBean always exposes the same reference.

The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there.

Specified by:
isSingleton in interface FactoryBean
Returns:
if this bean is a singleton
See Also:
FactoryBean.getObject()

destroy

public void destroy()
             throws RemoteException
Unexport the RMI registry on bean factory shutdown, provided that this bean actually created a registry.

Specified by:
destroy in interface DisposableBean
Throws:
RemoteException


Copyright (c) 2002-2007 The Spring Framework Project.