开发者

Spring Async RMI Call

Is it possible to invoke Java RMI asynchronously? I'd like my RMI call to return immediately and for the server to invoke a callback once a task is completed.

I'd cur开发者_如何学编程rently using RMI support from Spring framework, and i couldn't find any documentation describing it in spring, I suspect I'll need to implement it myself. Please provide examples if possible.

Thanks in advance!


RMI is synchronous and doesn't support callbacks as far as I know.

JMS is the Java EE way to make asynch calls. If you're using Spring, it would be a message-driven POJO.

Another place to look, since you're already using Spring, is either Spring Batch or Spring Integration. I'd try either of those before I wrote it myself.

But if that doesn't do it for you, your suspicion is correct - you'll have to implement it yourself.


I didn't look Spring batch and Spring Integration but without changing the RMI protocol the only way to implement asynchronous call is to span a new thread that wait for the result from the server and this is not a true asynchronous call.

The way to have true asynchronous call is to:

  1. Implement RMI with NIO.
  2. When the proxy is invoked put the request on the NIO selector and return immediately a result future to the caller.
  3. Each request has to have a unique request id and when a response with that id arrive from the server the right future should be resolved.

There is only one implementation of such async RMI (I am not sure it is production ready yet).

Here is a good explanation with sequence diagram

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜