官术网_书友最值得收藏!

RMI for distributed computing

Remote objects are similar to local objects when it comes to method invocation and returning results from methods. A remote object can be typecasted to any of the remote interfaces supported by its implementation, and the instanceof operator can be used to verify the type of remote or local object.

Although the aforementioned similarities exist between remote and local objects, they behave differently. While the clients of remote objects can only interact with remote interfaces, not with implementation classes, the clients of local objects can interact with both the interfaces and implementation classes. RMI is passed by a value, whereas a local method invocation can be passed by a reference. In this context, the mandatory remote exceptions must be defined in a local system.

The essential steps that need to be followed to develop a distributed application with RMI are as follows:

  1. Design and implement a component that should not only be involved in the distributed application, but also the local components.
  2. Ensure that the components that participate in the RMI calls are accessible across networks.
  3. Establish a network connection between applications that need to interact using the RMI.

In the preceding list, the most important step, which needs to be taken carefully, is defining the right architecture in the application with clear distinction between the components that act as Java objects available on a local JVM and ones that are remotely accessible. Let's review the implementation steps in detail:

  1. Remote interface definition: The purpose of defining a remote interface is to declare the methods that should be available for invocation by a remote client. Programming the interface instead of programming the component implementation is an essential design principle adopted by all modern Java frameworks, including Spring. In the same pattern, the definition of a remote interface takes importance in RMI design as well.
  2. Remote object implementation: Java allows a class to implement more than one interface at a time. This helps remote objects implement one or more remote interfaces. The remote object class may have to implement other local interfaces and methods that it is responsible for. Avoid adding complexity to this scenario, in terms of how the arguments or return parameter values of such component methods should be written.
  3. Remote client implementation: Client objects that interact with remote server objects can be written once the remote interfaces are carefully defined even after the remote objects are deployed.

Now let's consider a simple example and how we can implement it to stimulate interaction between multiple JVMs using the Java RMI.

主站蜘蛛池模板: 盐城市| 通河县| 青海省| 合水县| 永城市| 东宁县| 兴安县| 密云县| 浦城县| 阜阳市| 盐边县| 芷江| 连平县| 晋州市| 博罗县| 元阳县| 丰县| 会昌县| 甘孜县| 平凉市| 吐鲁番市| 龙岩市| 财经| 台东县| 孝义市| 水城县| 高陵县| 乌鲁木齐县| 天津市| 开江县| 西充县| 古丈县| 三门峡市| 宜城市| 托克托县| 荃湾区| 梁山县| 昭平县| 大名县| 柳河县| 河源市|