1 / 51

Java Remote Method Invocation (RMI)

Java Remote Method Invocation (RMI). ). Distributed Systems. „ a collection of independent computers that appears to its users as a single coherent system. Models of Distribution. „ Message passing. „ Distributed objects. „ Event-based architectures „ Space-based paradigms.

fairly
Download Presentation

Java Remote Method Invocation (RMI)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JavaRemoteMethodInvocation(RMI) )

  2. DistributedSystems „a collection of independent computers thatappearstoitsusersasasinglecoherentsystem

  3. ModelsofDistribution „Message passing „Distributed objects „Event-based architectures„Space-based paradigms

  4. DistributedObjectModel „Views a distributed system as a series ofinteractingobjects „Based on some underlying messagepassingprotocolinvisibletotheprogrammer „Three main technologies: RMI, CORBAandDCOM

  5. DistributedObjectComputing „Enable any object in the local system to directly interact with an object on a remote host „Goals: „Let any object reside anywhere in the network, and allow an application to interact with these objects in the same way as they do with a local object. „Provide the ability to construct an object on one host and transmit it to another host. „Enable an agent on one host to create an object on another host.

  6. WhatIsRMI? „A mechanism that allows the invocation ofamethodthatexistsinanotheraddressspace „Java-to-Java only „Client-Server Protocol„High-level API „Transparent„Lightweight

  7. RelatedTechnologies „RPC (“Remote Procedure Calls”) „Developed by Sun „Platform-specific „CORBA (“Common Object Request Broker Architecture”) „Developed by OMG „Access to non-Java objects (as well as Java) „DCOM (“Distributed Common Object Model”) „Developed by Microsoft „Access to Win32 objects „LDAP (“Lightweight Directory Access Protocol”) „Finding resources on a network

  8. RMI „Client –the process that invokes a method on aremoteobject „Server –the process that owns the remoteobject „Object Registry –a name server that relatesobjectswithnames „Objects are registered with the Object Registry, undera unique name. „The Object Registry is used to obtain access toremote objects, using their names.

  9. RemoteObjects(Diagram) Java Virtual Machine Java Virtual Machine ClientObject Remote Object TCP Client Server

  10. RMILayers Java Virtual Machine Client Java Virtual Machine Remote Object Object Stub Skeleton Remote Reference Layer Remote Reference Layer TCP Transport Layer Transport Layer 11/18/2003

  11. RMIArchitectureintheOSImodel User Application Application Layer Presentation Layer Stub Skeleton Remote Reference Layer Session Layer TCP Transport Layer IP Network Layer Data-link layerPhysical Layer Hardware Interface Network

  12. Java Virtual Machine Java Virtual Machine ClientObject RemoteObject RemoteObjects Stub Skeleton Remote Reference Layer Remote Reference Layer TCP Transport Layer Transport Layer Server Client „Remote Objects „Live on server „Accessed as if they were local

  13. Java Virtual Machine Java Virtual Machine ClientObject RemoteObject StubsandSkeletons Stub Skeleton Remote Reference Layer Remote Reference Layer TCP Transport Layer Transport Layer Server Client „Stub „lives on client „pretends to be remote object -a proxy for the remote object „Skeleton „lives on server „receives requests from stub, talks to the remote object and delivers response to stub „Stubs and skeletons are not written by the programmer! They are generated by a special compiler “rmic”

  14. Java Virtual Machine Java Virtual Machine ClientObject RemoteObject StubsandSkeletons Stub Skeleton Remote Reference Layer Remote Reference Layer TCP Transport Layer Transport Layer Server Client „Stub –responsibilities „Initiate remote calls „Marshals arguments to be sent „Informs the remote reference layer that a callshouldbeinvokedontheserver „Unmarshals a return value (or exception) „Informs the remote reference layer that thecalliscomplete

  15. Java Virtual Machine Java Virtual Machine ClientObject RemoteObject StubsandSkeletons Stub Skeleton Remote Reference Layer Remote Reference Layer TCP Transport Layer Transport Layer Server Client „Skeleton –responsibilities „Unmarshals incoming arguments „Calls the actual remote object implementation„Marshals return values for transport to theclient „Marshaling –definition „The process of converting native programminglanguagedatatypestoaformatsuitablefortransmissionacrossanetwork

  16. RemoteInterfacesandStubs Remote Interface implements implements Remote Object Client Stub Skeleton (Server) 11/18/2003

  17. RemoteInterfaces „Declare exposed methods –the methodsthatcanbecalledfromremotelocations „Extend java.rmi.Remote „The remote object implements thisinterface „Act like a proxy for the remote object

  18. Java Virtual Machine Java Virtual Machine ClientObject RemoteObject RemoteReferenceLayer Stub Skeleton Remote Reference Layer Remote Reference Layer TCP Transport Layer Transport Layer Server Client „Sets up connections to remote addressspaces „Manages connections „Listens for incoming calls„Communicates via TCP/IP

  19. ObjectRegistries „Name and look up remote objects „Remote objects register by name „Clients obtain a remote reference to theremoteobject „A registry is a running processon thesamehostastheRMIserver

  20. HTTPTunneling „Cool: if it can’t make the connection normally,itwilltunnelthroughport80 „Allows clients behind firewall to makeremotecallstoserver „Note: does not work server -> client

  21. RMISystemArchitecture Client Virtual Machine Client Server Virtual Machine Remote Object Skeleton Server Stub Server Client “Fred” Registry Registry Virtual Machine

  22. RMIFlow 1. Server Creates Remote Object Server Virtual Machine Remote 2. Server Registers Remote Object Client Object 1 Skeleton Server Stub 2 “Fred” Registry Virtual Machine

  23. RMIFlow Client Virtual Machine Client Server Virtual Machine 3. Client requests object from Registry 4. Registry returns remote reference Skeleton Server Stub 3 4 “Fred” Registry Virtual Machine

  24. RMIFlow Client Virtual Machine Client Server Virtual Machine Remote Object 5 7 6 Skeleton Server Stub 5. Client invokes stub method 6. Stub talks to skeleton 7. Skeleton invokes remote object method Registry Virtual Machine

  25. PartII:RMIUsage 11/18/2003 and Distributed Programming

  26. CreatingRemoteObjects „Define a Remote Interface „extends java.rmi.Remote „Define a class that implements theRemoteInterface „extends java.rmi.RemoteObject„or java.rmi.UnicastRemoteObject

  27. RemoteInterfaceExample importjava.rmi.*; publicinterfaceAdder extendsRemote { publicintadd(intx,inty) throws RemoteException;} ECE 451:Introduction to Parallel 11/18/2003

  28. RemoteClassExample import java.rmi.*; import java.rmi.server.*; public class AdderImpl extends UnicastRemoteObject implements Adder { public AdderImpl() throws RemoteException{ } public int add(int x, int y) throws RemoteException{ return x + y; } }

  29. InheritanceDiagraminJava Object Remote RemoteObject RemoteStub RemoteServer Unicast RemoteObject

  30. CompilingRemoteClasses „Compile the Java class „javac „reads .java file „produces .class file „Compile the Stub and Skeleton „rmic „reads .class file „produces _Skel.class and _Stub.class

  31. CompilingRemoteClasses (Diagram) javac Adder.java(interface) AdderImpl_Skel.class(skeleton classfile) Adder.class (interface classfile) javac AdderImpl.java(remote class) AdderImpl.class(classfile) rmic AdderImpl_Stub.class(stub classfile) ECE 451:Introduction to Parallel 11/18/2003 and Distributed Programming

  32. RegisteringRemoteClasses „start the registry „running process„Unix: rmiregistry& „Windows: start/mrmiregistry

  33. RegistryCLASSPATH „Registry VM needs to be able to find stub file(s)„You must set the CLASSPATH to include thedirectorycontainingthestubfile „An easy way to check CLASSPATH is to use the javapcommand, supplying a fully package qualified class name. It uses the current CLASSPATH to find and print the interface to a class. „Or, your server needs to specify the java.rmi.server.codebaseSystemproperty(morelater)

  34. Createtheserver „Creates a new instance of the remoteobject „Registers it in the registry with a name„That’s it ECE 451:Introduction to Parallel 11/18/2003 and Distributed Programming

  35. RMIServerExample try { AdderImpl adder = newAdderImpl(); Naming. rebind ("adder", adder); System.out.println("Adder bound");} catch (RemoteException re) { re.printStackTrace(); } catch (MalformedURLException me) { me.printStackTrace(); }

  36. LaunchtheServer %javaAdderServer&Adderbound ECE 451:Introduction to Parallel 11/18/2003 and Distributed Programming

  37. ServerLogging „invoke from command linejava -Djava.rmi.server.logCalls=trueYourServerImpl „or enable inside program RemoteServer.setLog(System.err);

  38. CreatinganRMIClient „Install a Security Manager „to protect from malicious stubs„Find a registry „use java.rmi.Naming „Lookup the name, returns a reference„Cast the reference to the appropriateRemoteInterface „Just use it!

  39. RMIURLs rmi://host[:port]/name„default port is 1099 „Specifies hostname of registry„can also use relative URLs „name only „assumes registry is on local host

  40. RMIClientExample System.setSecurityManager(newRMISecurityManager());Addera=(Adder) Naming.lookup("adder"); intsum=a.add(2,2); System.out.println("2+2="+sum);

  41. RemoteInterfacesvs.Remote Classes „Remember that the reference is to an interface„You must make references, arrays, etc. out ofthe interfacetype,nottheimplementationtype „You can’t cast the remote reference to a normalreference „So name your Remote Objects with “Impl” (soyoudon’tgetconfused)

  42. ParameterPassing „All parameters are passed by value „Primitive types „passed by value„Objects „passed by value „use Java Object Serialization

  43. ObjectSerialization „saves the state (data) of a particularinstanceofanobject „serialize-to save „unserialize -to load

  44. JavaSerialization „writes object as a sequence of bytes„writes it to a Stream „recreates it on the other end „creates a brand new object with the olddata

  45. java.io.Serializable „Objects that implement the java.io.Serializableinterfacearemarkedasserializable „Also subclasses „empty interface -just a marker –no needtoimplementanyspecialmethods

  46. RMISecurity „Server is untrusted „Stubs could be malicious „rmic is OK, but someone could custom-codeanevilstub:it’sjusta.classfile

  47. RMISecurityManagers „AppletSecurityManager „stub can only do what an applet can do„RMISecurityManager „disables all functions except class definition andaccess „A downloaded class is allowed to make a connectionif the connection was initiated via the RMItransport. „None „Stub loading disabled „Stubs still work if they are in local classpath

  48. LimitationsofRMI „Java-only „but you can use JNI on the server„Uses TCP, not UDP „At least two sockets per connection„Untested for huge loads

  49. Sunvs.Microsoft „RMI is not shipped as part of Microsoft’sproducts „RMI will still work in applications „include java.rmi.* class files in your classpath„download rmi.zip from ftp.microsoft.com „RMI will work in applets „include java.rmi.* class files (or rmi.zip) in yourcodebase „extra download time

  50. RMIChatServerObjects Message interface interface ChatServer MessageReceiver - login(MessageReceiver) - receiveMessage(Message) - sendMessage(Message) ChatClient ChatServerImpl implements Dispatcher remote reference MessageQueue local reference

More Related