Overview of RMI Architecture 1132022 Peter Cappello cappellocs






















- Slides: 22
Overview of RMI Architecture 1/13/2022 Peter Cappello cappello@cs. ucsb. edu Jump to first page
Introduction. . . Remote methods have: n much greater latency n new failure modes Do not distribute that which does not need to be 1/13/2022 cappello@cs. ucsb. edu Jump to first page
Introduction. . . Remote method invocation is like local method invocation, except: n Arguments & return values must: u implement u be n Serializable, or Remote objects. Arguments & return values are passed by value. 1/13/2022 cappello@cs. ucsb. edu Jump to first page
Other differences. . . n n An RMI client refers to a remote object via a Remote interface (it may have many). The object methods: u equals() u hash. Code(), u to. String() 1/13/2022 are overridden by java. rmi. Remote. Object. For example, the to. String value includes transport info (network protocol, host name, & port number) cappello@cs. ucsb. edu Jump to first page
Remote Object Structure n n n To apply a remote method (y) to a remote object (x): x. y() x must be a reference to a remote object. The RMI client gets this reference: u from a rmiregistry or u as the return value of a prior remote method invocation 1/13/2022 cappello@cs. ucsb. edu Jump to first page
Reference from Registry rmiregistry 2. Lookup service 1. Register service Client Server 3. Invoke method 1/13/2022 cappello@cs. ucsb. edu Jump to first page
Remote Objects Implement the Remote Interface n A remote object must implement at least 1 interface that extends the java. rmi. Remote interface. n Only those methods declared in the interface can be invoked remotely. n A diagram follows. . . 1/13/2022 cappello@cs. ucsb. edu Jump to first page
The Object Hierarchy Classes java. lang. Object Interfaces java. rmi. Remote java. rmi. server. Remote. Object java. rmi. server. Remote. Server java. rmi. server. Unicast. Remote. Object 1/13/2022 Your. Remote. Interface Your. Remote. Object cappello@cs. ucsb. edu Jump to first page
RMI System Architecture RMI Client Stub Application Layer RMI Server Proxy Layer Skeleton Remote Reference Layer 1/13/2022 Transport Layer cappello@cs. ucsb. edu Jump to first page
Application Layer n No interface description language (IDL) n The server application: u Implements the remote interface that the client uses. u Exports the object whose methods are invoked remotely (implicitly by extending Unicast. Remote. Object) 1/13/2022 u Registers itself with the rmiregistry. cappello@cs. ucsb. edu Jump to first page
Application Layer. . . n The client application: u Gets reference to remote object (o) u Casts reference as remote interface (t) u Applies methods (m) 1/13/2022 cappello@cs. ucsb. edu Jump to first page
Proxy Layer: Stub n The stub is the client’s proxy for the remote object. It: u marshals arguments u unmarshals u can returned values be typed as any of the remote object’s remote interfaces 1/13/2022 cappello@cs. ucsb. edu Jump to first page
Proxy Layer: Skeleton n The skeleton is the server’s proxy for the remote object. It: u Un-marshals u dispatches u marshals arguments actual method returned values 1/13/2022 cappello@cs. ucsb. edu Jump to first page
Remote Reference Layer n An abstraction between the proxy layer and the transport layer. n It’s mostly reserved for future development: u replicated objects u persistent objects u connection recovery 1/13/2022 cappello@cs. ucsb. edu Jump to first page
Transport Layer n This layer implements machine-tomachine communication. n It defaults to TCP/IP. n It can be overridden if you want to: u encrypt streams u compress streams u perform 1/13/2022 other security & performance enhancements cappello@cs. ucsb. edu Jump to first page
Name Service n n n Remote object registers itself with name server: rmiregistry Clients get reference to remote object by looking up object’s reference in rmiregistry. There are 2 ways: 4 1 rmiregistry/machine for all applications on a well-known port. 6 Application has its own rmiregistry on its own port. 1/13/2022 cappello@cs. ucsb. edu Jump to first page
Garbage Collection n A remote object can implement java. rmi. server. Unreferenced interface. n Method unreferenced is invoked when the object is no longer referenced: You can do “clean up”. n If network fails, an object may be wrongly collected. n Referencing a non-existent object causes a Remote. Exception to be thrown. 1/13/2022 cappello@cs. ucsb. edu Jump to first page
Class Loaders n n n 1/13/2022 Class loaders dynamically load classes as needed. The RMIClass. Loader loads the stub & skeleton classes, & any utility classes they need. For stub & skeleton classes, it looks in the directory named in the system property: java. rmi. server. codebase, set by the -D flag of the java interpreter. cappello@cs. ucsb. edu Jump to first page
Security n n Eavesdropping: Secure Sockets Layer (SSL) can be used instead of TCP. Misbehaving code: RMI requires a security manager. u Stand-alone applications set the security manager in main(). u System. set. Security. Manager(new RMISecurity. Manager()); 1/13/2022 prohibits stub classes from doing anything over the network except loading necessary classes. cappello@cs. ucsb. edu Jump to first page
Performance n RMI is simple to use. n RMI is not as fast as local MI. n n RMI is not as fast as special-purpose communication protocols can be. RMI may not be efficient enough for high-performance real-time applications, such as video streaming. u If 1/13/2022 you override TCP with a faster protocol, RMI may be fine. cappello@cs. ucsb. edu Jump to first page
Summary: RMI Server To write an RMI server: n Define interface that extends Remote. n Define a class that extends Unicast. Remote. Object & implements your remote interface. n 1/13/2022 Its main(): u Registers itself in the registry. cappello@cs. ucsb. edu Jump to first page
Summary: RMI Client n Execute System. set. Security. Manager( new RMISecurity. Manager() ); n Get a reference to the remote object by looking it up in rmiregistry. n Apply methods as though it were local. u Behind 1/13/2022 the scenes, object proxies, stubs & skeletons, are communicating. cappello@cs. ucsb. edu Jump to first page