Question

I think I need to connect to a remote RMI object without going through the registry, but I don't know how.

My situation is this: I'm implementing a simple job distribution service which consists of one distributor and multiple workers. The distributor has a registered RMI object to which clients connect to send jobs, and workers connect to accept jobs.

Unfortunately the distributor and worker hosts are behind a firewall. To get to the distributor host I am tunneling two ports (one for the registry, one for the distributor object) via SSH, so I can get to the registry and the distributor from outside the firewall. To make that work I have to set "-Djava.rmi.server.hostname=localhost" on the distributor JVM so that the clients connect to their local, tunneled port, instead of the port on the actual distributor host, which is blocked.

This creates a problem for the workers, though, because they need to connect to the distributor directly, but because of the "localhost" redirection they behave like clients and try to connect to a port on their own host, which is not available, because I'm not tunneling on the workers (it is impractical).

Now, if I could connect to a remote object directly by giving the hostname and port, I could do away both with the registry on the distributor and the "localhost" hack, and make the workers connect properly.

How do I do that? Or is there a different solution to this problem?

Was it helpful?

Solution

I've now solved the problem by implementing my own RMISocketFactory which connects to "localhost" instead of the distributor host. By using this socket factory on the clients via RMISocketFactory.setSocketFactory I can now run the distributors and workers without any hacks. On the clients I still need the SSH tunnel, of course.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top