An Overview of RMI applications

Source: Internet
Author: User
Tags define implement interface reference return stub client
Application
An Overview of RMI applications

RMI applications are often comprised of two separate server and a client. A Typical server application creates some remote objects, makes references to them accessible, and waits for clients to Voke methods on these remote objects. A typical client application gets a remote reference to one or more remote objects in the server and then invokes on them. RMI provides the mechanism by which the server and the client communicate and information. Such an application are sometimes referred to as a distributed object application.

Distributed object applications need to

Locate remote objects:applications can use one of the two mechanisms to obtain references to remote objects. An application can register it remote objects with RMI's simple naming facility, the Rmiregistry, or the application can Pass and return remote object references as part of its normal operation.

Communicate with remote objects:details of the communication between remote objects are by RMI; To the programmer, remote communication looks like a standard Java method invocation.

Load class bytecodes for objects so are passed Around:because RMI allows a caller to pass objects to remote objects, RM I provides the necessary mechanisms for loading an object ' s code, as as a for transmitting its data.

The following illustration depicts an RMI distributed application this uses the registry to obtain a reference to a remote Object. The server calls the registry to associate (or bind) a name with a remote object. The client looks up the remote object by its name in the server's registry and then invokes a method on it. The illustration also shows that RMI system uses a existing WEB server to load Class bytecodes, from server to client And from the client to server, for objects when needed.





This lesson contains the following sections:

Advantages of Dynamic Code Loading

Remote interfaces, Objects, and Methods

Creating Distributed Applications Using RMI

Building a Generic Compute Engine

Advantages of Dynamic Code Loading

Advantages of Dynamic Code Loading

One of the the the and unique features of RMI is it ability to download the bytecodes (or simply code) of the ' s CLA SS If the class is isn't defined in the receiver ' s virtual machine. The types and the behavior of an object, previously available-in-a single virtual machine, can is transmitted to Anot Her, possibly remote, virtual machine. RMI passes objects by their true type, so behavior of those objects??????????, changed, they to are sent Al Machine. This is allows new types to is introduced into a remote virtual machine, thus extending the behavior of a application Dynami Cally. The Compute engine example in this chapter uses RMI ' s capability to introduce new behavior to a distributed.

Remote interfaces, Objects, and Methods

Like no other application, a distributed application built the using Java RMI is made up of interfaces and classes. The interfaces define methods, and the classes implement the methods defined in the interfaces and, perhaps, define Onal methods as. In a distributed application some of the implementations are assumed to reside in different virtual machines. Objects that have methods the can be called across virtual machines are remote Objects.

An object becomes remote by implementing a remote interface, which has the following characteristics.

A remote interface extends the interface java.rmi.Remote.

Each method is the interface declares java.rmi.RemoteException in it throws clause, in addition to any APPLICATION-SPECIF IC Exceptions.

RMI treats a remote object differently from a Nonremote object, the object is passed from one virtual machine to Anoth Er. Rather than making a copy of the implementation object in the receiving virtual machine, RMI passes a remote stub for a re Mote object. The stub acts as the local representative, or proxy, for the remote object and basically are, to the caller, the remote ref Erence. The caller invokes "a" on the "local stub", which is responsible to carrying out the "method" call on the remote object.

A stub for a remote object implements the same set of remote interfaces the remote object implements. This is allows a stub to is cast to any of the interfaces which is the remote object implements. However, this also means is only those methods defined in a remote interface are available to be called in the receiving Virtual machine.

Creating Distributed Applications Using RMI

When your use RMI to develop a distributed application, you follow this general steps.

Design and implement the components of your distributed application.

Compile sources and generate stubs.

Make classes network accessible.

Start the application.

Design and implement the application components

Decide on your application architecture and determine which components are local objects and which ones should emotely accessible. This step includes:

Defining the remote INTERFACES:A remote interface Specifies the methods that can is invoked remotely by A client. Clients program to remote interfaces, not to the implementation classes of those interfaces. The "design of" such interfaces is the determination an any local objects that'll be used as parameters and return Values for these methods; If any of the interfaces or classes do not yet exist, you are need to define them as.

Implementing the remote Objects:remote objects must implement one or more remote interfaces. The remote object class may include implementations of other interfaces (either local or remote) and other methods (which are available only locally). If any local classes are to is used as parameters or return values to any of the methods, they must be implemented as we ll.

Implementing the clients:clients that use remote objects can is implemented at any time after the remote interfaces are D Efined, including after the remote objects have been deployed.

Compile Sources and Generate stubs

This is a two-step process. In the ' The ' the ' Javac compiler to compile the source files, which contain the implementation of the remote I Nterfaces and implementations, the server classes, and the client classes. In the second step, use the Rmic compiler to create stubs for the remote objects. RMI uses a remote object ' s stub class as a proxy in clients so, clients can communicate with a particular remote OBJEC T.

Make Classes network Accessible

In this step you make Everything--the class files associated with the remote interfaces, stubs, and other classes that nee D to is downloaded to clients--accessible via a WEB server.

Start the application

Starting the application includes running the RMI remote object registry, the server, and the client.

The rest of this lesson walks through the steps to create a compute engine.

Building a Generic Compute Engine

This trail focuses in a simple yet powerful distributed application called a compute engine. The compute engine, a remote object in the server, takes tasks from clients, runs them, and returns any results. The tasks are run on the machine where the server is running. This sort of distributed application could allow a number of "client machines to" make use of a particularly powerful Machin E or one that has specialized hardware.

The novel aspect of the compute engine is that the tasks it runs does not need to being defined when the compute engine is writ Ten. New kinds of tasks can be created in any time and then given to the compute engine to be run. This is required of the a task is this its class implement a particular interface. Such a task can be submitted to the compute engine and run, even if the class that defines this task was written long afte R the Compute engine was written and started. The code needed to accomplish the task can is downloaded by the RMI system to the compute engine, and then the engine runs The task, using the "machine on" which the compute engine is running.

The ability to perform arbitrary tasks are enabled by the dynamic nature of the Java platform, which was extended to the net Work by RMI. RMI dynamically loads the task code into the compute engine ' s Java virtual machine and runs the task without prior GE's the class that implements the task. An application like this, which has the ability to download code dynamically, are often called a behavior-based application . Such applications usually require full agent-enabled infrastructures. With RMI such applications are part of the basic mechanisms for distributed computing on the Java platform




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.