Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Remote Method Invocation RMI Distributed Object Applications • RMI applications are often comprised of two separate programs: – A server – A client • Distributed object applications need to: – Locate remote objects – Communicate with remote objects – Load class bytecodes for objects that are passed as parameters or return values RMI Layers RMI Development Process Differences • The Java platform's distributed object model differs from the Java platform's object model in these ways: – Clients of remote objects interact with remote interfaces, never with the implementation classes of those interfaces. – Non-remote arguments to, and results from, a remote method invocation are passed by copy rather than by reference. This is because references to objects are only useful within a single virtual machine. – A remote object is passed by reference, not by copying the actual remote implementation. – The semantics of some of the methods defined by class java.lang.Object are specialized for remote objects. – Since the failure modes of invoking remote objects are inherently more complicated than the failure modes of invoking local objects, clients must deal with additional exceptions that can occur during a remote method invocation. RMI Interfaces and Classes • java.rmi package hierarchy : – java.rmi. – java.rmi.server – java.rmi.registry RMI Core (1) • Remote interface – Does not define any methods. Every Remote objects must implement this interfaces • RemoteException class – the superclass of exceptions thrown by the RMI runtime during a remote method invocation. -------------------------------------------------------------------------------------------import java.rmi.*; public interface yourOwnDefinedService extends java.rmi.Remote { // declare yourOwnDefinedMethods public int method1 ( int number ) throws RemoteException; ……………………. } RMI Core (2) • UnicastRemoteObject class – Class implement a remote server object with the following characteristics: • All references to the remote objects are only valid during the life time of the process that create the remote object • The remote protocol requires a TCP connection • Client/server communicate parameters, invocations, and results using a stream protocol import java.math.*; import java.rmi.*; import java.rmi.server.*; public class yourOwnDefinedServiceServer extends UnicastRemoteObject implements yourOwnDefinedService { public yourOwnDefinedServiceServer () throws RemoteException { super(); } // implement the methods public int method1 ( int number ) throws RemoteException { //implementation of method here ... } // ....... probably more method implementation here public static void main ( String args[] ) throws Exception{ // Assign a security manager // Create an instance of our power service server ... // ... and bind it with the RMI Registry } } RMI Core (3) import java.rmi.*; import java.rmi.Naming; import java.io.*; public class yourOwnDefinedServiceClient { public static void main(String args[]) throws Exception{ ………. // Assign security manager // Call registry for PowerService ……….. } RMI Naming RMI Security