Marcos Roriz Junior
Marcos Roriz Junior

Reputation: 4106

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"
}

Upvotes: 0

Views: 316

Answers (3)

erickson
erickson

Reputation: 269667

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.

Upvotes: 1

sgargan
sgargan

Reputation: 12628

An RMI call forwarding to a JMSService? Sounds like Apache Camel is exactly what you need; its a framework for doing just this sort of Enterprise integration.

The components page has examples of how to set up RMI and JMS (and myriad other) endpoints. You'll then write a route using its powerful DSL to forward messages from one endpoint to the other.

Upvotes: 0

Carl Smotricz
Carl Smotricz

Reputation: 67760

Well, since A and B are already connected via a RMI locator, why not just have A register a service as well, and then let B call that service?

Upvotes: 0

Related Questions