Search code examples
javarmiproxy-classesremoteobject

Java RMI: Pass remote object reference back to host


My client uses RMI to connect to a service on a different host.

This client calls a method on the service that returns a remote object reference. Can the client pass the associated stub to a different method of the service in a way that is transparent to the service?

In other words, can the client use the stub to call a method of the service, so that the service sees the original object and not the stub?

High level example: (client code)

// Connecting to the service.
Service service = (Service) Naming.lookup(servicename);

// Retrieving intermediate result. (Passed as remote object reference.) 
IntermediateResult res = service.getIntermediateResult();

// Passing stub result back to service...
service.confirmResult(res);

I would expect RMI to resolve the reference/proxy so that Service sees the object it originally sent, but this doesn't appear to be the case. Instead, the above code just sends the proxy to the service:

Proxy[IntermediateResult,RemoteObjectInvocationHandler[UnicastRef [liveRef: [endpoint:[10.43.89.166:58799](remote),objID:[-762db624:148f519cb69:-7fec, -4488749599514745712]]]]]


Solution

  • No. The remote object gets serialized as its stub, but the reverse doesn't happen. You would need to maintain your own Map for this purpose.