Search code examples
javarmi

How to store rmi connections in java?


I'm with a problem here. I have a client A code that calls a B via RMI. After that I'm sending a queue request via JMS to the real implementation C. However, I don't know the "address" of A. Is there a way to store the connection data somehow so that I can return the data to A later?

Basically the thing is that B can have tons of requests and need to synchronize this to the requestor. How to do that?

Example:

A:

...
    rmiB.HelloWorld("Sys");
...

B:

String HelloWorld(String s) {
    ...
   sendToJMS(s);
    ...
   return????
}

C:

String HelloWorldOnJMS(String aff) {
    return "aff+2"
}

Solution

  • If you can't modify A, then B needs to be responsible for blocking until C produces a result, and returning that result synchronous as the result of the RMI method.

    So it seems the problem is more about how C can reply to B (or "Bs", since it sounds like you have a cluster of these) than how to respond to A.

    Normally, synchronous calls like this are simulated via JMS by creating a temporary queue, and specifying that as the reply address on the message. So, B would create a temporary queue, then block on that queue until it received the result back from C, then return the content of the reply to A.

    I might not understand your circumstances fully, but it seems like any other approach would require modifications to the AB interface.