Difference Between Rpc And Rmi Computer Science Essay Free Essay Example

In enterprise application there is possibility that resources need to be entree across multiple system to make a concern procedure. One of the Java ‘s solutions for distributed application is Remote Method Invocation ( RMI ) .

guarantee
Essay writing service:
  • Excellent quality
  • 100% Turnitin-safe
  • Affordable prices

Aim of this paper is understand how a RMI system works in existent clip scenarios and how enterprise application can implemented utilizing java RMI API ‘s. An endeavor distributed system is a set of objects that isolates the consumers of services from the suppliers of services by a chiseled interface.

In other words, clients are wholly abstracted from the execution of concern method as informations construction and feasible codification. This is how one can separate with simple client / waiter application with object based distant supplication method theoretical account.

In the distributed endeavor object theoretical account, a client sends a petition message to an object, which in bends analyzes the petition to make up one’s mind what service to execute. This concern entity service, choice could be performed by either the object or a agent.

Remote Method Invocation ( RMI ) :

RMI is one of the possible ways to entree distributed concern objects from another JVM and RMI uses object serialisation to marshal and unmarshal parametric quantities. If you want send objects across the wire, your category ( object ) demand to implements Serializable interface.

Here is the RMI architecture and how RMI ‘s plants internally.

RMI Transport Layer

Client

Waiter

skeleton

stub

Interface

Interface

Client Procedure

Server Process

Procedure

Harmonizing to sun web site “ Java Remote Method Invocation ( Java RMI ) enables the coder to make distributed Java technology-based to Java technology-based applications, in which the methods of distant Java objects can be invoked from other Java practical machines* , perchance on different hosts.

RMI uses object serialisation to marshal and unmarshal parametric quantities and does non truncate types, back uping true object-oriented polymorphism. ”

When a endeavor waiter procedure wants to export some distant method supplication based service to consumer, it does so by registering distant method supplication enabled objects with its local rmiregistry ( Registry interface ) . Every distant object is registered with a name consumer can utilize to cite it. A consumer can obtain a mention of stub to the distant object by bespeaking for the distant object by name through the Naming interface.

The statement for Naming.lookup ( ) method is name of a distant object and locates the object on the web. The object ‘s to the full qualified name can be composed with host name port and the name of the object expression like url sentence structure for the appellative resource.

Few of the nomenclature one should cognize about RMI are listed below.

rmiregistry — A feasible plan used to adhere distant object to names and that provides a bootstrap calling service which is used by waiters on the waiter machine. JVMs on client and server machines can so look up distant objects and do distant method supplications.

rmic: The rmic compiler tool generates stub, and skeleton category files for distant objects. These categories ‘ files are generated from the compiled Java linguistic communication classes that contain remote object executions ( enforced java.rmi.Remote interface ) .

skeleton: A skeleton for a distant object is a JRMP protocol server side concern object that contains a method which despatch calls to the existent remote object realisation.

stub: A placeholder object for a distant object which is responsible for deputing method on distant objects to the waiter where execution of the existent remote object resides. A consumer plan mention to a distant object, hence, is really a mention to a local stub.

Distant Interface: The Remote interface serves to acknowledge interfaces whose methods may be invoked from a non-local practical machine. Any object that is a distant object must straight or indirectly implement this interface.

Difference between RPC and RMI

Distant process call ( RPC ) is a web communicating protocol with waiter and client architecture and the thought behind RPC is to name enforced codification remotely as if we were merely naming a map. The lone difference between RMI and RPC is in instance of RPC maps are invoked through a proxy map, and in instance of RMI we invoke methods through a proxy object.

RMI is java solution to RPC, with connectivity to bing systems utilizing native methods. RMI can take a natural, direct, and to the full powered attack to supply a endeavor distributed calculating engineering that allows us to add Java functionality throughout the system. To acquire the cross-platform portability that Java provides, RPC requires a batch more operating expenses than RMI. RPC has to change over the statements between architecture so that each computing machine can utilize its native informations type.

Java-RMI is tightly coupled with the Java linguistic communication. Whereas RPC is non specific to any individual linguistic communication and one can implement RPC utilizing different linguistic communication.

Because RMI can implemented utilizing Java, its get all the advantages like object oriented, parallel computer science, design form, easy to compose and re usage, safe and secure, Write one time and run anyplace. But in the instance of RPC, to accomplish any of these advantages one has to compose execution codification.

Sample application:

To show RMI and distributed application in existent clip I have implemented a Lottery system. The Lottery system is developed as per UK Lotto system. Assuming that user before utilizing this RMI client application already purchased the lottery ticket.

Lottery client system displays the welcome message to client.

Lottery system besides displays the winning sum to the client. The Lottery system is developed as per UK Lotto system. But simplifying system I have modified certain regulations. Here how victor is chosen.

Jackpot, Match 6: ?500,000

Match 5 Numberss: ?1,500

Match 4 Numberss: ?60

Match 3 Numberss: ?10.

System asks client to come in positive whole number figure runing 1 to 49.

Once he enters all 6 Numberss Lottery system generate 6 winning non-repeating random figure between 1 to 49.

System checks the lucifer between user entered figure and server generated figure and cipher winning sum and expose the consequence

Execution:

Here is how I have implemented Lottery system

Specify a distant interface

import java.rmi.Remote ;

public interface LotteryGenerator extends Remote {

public ArrayList & lt ; Integer & gt ; getLottoryNumber ( ) throws java.rmi.RemoteException ;

}

Implement the distant interface

Below is the merely a snipping of the execution category for the distant interface. I have non listed the back uping private methods of the category.

import java.rmi.RemoteException ;

public category LotteryGeneratorImpl extends java.rmi.server.UnicastRemoteObject implements LotteryGenerator {

private ArrayList & lt ; Integer & gt ; Numberss ; // Integer array for keeping repetition

private ArrayList & lt ; Integer & gt ; batch ;

private java.util.Random gen ;

public ArrayList & lt ; Integer & gt ; getLottoryNumber ( ) {

lot.clear ( ) ;

for ( int i=0 ; i & lt ; 6 ; i++ ) {

lot.add ( getNextInt ( ) ) ;

}

System.out.println ( “ Generated Lottery figure: ” +lot ) ;

return batch ;

}

}

Develop the waiter

Create an case of distant object and register the distant object with RMI register. Here is the codification snipping for the LotterServer.java

import java.rmi.Naming ;

import java.rmi.Remote ;

public category LotteryServer {

public LotteryServer ( ) {

seek {

LotteryGenerator c = new LotteryGeneratorImpl ( ) ;

Naming.rebind ( “ rmi: //127.0.0.1:1099/LotteryGenerator ” , ( Remote ) degree Celsius ) ;

} gimmick ( Exception e ) {

System.out.println ( “ Trouble: “ + vitamin E ) ;

e.printStackTrace ( ) ;

}

}

public inactive nothingness chief ( Stringing args [ ] ) {

new LotteryServer ( ) ;

System.out.println ( “ *****Server started****** ” ) ;

}

}

If RMI application running on default port 1099 so the rebind statement will be Naming.rebind ( “ rmi: //127.0.0.1:1099/LotteryGenerator ” , ( Remote ) degree Celsius ) ; and if you run the RMI register on a non default port figure, for illustration on port 5100, so adhering statement becomes:

Naming.rebind ( “ rmi: //127.0.0.1:5100/LotteryGenerator ” , ( Remote ) degree Celsius ) ;

Develop a Client

Following measure is implementing the RMI Lottery client and the client remotely invokes the method getLottoryNumber specified in the LotterGenerator distant interface. To make so nevertheless, the consumer plan must foremost obtain an object mention to the LotteryGeneratorImpl remote object from the RMI register. Once an object mention is obtained, the getLottoryNumber method is invoked.

import java.rmi.Naming ;

import java.util.ArrayList ;

import java.util.Scanner ;

public category LotteryClient {

public inactive nothingness chief ( Stringing [ ] args ) {

displayWelcomeMessage ( ) ;

Scanner scanner = new java.util.Scanner ( System.in ) ;

System.out.println ( “ Please Enter 6 whole number Numberss runing 1 to 49 ) ” ) ;

ArrayList & lt ; Integer & gt ; clientArray=new ArrayList & lt ; Integer & gt ; ( ) ;

for ( int ii=0 ; ii & lt ; 6 ; ii++ ) {

int val = scanner.nextInt ( ) ;

clientArray.add ( val ) ;

}

System.out.println ( “ You have entered: “ +clientArray ) ;

seek {

LotteryGenerator degree Celsius = ( LotteryGenerator ) Naming.lookup ( “ rmi: //localhost/LotteryGenerator ” ) ;

ArrayList servList=c.getLottoryNumber ( ) ;

System.out.println ( “ Lottery Wining Numberss: ” +servList ) ;

int count=checkWin ( clientArray, servList ) ;

dispalyResult ( count ) ;

System.out.println ( “ Thank you! ! “ ) ;

} gimmick ( java.net.MalformedURLException murle ) {

System.out.println ( ) ;

System.out.println ( “ MalformedURLException ” ) ;

System.out.println ( murle ) ;

} gimmick ( java.rmi.RemoteException rhenium ) {

System.out.println ( ) ;

System.out.println ( “ RemoteException ” ) ;

System.out.println ( rhenium ) ;

} gimmick ( java.rmi.NotBoundException nbe ) {

System.out.println ( ) ;

System.out.println ( “ NotBoundException ” ) ;

System.out.println ( north by east ) ;

}

}

private inactive nothingness dispalyResult ( int count ) {

//implemenattion for show codification

}

private inactive nothingness displayWelcomeMessage ( ) {

//display the welcome message and Lottery winning sum.

}

public inactive int checkWin ( ArrayList clientArray, ArrayList serverArray ) {

int count=0 ;

for ( int ii=0 ; ii & lt ; 6 ; ii++ ) {

int clientVal= ( Integer ) clientArray.get ( two ) ;

for ( int k=0 ; k & lt ; 6 ; k++ ) {

int serVal= ( Integer ) serverArray.get ( K ) ;

if ( clientVal==serVal ) {

count++ ; interruption ;

}

}

}

return count ;

}

}

Runing RMI application:

Here is the stairss how one can put to death Lottery application.

Compile all the Java categories.

Using rmic bid, create stubs and skeleton for the enforced remote object.

rmic LotteryGeneratorImpl

Get down the RMI register utilizing rmiregistry bid

Execute LotteryServer application

Execute LotteryClient application

Decision:

Because it easy implementation nature RMI has definite advantages over other distributed application methodological analysis like RPC, Corba etc. Because it is implemented utilizing Java it ‘s acquire all the advantages like object oriented, parallel computer science ( Multi-threading ) , design form, easy to compose and re usage, safe and secure, Write one time and run anyplace. Besides one can incorporate RMI based application any other application because of its platform independent ability.

Calculate your order
275 words
Total price: $0.00

Top-quality papers guaranteed

54

100% original papers

We sell only unique pieces of writing completed according to your demands.

54

Confidential service

We use security encryption to keep your personal data protected.

54

Money-back guarantee

We can give your money back if something goes wrong with your order.

Enjoy the free features we offer to everyone

  1. Title page

    Get a free title page formatted according to the specifics of your particular style.

  2. Custom formatting

    Request us to use APA, MLA, Harvard, Chicago, or any other style for your essay.

  3. Bibliography page

    Don’t pay extra for a list of references that perfectly fits your academic needs.

  4. 24/7 support assistance

    Ask us a question anytime you need to—we don’t charge extra for supporting you!

Calculate how much your essay costs

Type of paper
Academic level
Deadline
550 words

How to place an order

  • Choose the number of pages, your academic level, and deadline
  • Push the orange button
  • Give instructions for your paper
  • Pay with PayPal or a credit card
  • Track the progress of your order
  • Approve and enjoy your custom paper

Ask experts to write you a cheap essay of excellent quality

Place an order
Live Chat+14106602809EmailWhatsApp

Online Class Help Services Available from $100 to $150 Per Week Chat us for a quote