Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Benefits and disadvantages of using java rmi

Tags:

java

rmi

What are the advantages and disadvantages of RMI?

like image 846
samuel Avatar asked Feb 26 '10 06:02

samuel


People also ask

What are the advantages and disadvantages of RMI?

Explain the advantages and disadvantages of RMI. - It is possible to create zero-install client for the users. - At the time of changing the database, only the server objects are to be recompiled but not the server interface and the client remain the same. Disadvantages of RMI: - Less efficient than Socket objects.

What is RMI explain advantages of using RMI?

Java Remote Method Invocation (RMI) allows you to write distributed objects using Java. This paper describes the benefits of RMI, and how you can connect it to existing and legacy systems as well as to components written in Java. RMI provides a simple and direct model for distributed computation with Java objects.

What is the purpose of Java RMI?

The Java Remote Method Invocation (RMI) system allows an object running in one Java virtual machine to invoke methods on an object running in another Java virtual machine. RMI provides for remote communication between programs written in the Java programming language.

What is Java RMI vulnerability?

A security vulnerability in the Remote Method Invocation component of the Java Runtime Environment allows unauthenticated network attacks which can result in unauthorized operating system takeover including arbitrary code execution.


2 Answers

The advantages and disadvantages are similar to those of any RPC-like (Remote Procedure Call) System. There is a superficial appearance of simplicity, because it objects which are in fact remote can be treated as though they were local.

This would seem like a great benefit to simplicity of programming, but there are hidden costs. Distributed systems have issues of latency and potential for partial failure which the programmer has to be aware of. An invocation of a remote method is subject to potential failure from security, latency problems, network failure, etc. Papering over these sorts of problems can be a disaster for reliability.

like image 190
Rob Lachlan Avatar answered Oct 13 '22 05:10

Rob Lachlan


From my experience:

Pros:

  • Easy to start
  • Dynamic class loading is very powerful
  • If you implement something like below you can not change server side for a long time and develop client (one exception on rmi server has to get these classes in classpath - so either server them over net or include them and rebuild server)

You can implement two interfaces like that:

Common task interface:

public interface Task<T extends Serializable> extends Serializable {

    T execute();

}

Rmi interface:

public interface RmiTask extends Remote {

    <T extends Serializable> T executeTask(Task<T> task) throws RemoteException;

}

RmiTask implementation on server side:

public class RmiTaskExecutor implements RmiTask {

    public <T extends Serializable> T executeTask(Task<T> task) {
        return task.execute();
    }

}

Example client Task implementation:

public class IsFileTask implements Task<Boolean> {

    final String path;

    public IsFileTask(String path) {
        this.path = path;
    }

    public Boolean execute() {
        return new File(path).isFile();
    }

}

Cons:

  • Could be insecure, when using Dynamic class loading (client serves implementation of passed types) - for example you know that rmi server calls method() on PassedObject, but marvellous client could override this method and execute whatever he wants there...
  • hard to implement callback which would work over Internet (it needs to establish new connection from server to client - it can be challenging to pass it through NAT/routers/ firewalls)
  • when you suddenly broke the connection during execution of remote method it happens that this method would not return (I recommend wrapping rmi calls into Callables and run them with defined timeouts).
like image 30
rafalmag Avatar answered Oct 13 '22 03:10

rafalmag