|
![]() |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.rmi.server.RemoteObject
java.rmi.server.RemoteServer
java.rmi.server.UnicastRemoteObject
RegistryDelegate
public class RegistryDelegate
This class implements the registry delegate concept.
In order to enforce some level of security, the standard RMI
registry implementation (e.g. rmiregistry.exe
)
only allows processes on the same host to register objects
in the registry (think of a bank running a registry on one of its servers,
and doesn't want anybody modifying it).
So, by design, if a process tries to bind(String, Remote)
an object to a remote registry, an exception will be thrown.
However, the design of a distributed system may require remote clients to register themselves in a central registry. If such system is deployed in a controlled and trusted environment (e.g., a firewalled intranet with tight access control), the security risk may be acceptable.
The simplest technical solution to the remote registration problem
is to have a registry delegate. A registry delegate is an object
that serves as a proxy for the real registry. The delegate itself
usually appears in the registry under a well known name. It implements the Registry
interface and simply delegates all method calls to the appropriate methods of the
real registry. The delegate is allowed to perform bind and unbind operations because
it is running on the same host as the registry.
The common scenario for starting a registry and creating the delegate is starting a class with
the following main(String[])
method:
public static void main(String[] args) throws AccessException, RemoteException, AlreadyBoundException { if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } Registry registry = LocateRegistry.createRegistry(REGISTRY_PORT); registry.bind(DELEGATE_NAME, new RegistryDelegate()); do { try { Thread.sleep(Long.MAX_VALUE); } catch (InterruptedException e) { ; // do nothing } catch (Throwable e) { e.printStackTrace(); System.exit(1); } } while(true); }The common usage scenario looks something like:
Registry remoteRegistry = LocateRegistry.getRegistry("remotehost.mycompany.com"); Registry delegate = (Registry) remoteRegistry.lookup(DELEGATE_NAME); delegate.bind("someName", new SomeRemoteObject());The
getRegistryDelegate(String)
method is a helper method that fetches the
registry delegate for you.
The main(String[])
method of this class will create
a local registry on the default port, create a registry delegate and bind it
under the well known name that you chose in the wizard (DELEGATE_NAME
).
Field Summary | |
---|---|
static String |
DELEGATE_NAME
The name under which the delegate appears in the registry |
private Registry |
localRegistry
The local resistry. |
Fields inherited from class java.rmi.server.RemoteObject |
---|
ref |
Fields inherited from interface java.rmi.registry.Registry |
---|
REGISTRY_PORT |
Constructor Summary | |
---|---|
RegistryDelegate()
Create a delegate for a local registry that is bound to the default local port (1099). |
|
RegistryDelegate(int port)
Create a delegate for a local registry that is bound to a user specified port. |
|
RegistryDelegate(Registry reg)
Create a delegate for a user provided registry instance. |
Method Summary | |
---|---|
void |
bind(String name,
Remote obj)
|
static Registry |
getRegistryDelegate(String remoteHost)
This method retrieves the registry delegate from a registry that is running on a remote host. |
static Registry |
getRegistryDelegate(String remoteHost,
int remotePort)
This method retrieves the registry delegate from a registry that is running on a remote host. |
String[] |
list()
|
Remote |
lookup(String name)
|
static void |
main(String[] args)
A simple way to run a registry and bind a registry delegate. |
void |
rebind(String name,
Remote obj)
|
void |
unbind(String name)
|
Methods inherited from class java.rmi.server.UnicastRemoteObject |
---|
clone, exportObject, exportObject, exportObject, unexportObject |
Methods inherited from class java.rmi.server.RemoteServer |
---|
getClientHost, getLog, setLog |
Methods inherited from class java.rmi.server.RemoteObject |
---|
equals, getRef, hashCode, toString, toStub |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private Registry localRegistry
public static final String DELEGATE_NAME
Constructor Detail |
---|
public RegistryDelegate() throws RemoteException
RemoteException
- if any error occurs.public RegistryDelegate(int port) throws RemoteException
port
- the local registry port.
RemoteException
- if any error occurs.public RegistryDelegate(Registry reg) throws RemoteException
reg
- the registry for which a delegate is to be created.
RemoteException
- if any error occurrs.Method Detail |
---|
public void bind(String name, Remote obj) throws RemoteException, AlreadyBoundException, AccessException
bind
in interface Registry
RemoteException
AlreadyBoundException
AccessException
public String[] list() throws RemoteException, AccessException
list
in interface Registry
RemoteException
AccessException
public Remote lookup(String name) throws RemoteException, NotBoundException, AccessException
lookup
in interface Registry
RemoteException
NotBoundException
AccessException
public void rebind(String name, Remote obj) throws RemoteException, AccessException
rebind
in interface Registry
RemoteException
AccessException
public void unbind(String name) throws RemoteException, NotBoundException, AccessException
unbind
in interface Registry
RemoteException
NotBoundException
AccessException
public static Registry getRegistryDelegate(String remoteHost, int remotePort) throws RemoteException, NotBoundException
remoteHost
- name of the remote host.remotePort
- port on which the registry accepts requests.
RemoteException
- if we could not connect to the registry.
NotBoundException
- if the delegate does not appear in the registry.public static Registry getRegistryDelegate(String remoteHost) throws RemoteException, NotBoundException
remoteHost
- name of the remote host.
RemoteException
- if we could not connect to the registry.
NotBoundException
- if the delegate does not appear in the registry.public static void main(String[] args) throws AccessException, RemoteException, AlreadyBoundException
AccessException
RemoteException
AlreadyBoundException
|
![]() |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |