Kunal
Kunal

Reputation: 1024

JAVA asynchronous RMI

I need to have Remote Method invocation (RMI) functionality between two different JAVA programs. Both are supposed to perform some backend functionality on given file(File Name as parameter)sequentially. As the number of files to be processed can be too large, I require that the Remote Call to be done asynchronously. Initially I used Java RMI for this as it fits perfectly except that call is done synchronously. These are simple java programs and I don’t want to deploy them on any Application server as that would be too much overhead. Also multiple files need to be executed simultaneously so program is developed in thread-safe mode. Please suggest ideal implementation for that. Any custom developed API if available free would be really helpful.

Upvotes: 2

Views: 7102

Answers (7)

Oscar Besga Panel
Oscar Besga Panel

Reputation: 25

I'm with the same issue. Looking for reponses, I've found

  • With the base libraries, it's not possible
  • You can do polling (make calls every n time to know if something has changed) to emulate async.
  • Use JMS or other messaging system
  • Found this github project, but not checked myself: https://github.com/barakb/asyncrmi
  • Use a RMI server in every client
  • Use gRPC / Java, which by design accepts futures and streams. It involves use IDL and generate more complex code, but it works neat.

I have choosen the last option

Upvotes: 0

Nikita Koksharov
Nikita Koksharov

Reputation: 10803

Here is another new player in RMI area which supports asynchronous execution. The Redisson framework. More documentation about asynchronous execution is here.

Upvotes: 0

Barak
Barak

Reputation: 43

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 that I know of such async RMI

Here is a good explanation with sequence diagram about how it is actually implemented.

Upvotes: 2

Darwin
Darwin

Reputation: 4786

Just spin up a thread and call the method from with the thread. Now you have async RMI ;-)

Upvotes: 0

user207421
user207421

Reputation: 310980

I need to have Remote Method invocation (RMI) functionality between two different JAVA programs ... I require that the Remote Call to be done asynchronously.

Those two requirements are mutually contradictory. RMI means Remote Method Invocation, which implies call-and-return method call semantics. If it isn't call-and-return, it isn't method invocation, so it isn't RMI either.

You should investigate technologies that have listeners, such as JMS.

Upvotes: 2

Peter Lawrey
Peter Lawrey

Reputation: 533680

The simplest solution is to have your RMI call start an asynchronous task. If you want to improve efficiency you could send batches of files to process. Note: unless you are careful, you disk subsystem could be your bottleneck and using multiple threads can be slower instead of faster.

Upvotes: 2

Random42
Random42

Reputation: 9159

You should JMS (Java Messaging Service) if you are sure both your applications are in Java (and are going to be). The communication being asynchronously there is also going to be a 3rd party broker - a message queue (ActiveMQ or one directly embedded in an application server like Glassfish or others).

By using this, you send the MQ and it sends the messages to the other application.

If you want more flexibility and maybe some of the applications are (or are going to be) written in another language you should probably use AMQP instead of JMS.

Upvotes: 0

Related Questions