Wednesday, June 5, 2019
Differences Between RPC And RMI
Differences Between RPC And RMIIn enterprise application there is possibility that resources need to be access across multiple system to do a business process. One of the javas solutions for distributed application is conflicting Method Invocation (RMI).Objective of this paper is understand how a RMI system works in real date scenarios and how enterprise application give the bounce implemented using java RMI APIs. An enterprise distributed system is a set of objects that isolates the consumers of services from the providers of services by a percipient interface. In other words, clients are completely abstracted from the implementation of business manner as data structure and executable code. This is how one can learn with simple client / horde application with object based out-of-door invocation method model.In the distributed enterprise object model, a client sends a request message to an object, which in turns analyzes the request to decide what service to perform. This b usiness entity service, selection could be performed by either the object or a broker.Remote Method Invocation (RMI)RMI is one of the possible ways to access distributed business objects from a nonher JVM and RMI uses object serialization to marshal and unmarshal parameters. If you want send objects across the wire, your family unit (object) need to implements Serializable interface.Here is the RMI architecture and how RMI s works internally.RMI Trans sort LayerClientServerskeletonstubInterfaceInterfaceClient physical processServer ProcessProcessAccording to sun web site Java Remote Method Invocation (Java RMI) enables the programmer to create distributed Java technology-based to Java technology-based applications, in which the methods of removed Java objects can be invoked from other Java realistic machines*, possibly on different hosts. RMI uses object serialization to marshal and unmarshal parameters and does not truncate types, supporting true object-oriented polymorphism.W hen a enterprise server process wants to export some remote method invocation based service to consumer, it does so by registering remote method invocation enabled objects with its local rmiregistry (Registry interface). Every remote object is registered with a name consumer can use to reference it. A consumer can obtain a reference of stub to the remote object by requesting for the remote object by name with the Naming interface.The argument for Naming.lookup() method is name of a remote object and locates the object on the network. The objects fully qualified name can be composed with host name port and the name of the object look like url syntax for the naming resource.Few of the terminology one should know about RMI are listed below.rmiregistry A executable program used to bind remote object to names and that provides a bootstrap naming service which is used by servers on the server machine. JVMs on client and server machines can then look up remote objects and make remote met hod invocations.rmic The rmic compiler tool generates stub, and skeleton class files for remote objects. These classes files are generated from the compiled Java language classes that contain remote object implementations (implemented java.rmi.Remote interface).skeleton A skeleton for a remote object is a JRMP protocol server side business object that contains a method which dispatch identifys to the actual remote object realization.stub A proxy object for a remote object which is responsible for delegating method on remote objects to the server where implementation of the actual remote object resides. A consumer program reference to a remote object, therefore, is actually a reference to a local stub.Remote Interface The Remote interface serves to recognize interfaces whose methods may be invoked from a non-local virtual machine. Any object that is a remote object must directly or indirectly implement this interface.Difference between RPC and RMIRemote procedure call (RPC) is a n etwork communication protocol with server and client architecture and the idea behind RPC is to call implemented code remotely as if we were on the dot calling a function. The only difference between RMI and RPC is in case of RPC functions are invoked through a proxy function, and in case of RMI we invoke methods through a proxy object.RMI is java solution to RPC, with connectivity to existing systems using native methods. RMI can take a natural, direct, and fully powered approach to provide a enterprise distributed computing technology that allows us to add Java functionality throughout the system. To get the cross-platform portability that Java provides, RPC requires a lot more overheads than RMI. RPC has to convert the arguments between architecture so that each computer can use its native data type.Java-RMI is tightly coupled with the Java language. Whereas RPC is not specific to any single language and one can implement RPC using different language.Because RMI can implemented using Java, its get all the advantages like object oriented, parallel computing, design pattern, low-cal to write and re use, safe and secure, Write once and run anywhere. But in the case of RPC, to achieve any of these advantages one has to write implementation code. adjudicate applicationTo demonstrate RMI and distributed application in real time I do implemented a draught system. The Lottery system is developed as per UK Lotto system. Assuming that user before using this RMI client application already purchased the lottery ticket.Lottery client system displays the welcome message to customer.Lottery system also displays the winning union to the customer. The Lottery system is developed as per UK Lotto system. But simplifying system I have modified true rules. Here how winner is chosen.Jackpot, Match 6 500,000Match 5 numbers 1,500Match 4 numbers 60Match 3 numbers 10. placement asks customer to enter positive integer number ranging 1 to 49.Once he enters all 6 numbers Lottery system generate 6 winning non-repeating random number between 1 to 49.System checks the match between user entered number and server generated number and calculate winning amount and display the resultImplementationHere is how I have implemented Lottery systemDefine a remote interfaceimport java.rmi.Remote ordinary interface LotteryGenerator extends Remote public ArrayList getLottoryNumber() throws java.rmi.RemoteExceptionImplement the remote interfaceBelow is the just a snippet of the implementation class for the remote interface. I have not listed the supporting cliquish methods of the class.import java.rmi.RemoteExceptionpublic class LotteryGeneratorImpl extends java.rmi.server.UnicastRemoteObject implements LotteryGeneratorprivate ArrayList numbers // Integer array for holding repeatprivate ArrayList lotprivate java.util.Random genpublic ArrayList getLottoryNumber()lot.clear()for(int i=0i
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.