java.rmi.Remote - get IP on which object is exported

I use

UnicastRemoteObject.exportObject(this);

to export an object that implements java.rmi.Remote. Then I send this object (wrapped in a MarshalledObject) via an ObjectOutputStream to an application in another JVM (i.e. give it a callback to call my application's methods).

In case there are several network adapters there may be need to setup java.rmi.server.hostname property to ensure that the socket given for backward connection (the socket on which the object is exported) to the remote application is bound to an IP that is reachable from the remote machine.

Is there a way to determine at time of export on what IP (and possibly port) is the object exported? In the debugger I see that the Remote (the stub) returned by the call to exportObject contains a reference to a TCPEndpoint instance that contains this information, but is there a way to reach this information without reflection?

I want to log this information on the side that exports the object so that I can analyze possible reasons for callback functionality failure.

Thanks

Mike

[1136 byte] By [bellyrippera] at [2007-11-26 15:14:50]
# 1

> (wrapped in a MarshalledObject)

Why the MarshalledObject?

You will need to make sure it is the stub that you marshall, i.e. the value returned by exportObject.

> Is there a way to determine at time of export on what

> IP (and possibly port) is the object exported?

If you use an RMIServerSocketFactory you can control the bind-address yourself by constructing your own ServerSocket with the appropriate bind-address, and you also get to see the port number. Make sure the bind-address agrees in a reasonable way with java.rmi.server.hostname, whatever that means in your topology, i.e. that someone using the java.rmi.server.hostname will connect to your bind-address.

> The Remote (the stub) returned by

> the call to exportObject contains a reference to a

> TCPEndpoint instance that contains this information,

> but is there a way to reach this information without

> reflection?

No.

> I want to log this information on the side that

> exports the object so that I can analyze possible

> reasons for callback functionality failure.

Just call toString() on the stub.

ejpa at 2007-7-8 9:06:22 > top of Java-index,Java Essentials,Java Programming...
# 2
>Just call toString() on the stub.That output suits perfectly my needs. Many thanksMike
bellyrippera at 2007-7-8 9:06:22 > top of Java-index,Java Essentials,Java Programming...