Thanks Ken and Chris for replies.
But I thought and verified that a program in host A cannot simply bind its object (in host A) to the RMI registry in host B. This is because the RMI registry does not allow binding other than the local host. The exception is:
Exception in
thread "main" java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.AccessException: Registry.Registry.rebind disallowed; origin /192.168.0.89 is non-local host
... other exception deleted...
Actaully, there can be a complicated way to get around this:
- In host A (for registry): run the RMI registry, and run a remote object server program, say class MyRegisterImpl, with a remote method, say myRebind(), which provide a binding serice. This object is binded to real RMI registry in host A, and it acts as an agent for the real RMI registry.
- In host B (for remote server): run a remote object server, say class MyServerImpl, which lookup the MyRegisterImpl class and invokes the myRebind() method to bind itself (MyServerImpl) to the RMI registry in host A.
- In host C (for client): run a program, say class Client, which lookup the MyServerImpl object from the RMI registry in host A, and invokes the service.
I tried this in programs, and it worked.
The questions are:
1. Is there an easier way to get around the restriction that RMI registry only allow binding in local host?
2. Is there anyone really do this thing in real systems (i.e. RMI registry, remote server object, client in 3 separate machine)?
3. Does the JNDI server(?) (instead of RMI registry) have such a restriction of only allowing binding in local host?
Ken