&扇 Using RMI 11 4.Create and compile the server application (registration) 5.Create and compile a client program to access the remote objects 6.Start the RMI Registry and the server application 7.Test the client Institute of Computer Software 2022-2-27 Nanjing University
Using RMI 4. Create and compile the server application (registration) 5. Create and compile a client program to access the remote objects 6. Start the RMI Registry and the server application 7. Test the client 2022-2-27 Institute of Computer Software Nanjing University 11
&扇 Point 1 Remote Interface 1902 12 ▣Remote All remote interfaces must extend the interface java.rmi.Remote(tagging interface) All methods must throw a java.rmi.RemoteException (extension of java.io.IOException) Institute of Computer Software 2022-2-27 Nanjing University
Point 1 – Remote Interface Remote All remote interfaces must extend the interface java.rmi.Remote (tagging interface) All methods must throw a java.rmi.RemoteException (extension of java.io.IOException) 2022-2-27 Institute of Computer Software Nanjing University 12
&扇 Point 2 -Implementation 102 13 UnicastRemoteObject Application must implement the defined remote interface Application extends class UnicastRemoteObject or calls explicitly UnicastRemoteObject.exportObject ■link to RMI system base class performs RMI linking and remote object initialization constructor may throw a RemoteException Activatable Base class to be used for activatable objects 口激活服务的目标:只有在需要时才启动服务进程 Institute of Computer Software 2022-2-27 Nanjing University
Point 2 – Implementation UnicastRemoteObject Application must implement the defined remote interface Application extends class UnicastRemoteObject or calls explicitly UnicastRemoteObject.exportObject link to RMI system base class performs RMI linking and remote object initialization constructor may throw a RemoteException Activatable Base class to be used for activatable objects 激活服务的目标:只有在需要时才启动服务进程 2022-2-27 Institute of Computer Software Nanjing University 13
Dynamic stubs in Java 1.5 14 ▣Dynamic Proxies Implemented using java.lang.reflect.Proxy (where the implementation is based on a RemoteObjectInvocationHandler) Dynamic proxy is only used if no pre-generated stub class is available or if the system property java.rmi.server.ignoreStubClasses true. It is only possible if clients run on Java 5. Notice If a remote object has pre-1.5 clients,then that remote object should use a stub class pre-generated with rmic.There are two stub class. protocols:v1.1 /v1.2 (default). Institute of Computer Software 2022-2-27 Nanjing University
Dynamic stubs in Java 1.5 Dynamic Proxies Implemented using java.lang.reflect.Proxy (where the implementation is based on a RemoteObjectInvocationHandler) Dynamic proxy is only used if no pre-generated stub class is available or if the system property java.rmi.server.ignoreStubClasses = true. It is only possible if clients run on Java 5. Notice : If a remote object has pre-1.5 clients, then that remote object should use a stub class pre-generated with rmic. There are two stub class. protocols: v1.1 / v1.2 (default). 2022-2-27 Institute of Computer Software Nanjing University 14
&扇 Point 3 Server 15 RMI service must be hosted in a server process whose job is: to create an instance; to register the object with the naming service. Naming/Registry service RMI can use different naming services: (i)Simple service:RMI Registry; (ii)JNDI (Java Naming and Directory interface). Institute of Computer Software 2022-2-27 Nanjing University
Point 3 – Server RMI service must be hosted in a server process whose job is: to create an instance; to register the object with the naming service. Naming/Registry service RMI can use different naming services: (i) Simple service: RMI Registry; (ii) JNDI (Java Naming and Directory interface). 2022-2-27 Institute of Computer Software Nanjing University 15