Why do people use RMI, or when should I use RMI? I read those tutorials about RMI on oracle's website. But it doesn't provide enough practical examples.
To my understanding, software should have its modules as "unrelated and separated" as possible. RMI somehow seems to be an example of high coupling to me. Why is this not a bad coding practice? I thought the client should only fire instructions, whereas all the actually manipulations of the object were done by the server.
RMI stands for Remote Method Invocation. It is a mechanism that allows an object residing in one system (JVM) to access/invoke an object running on another JVM. RMI is used to build distributed applications; it provides remote communication between Java programs. It is provided in the package java.
RMI provides the mechanism by which the server and the client communicate and pass information back and forth. Such an application is sometimes referred to as a distributed object application. Distributed object applications need to do the following: Locate remote objects.
A Java RMI registry is a simplified name service that allows clients to get a reference (a stub) to a remote object. In general, a registry is used (if at all) only to locate the first remote object a client needs to use.
Remote Method Invocation (RMI) is Java's implementation of object-to-object communication among Java objects to realize a distributed computing model. RMI allows us to distribute our objects on various machines, and invoke methods on the objects located on remote sites.
You really should not be using RMI for any application you build today, basically for the reasons you just laid out.
In some cases (diving into legacy or "enterprise" applications) you just have no choice.
However, if you are starting a new project, other options are:
The de-facto standard for communicating to remote services. The biggest advantage it has it that it is lightweight and easy to grasp the concept.
In theory it should require more work than RMI because you have to manually craft the available URL's, accepted verbs in each URL etc. In practice, I would say that RMI's boilerplate does not really help anybody.
Sticking with java, Jersey is a brilliant library to write your own RESTful web services.
If you want a batteries included solution for RESTful web services with java, Dropwizard by the nice guys at Yammer gives you a full server and framework ready to just plug in your business logic, and provides logging, database connectivity, serialization, request routing, and even metrics gathering out of the box.
The previous standard for communicating to remote services. Unless you have a reason to use it, I would stick to REST.
Thrift will create a client and a server stub, basically doing much of the work. The communication is in an efficient binary protocol. It's gaining popularity in the Java world as it is used by many open source projects in the "Big Data" field. Examples, Cassandra, HBase (switching to Avro). Scrooge is a twitter project to create idiomatic thrift stubs for scala.
Akka is framework that implements the Actor model for Scala and Java. Includes provisions for inter-service communication, and takes care of many of the details under the hood. I
Depending on your needs, some will be more suitable than others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With