Presentation is loading. Please wait.

Presentation is loading. Please wait.

UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 20 A little more on RMI Getting started with.

Similar presentations


Presentation on theme: "UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 20 A little more on RMI Getting started with."— Presentation transcript:

1 UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 20 A little more on RMI Getting started with Jini Mon. 11/20

2 Homework Status 1 Fri, 9/8 9/15, 9/18 2Fri, 9/15 Fri, 9/22 3Fri, 9/22 Fri, 9/29 4Fri, 10/6Fri, 10/13 5Fri, 10/13Fri, 10/20 6Fri, 10/20 Fri, 10/27 7Fri, 10/27 Fri, 11/3 & 11/6 8Fri, 10/27 Mon, 11/20 9Mon, 11/20 Fri, 12/1 HW# Assigned Due Graded Submitted Pending Start reading CoreJini (Chapters 1-5)

3 First, a little more on RMI...

4 Dynamic Loading of Code ä Server side can accept unknown (at compile time) subclasses as arguments to method invocations ä Requires such a class to create a codebase ä Tells the JVM where to get the code from (just like moving applets around in the Web!) ä Contains a URL that can be used to download the code ä All RMI does is annotate the serialized data with the URL ä Is used to transmit stubs around as well as customized code ä The client does not have to receive stubs ahead of time

5 Security Issues ä RMI supports downloading code at runtime ä E.g., getting stubs, remote polymorphism ä RMI provides a SecurityManager to enable the use of downloadable code ä Implements a rudimentary security policy (e.g., all code signed by Bill can write to this directory) ä See system.getSecurityManager(), system. setSecurityManager(), and class RMISecurityManager for more details

6 RMI Activation Framework ä Mechanism for starting server-side objects from the client side ä Activate remote objects when needed ä Deactivate them when not needed ä Useful when: ä Have rarely used remote objects ä Have many remote objects ä To reconstitute remote services after a crash ä Requires special code

7 Some Notes About RMI ä The distributed environment is more fragile (need to worry more about exceptions) ä Network connections can go down ä Remote machines can go down ä Garbage collection ä Remote references have a lease period ä If no local and no remote references, becomes a candidate for GC ä Invokes the unreferenced method of the Unreferenced interface (if implemented) vs finalize

8 Some Notes About RMI (continued ) ä A remote object can be richer than the interface it presents to the outside world ä Not all of its methods have to be exposed ä A remote object can expose multiple sets of interfaces ä E.g., an admin interface and a functional interface ä Higher parts of inheritance hierarchies can be remoted ä Base classes become servers ä Java does not use a separate Interface Definition Language (IDL) ä JAVA RMI is specific to Java ä Java does not use an Object Request Broker (ORB) ä Some typical ORB services are built into the RMI mechanism (e.g., naming, security)

9 A Short RMI Quiz http://developer.java.sun.com/developer/Quizzes /rmi

10 For More RMI Information... http://developer.java.sun.com/developer/onlineTraini ng/rmi - RMI Tutorial - RMI Exercises

11 Key Jini Concepts

12 Key Concepts Networking

13 Open Systems Interconnect (OSI) Reference Model Physical Data Link Network Transport Session Presentation Application 1 2 3 4 5 6 7 Sends bit stream through network Adds error, synchronization control Adds routing, forwarding Adds end-to-end control Adds session, connection coordination Adds syntax/presentation format conversion Adds user authentication, privacy Source :http://www.cisco.com/cpress/cc/td/cpress/fund/ith/ith01gb.htm

14 Key Networking Terms: Protocols ä Packet, Datagram: header (e.g. address) + data ä IP= Internet Protocol ä IP = Internet Protocol ä ä moves packets from network node to node ä TCP = Transmission Control Protocol (OSI layer 4) ä ä decomposes message into packets and recomposes (in order) on other end ä ä supports point-to-point messaging ä TCP/IP = TCP + IP = basic Internet protocol ä UDP = User Datagram Protocol (OSI layer 4) ä UDP = User Datagram Protocol ä uses datagrams UDP = User Datagram Protocol ä ä does not decompose, recompose, or provide ordering ä UDP/IP = UDP + IP = lightweight Internet protocol Source: http://www.whatis.com

15 Key Networking Terms (continued) See Core Jini (p. 202) ä Unicast: ä point-to-point ä separate message for each recipient ä sender knows IP address of recipient ä Broadcast: ä every party on network receives the message ä Multicast: “ In-between” Unicast and Multicast ä multiple parties may receive same message ä parties may be “grouped”

16 Key Concepts Chapter 3

17 Some Jini Definitions ä Service: an entity on the network (e.g. hardware device or software module) that can be used by other Jini participants ä Community: a group of Jini services that are “aware” of each other (typically workgroup size) ä Group: used by Jini APIs to specify and represent a community ä But, due to network separation, different communities may have same group name ä Federation: a collection of communities that are “aware” of each other

18 5 Key Concepts ä Discovery: find communities on a network and join them ä Lookup: use Lookup Service(s) to find services and use them ä Leasing: resource is “loaned” to some consumer for fixed time period ä Remote Events: allow services to notify others of their state changes ä Transactions: protocol to support multiple services moving to “safe” state

19 Key Concepts Chapter 3: Discovery

20 Discovery Single community example Lookup Service Assumes Java and network Service Provider Service Item Proxy Attribute

21 Joining Single community example Lookup Service Service Provider Service Item Proxy Attribute Service Item Proxy Attribute

22 Discovery/Joining Steps for a Service ä Find Lookup Service(s) ä Use Jini discovery protocol to get reference(s) to object(s) that implement lookup interface(s) (ServiceRegistrar interface) ä Join community(s) Lookup Service(s) ä Publish service object using join protocol ä use register( ) method of ServiceRegistrar ä pass service item to register( ) method Client also uses discovery to find Lookup Service(s)

23 Jini Discovery Protocols ä Lightweight ä Do not depend on Java (JVM, serialization, RMI...) ä Short messages ä minimize partial message loss due to multiple packets ä Jini multicast is based on UDP/IP ä Parties can join multicast group by listening for messages sent to a special IP address for that group ä Messages are confined to local network (subnet) ä Simple ä Implement DiscoveryListener interface, do simple bookkeeping

24 Jini Discovery Protocols (cont.) ä Multicast Request Protocol ä Used by service or client ä Find local, active lookup service(s) ä Multicast Announcement Protocol ä Used by Lookup Service ä Announces presence periodically ä Unicast Discovery Protocol ä Used by a service or client ä Communicate directly with a Lookup Service

25 Client D Client C Client B Discovery Example: Multiple Community Service Provider 1 Service 1 Item Service Provider 2 Service 2 Item Service Provider 3 Service 3 Item Service Provider 4 Service 4 Item Client A Client E Lookup Service Service 1 Item Service 4 Item Service 3 Item Service 2 Item Service 1 ItemService 4 Item Service 1 Item Service 2 ItemService 3 Item Service 4 Item Service 3 Item

26 Key Concepts Chapter 3: Lookup

27 Lookup Single community example Client Lookup Service Service Item Proxy Attribute Service Provider Service Item Proxy Attribute Service Item Proxy Attribute

28 Lookup ä Lookup service is like a name server, but with richer semantics ä Object returned from discovery implements lookup interface ServiceRegistrar ä To search for a service, use lookup( ) method of ServiceRegistrar interface ä Search parameters for matching a service item: ä type of proxy object ä service id (unique) ä attributes

29 Lookup (continued) ä Downloadable proxy insulates client from service communication and implementation details ä Proxy common scenarios: ä Proxy actually performs the service ä Proxy is an RMI stub for talking with remote service ä Proxy uses private communication protocol to communicate with service (e.g. legacy or hardware)

30 Service Invocation Single community example proxy manages service interaction ClientLookup Service Service Item Proxy Attribute Service Provider Service Item Proxy Attribute Service Item Proxy Attribute Lookup Service does not participate in service interaction.

31 Key Concepts Chapter 3: Leasing

32 Leasing ä Resource is “loaned” to some consumer for fixed time period ä Consumer must continue to show interest in resource ä Provides the resiliency of Jini ä Acts somewhat like garbage collection system for distributed system ä Leases used in Lookup Service and elsewhere ä Lease grantor (e.g. Lookup Service) grants a lease to lease holder (e.g. Service) ä Jini Leases work like “real world” leases ä They expire at predetermined time unless renewed ä They can be denied or granted by the grantor of the lease ä They can be renewed by the lease holder ä They can be canceled by either party ä They can be negotiated but the grantor has final say portions of this slide contributed by Ayal Spitz

33 Leasing (continued) Third-Party Leasing ä Delegate leasing authority to another party (but not responsibility) ä Like power-of-attorney ä Advantage: convenience ä third-party can keep renewing lease for you ä especially useful when service holding lease is long-lived but rarely active ä Third-party: LeaseRenewalManager class

34 Leasing (continued) ä register( ) method of ServiceRegistrar has integer lease duration parameter ä When service calls register( ), Lookup Service responds with Lease object (if it grants the lease) ä Single round of negotation ä Duration ä may be approximate due to time discrepancies in a distributed system ä right length of time may be application-dependent

35 Key Concepts Chapter 3: Remote Events

36 Remote Events ä Asynchronous (remote) event notification ä Asynchrony: “absolute and even relative times at which events take place cannot always be known precisely” [Distributed Computing, Attiya] ä Message handled outside normal flow of control of software component ä “Listener”/callback

37 Remote Events (continued) Remote vs. Local Events ä Java 2 event generator is a thread within JVM ä In remote case, it is hard to guarantee: ä Delivery itself ä failures, even partial ones, can occur ä recipient may be inactive (using RMI activation) ä Order of events ä Sending vs. event processing cost: ä local: send is often small compared with processing ä remote: send is often large compared with processing

38 Remote Events (continued) Event-Programming Model ä Use RemoteEventListener (an RMI Remote interface) to receive events ä its only method is notify( ) [distinct from Java notify( )] ä RemoteEvent class represents a remote event ä Simplicity allows event delegation ä can create generic third-party event listeners to store, use, forward remote events ä No generic way to express interest in events ä no addRemoteEventListener interface: each generator provides way for recipients to express interest ä Interest must be renewed (like leasing) ä Each RemoteEvent has a sequence number

39 Key Concepts Chapter 3: Transactions

40 Transaction Goals ä Atomicity ä All operations succeed or fail together ä Consistency ä Transaction leaves system in “consistent” state ä Isolation ä Applications are isolated from intermediate transaction operations ä Durability ä Successful transaction survives failure/crash

41 Transactions: Database Example Two-Phase Commit: Phase 1 Participant 1 Participant 2 Participant 3 Ready! Ready to Commit? Temporary Storage Phase 1: All services signal preparedness to commit Log Transaction Manager Permanent Storage Log

42 Transactions: Database Example Two-Phase Commit : Phase 2 Phase 2: All services are told to commit Commit! Participant 1 Participant 2 Participant 3 Temporary Storage Log Transaction Manager Permanent Storage Log If any part of the transaction fails, transaction logs are used to restore consistency.

43 Jini Transaction Model ä Two-phase commit transaction ä But it is only “skin-deep” ä Participants implement TransactionParticipant interface with methods ä prepare( ) ä commit( ) ä abort( ) ä Participating class must implement methods!

44 Chapter 3 Conclusion: How to be a Jini Service? ä Either you or a delegate must be able to: ä Connect to a TCP/IP network ( ) ä IP address and complete TCP stack with multicast message send/receive capability ä Participate in discovery to find a Lookup Service ä Register with a Lookup Service to provide proxy ä Keep leases current

45 Chapter 3 Conclusion: How to be a Jini Client/Consumer? ä Participate in discovery to find a Lookup Service ä Communicate with a Lookup Service to receive service proxy

46 Additional Jini Information ä Sun web sites ä http://www.javasoft.com/jini http://www.javasoft.com/jini ä http://www.jini.org http://www.jini.org ä Development – Books ä “Core Jini” by W. Keith Edwards ä “The Jini Specification” by Arnold, O’Sullivan, Scheifler, Waldo, and Wollrath ä Gartner Advisory: ä Java Jini: A ‘Killer-App Enabler’ for Network Computing? http://gartner.jmu.edu/research/ras/83000/83044/83044.html

47 Key Jini Concepts Core Jini Chapter 5 Core Jini Chapter 5 Getting Started with Jini: “Hello World”

48 “Hello World” Jini Community Service Provider 1 Service 1 Item Lookup Service Service 1 Item Client A Service 1 Item

49 “Hello World” Service and Client ä What they use: ä A Single Jini Community with Lookup Service ä Simple proxy ä provides “Hello World” string ä What they do not use: ä Proxy communication with service ä Lease renewal for service with Lookup Service ä Remote events and event registration renewal ä Transactions ä RMI activation for service

50 Using Jini ä Define interfaces ä Implement services ä Build clients that use the services ä Compile the pieces and run them Note the similarity between this and using RMI

51 Class and File Dependencies Jini Service Jini Client Proxy HelloWorldService.java Implementation HelloWorldServiceInterface.java Jini Interface HelloWorldClient.java class HelloWorldServiceProxy class HelloWorldService Wrapper

52 Common Structure for Service & Client Jini Service or Client Class HelloWorldX.java implements Runnable inner class Listener implements DiscoveryListener inner class Listener implements DiscoveryListener discovered( ) discovered( ) called when new Lookup Service is discovered called when new Lookup Service is discovered triggers handling of discovery event triggers handling of discovery event uses ServiceRegistrar uses ServiceRegistrar discarded( ) discarded( ) constructor constructor sets up a Security Manager sets up a Security Manager loads data structure to be used with Lookup Service loads data structure to be used with Lookup Service installs discovery Listener installs discovery Listener run( ): sleeps and makes sure JVM does not exit run( ): sleeps and makes sure JVM does not exit main( ): creates and starts thread main( ): creates and starts thread

53 Hello World: Service Side Getting Started with Jini Core Jini Chapter 5

54 Service Side: Proxy ä Proxy: class HelloWorldServiceProxy ä implements service interface ä implements java.io.Serializable interface ä has public, no-argument constructor (to support serializing) ä example shows proxy as top-level nonpublic class in service’s wrapper file

55 Service Side: Wrapper ä Wrapper: class HelloWorldService ä is “light-weight” in this example ä implements Runnable interface for a thread ä manages proxy’s Jini responsibilities ä constructor ä sets up a Security Manager ä configures ServiceItem to be used with Lookup Service ä installs discovery Listener ä discovery Listener inner class ä listens for Lookup Service(s) discovery events ä triggers registration with new Lookup Service(s) ä explicitly discards registration for a Lookup Service

56 Service Side: Registration ä Registration: ä triggered from discovery Listener ä uses ServiceRegistration, ServiceRegistrar classes ä publishes service object using join protocol ä use register( ) method of ServiceRegistrar ä pass ServiceItem and lease time to register( ) method ä get back unique serviceID

57 Service Side: Main ä In main( ) (in this example) ä Start an application thread ä Create an instance of the HelloWorldService class ä Create an instance of Thread class ä pass reference to HelloWorldService instance so Thread can use HelloWorldService’s run( ) method Note this is the same technique used in Exam2’s wave thread problem. Recall that this is the second of the 2 techniques for instantiating threads (first is extending class Thread).

58 HelloWorld Example: Core Jini Examine Service-Side Code Jini Service Proxy HelloWorldService.java Implementation HelloWorldServiceInterface.java Jini Interface class HelloWorldServiceProxy class HelloWorldService Wrapper

59 Hello World: Client Side Getting Started with Jini Core Jini Chapter 5

60 Client Side ä Client structure is similar to service structure ä Constructor ä sets up a Security Manager ä configures template to be used by Lookup Service for matching ä installs discovery Listener ä Discovery Listener inner class ä listens for Lookup Service(s) discovery events ä triggers lookup with new Lookup Service(s)

61 Client Side: Matching Template Client Template T matches a service X’s ServiceItem if: and and T’s serviceID = X’s serviceID T’s serviceID = null serviceIDs match: or X is instance or subtype of each type in T’s serviceType T’s serviceType = null serviceTypes match: or attributes match: or T’s attributes = null X’s attributes contain >=1 match for each attribute in T

62 Client Side: Lookup ä To search for a service, use lookup( ) method of ServiceRegistrar interface ä Pass template to lookup( ) ä This form of lookup( ) method returns first match ä Another form of lookup( ) method can return multiple matches

63 Client Side: Main ä In main( ) (in this example) ä Start an application thread ä Create an instance of the HelloWorldClient class ä Create an instance of Thread class ä pass reference to HelloWorldClient instance so Thread can use HelloWorldClient’s run( ) method Note this is the same technique used on service side

64 HelloWorld Example: Core Jini Examine Client-Side Code Jini Client HelloWorldClient.java

65 Hello World: Putting It All Together [PC Example] Getting Started with Jini Core Jini Chapter 5

66 Putting the Pieces in Place... ä Establish a network connection ä Need to start/run (in this order): ä HTTP daemon ä to offer up downloadable code from Lookup Service ä on same machine as Lookup Service ä RMI activation daemon ä on same machine as Lookup Service ä Jini Lookup Service ä on same subnet as Jini community ä Can use Chapter 1 startup-GUI

67 Using Chapter 1 Startup-GUI

68

69

70

71 start http daemon first start rmi daemon second start Lookup Service third

72 Developing for Non-Local Use ä Run a separate HTTP daemon for each program that provides downloadable code ä Put client, server and downloadable code into separate directories ä Consider bundling downloadable code into JAR file ä Beware: ä codebase problems ä classpath problems ä Use Security Manager & security policy file

73 Compiling the Service & Client javac -classpath C:\jini1_0_1\lib\jini- core.jar;C:\jini1_0_1\lib\jini-ext.jar;C:\jini1_0_1\lib\sun- util.jar;C:\service -d C:\service C:\corejini\chapter5\HelloWorldServiceInterface.java C:\corejini\chapter5\HelloWorldService.java javac -classpath C:\jini1_0_1\lib\jini-core.jar;C:\jini1_0_1\lib\jini- ext.jar;C:\jini1_0_1\lib\sun-util.jar;C:\client -d C:\client C:\corejini\chapter5\HelloWorldServiceInterface.java C:\corejini\chapter5\HelloWorldClient.java Service: Client:

74 Start an HTTP Server java -jar C:\jini1_0_1\lib\tools.jar -dir C:\service-dl -verbose -port 8085 ä Copy HelloWorldServiceProxy.class to server- dl sub-directory ä HTTP server will “serve up” downloadable code from server-dl sub-directory ä Pick an unused port (e.g. 8085)

75 Set Up a Security Policy File grant { permission java.security.AllPermission "", ""; }; policy.all ä Create a “permissive” policy file ä beyond this example permissions will be more strict

76 Directory/File Hierarchy c: policy.all policy corejinichapter5 HelloWorldServiceInterface.javaHelloWorldService.javaHelloWorldClient.java client HelloWorldServiceInterface.classHelloWorldClient$Listener.classHelloWorldClient.class corejinichapter5 HelloWorldServiceInterface.classHelloWorldServiceProxy.classHelloWorldService$Listener.classHelloWorldService.class corejinichapter5service service-dl HelloWorldServiceProxy.class corejinichapter5 inner “Listener” class

77 Finally...run the service! Run the service first java -cp c:\jini1_0_1\lib\jini-core.jar;c:\jini1_0_1\lib\jini- ext.jar;c:\jini1_0_1\lib\sun-util.jar;c:\service - Djava.rmi.server.codebase=http://pavilion:8085/ - Djava.security.policy=c:\policy\policy.all corejini.chapter5.HelloWorldService

78 Finally...run the client! Run the client second java -cp c:\jini1_0_1\lib\jini-core.jar;c:\jini1_0_1\lib\jini- ext.jar;c:\jini1_0_1\lib\sun-util.jar;c:\client - Djava.security.policy=c:\policy\policy.all corejini.chapter5.HelloWorldClient

79 Celebrate Success!


Download ppt "UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 20 A little more on RMI Getting started with."

Similar presentations


Ads by Google