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
Distributed Objects And A Jini Use Case 1. RMI Overview: Example taken from Java a) “Java” is not important – here for a use case of the concept of distributed objects (code not examinable, nor is it in labs). b) What is RMI c) Serialization: to disk, sockets and in RMI d) RMI in Action: A Broad Overview 2. Jini a) b) c) d) What is Jini Jini Scenario: An Overview Types of Jini Services Jini in Operation: Jini Protocols a) Discovery b) Join c) Lookup e) Jini Scenario: Filling in the Gaps f) Jini Scenario: More Detail … 3. Jini: other a) Jini Event Model b) Jini Groups 1 What is RMI? To communicate across the network in Java, can use: • Sockets – one to one, duplex connections • Need to pack data for socket and unpack other side • i.e. need to agree on format and internal protocol up front • RPC (Remote Procedure Call) • abstracts communication interface to the level of a procedure call • programmer appears to be calling a local procedure • encodes arguments and returns values using an external data representation e.g. XDR • RMI: Remote Method Invocation • 2 Similar to RPC but uses Java Serialization to pack objects Serialization in Java java.io.Serializable & java.io.Externalizable – Java Interfaces • For storing and retrieving objects • represents the state of objects sufficient for reconstruction • Objects to be saved in the stream may support: • Serializable interface: default serialization mechanism • Externalizable interface: custom serialization Java Object Serialize (ByteStream/String) 3 Java Object Disk File TCP Socket RMI Argument/ Parameter Deserialize (ByteStream/String) Serialize/Deserialize to Disk File Serialize today's date to a file: FileOutputStream f = new FileOutputStream("tmp"); ObjectOutputStream s = new ObjectOutputStream(f); s.writeObject(new Date()); s.flush(); Deserialize today's date from a file: FileInputStream in = new FileInputStream("tmp"); ObjectInputStream s = new ObjectInputStream(in); Date date = (Date)s.readObject(); Same for Sockets … - RMI does this for you automatically 4 Serializing a Class To Implement Default Serialization import java.io.Serializable; public class PersistentClass implements Serializable { transient private String notToCopy; private String name; To tag Instance variables which should not be copied 5 public PersistentClass() { notToCopy = whatever ; name = PersitentObject ; } } RMI In Action: A Broad Overview Known as a Java Proxy Object 1. Create a Remote Interface e.g. public void sendMessage(String message); 4. Call Remote Function by using Proxy RMI Service 5. Returns data from remote call (if any) RMI Client the network (TCP/IP) 2. Create Implementation of Remote Interface 6 3. Create Client Side that wants to call remote method What is Jini? Historically, operating systems rely on disk drives … Jini’s goal is to shift this reliance back to the network Key Features: • • Written in Java Uses RMI and Java Object Serialization to enable Java objects to move around the network • Offers network plug and play of services (java objects) Differences with RMI: 7 • Provides Discovery of Jini Services • Published RMI stub -> RMI proxy • Distributed Service concepts e.g.: • Searching, • Leasing and Grouping • Distributed Events Jini Concepts and Architecture 1. Jini Players 2. Broad Overview 3. Joining and Using a Jini Network a. Discovery b. Join – Leasing c. Lookup 4. A Jini Scenario: Filling in the gaps 5. Jini Scenario: More Detail.. 8 Jini Players Jini defines a runtime infrastructure that provides mechanisms that enable you to add, remove, locate, and access services. There are three main players: a service, such as a printer, scanner, storage device, a software service etc. a client which would like to make use of this service. a lookup service (LUS) - a service locator 9 … and yes, and the network connecting all three - generally be running TCP/IP Jini Scenario: Broad Overview 4. Jini client uses proxy to contact Jini service directly 3. Jini client receives Java proxy for Jini Service Jini Service 1. Jini service discovers LUS and registers its service LUS – Lookup Service 10 the network (TCP/IP) Jini Client (Consumer) 2. Jini client discovers LUS and locates the desired Jini service Brokered Architecture Using Jini Services Three ways proxies interact with the service: 11 • Proxy performs the service itself: • Java proxy code is completely self-contained – like an applet • does not require any remote functionality • Proxy is an RMI stub for a remote service: • proxy is a minimal piece of code - interface to the remote object • client makes a call on the proxy object, then make remote invocation (by transferring the arguments to the remote object) • Proxy is a Smart Adapter: Proxy contains code that decides where to execute it e.g.: execute code elsewhere (e.g. Web) or contact services written in other programming languages Jini Federations 12 • Federation of services available on the Jini network • cleints enlist the help of services to accomplish their tasks Joining and Using a Jini Network Jini defines one network-level protocol -discovery and two object-level protocols - join and lookup Discovery - enables clients and services to locate lookup services (LUS) Join - enables a service to register itself in a lookup service Lookup - enables a client to query a lookup service for available services. 13 Discovery • Unicast Interaction – Client knows location of Jini LUS e.g. jini://spectra.astro.cf.ac.uk – Use when static connections are needed • Multicast dynamic discovery – Uses the multicast request protocol • Sends multicast request message to a well known multicast address • LookUp service gets the request and connects to the requesting service. • Sends a unicast message which contains proxy for the lookup service. …whichever the method, when LUS is contacted: LUS return a ServiceRegistrar Object (using RMI) 14 Service Registrar The Join Process Allows services to register as Jini services with the LUS register(ServiceItem, long) Service Registrar Jini Service • Pass register() a ServiceItem object + lease duration (next….) ServiceItem Class: • ID for the service (automatically generated by LUS) • object implementing the actual Jini Service • attributes for service - list of objects 15 Leasing in Jini • used to keep track of active Jini services • can be set by service or controlled by LUS • services use leasing to register that they are alive, but allow themselves to be ``timed out'' if they have failed or if they are unreachable. • lookup service acts as the granter of the lease. Setting Lease Duration: Services can use defaults or set manually: • Lease.ANY - the service lets the lookup service decide on the time • Lease.FOREVER - the request is for a lease that never expires Grant Lease 4 Second Lease Scenario Jini Service LUS 16 2 4 31 Lookup • When a service has registered - its available for use by clients • Clients use lookup to find services Jini Client (Consumer) Lookup(ServiceTemplate t) Service Registrar (Obtain ServiceRegistrar using Discovery) ServiceTemplate: • contains the search query • typically search using Java type (i.e. interface) 17 public interface JiniPrinter { // print a document contained in String or throw PrinterException public void print(String text) throws PrinterException; } public Class LaserPrinter implements JiniPrinter { public int print(String text) throws PrinterException { // implement Laser-specific code here or throw exception } } Jini Scenario: Filling the Gaps Jini Service 4. Jini client uses proxy to contact Jini service directly 3. Jini client receives Java proxy for Jini Service 1. Jini service discovers LUS (Discovery) and registers its service (Join) LUS – Lookup Service 18 the network (TCP/IP) Jini Client (Consumer) 2. Jini client discovers LUS (Discovery) and locates the desired Jini service (Lookup) Jini Scenario: More Detail…. 7. Jini client uses Java proxy to communicate and use the Jini service Jini Service 3. invokes register() on ServiceRegistrar object to register service 6. invokes lookup() on ServiceRegistrar to locate desired service (returns Java proxy) 5. receives a ServiceRegistrar object 2. receives a ServiceRegistrar object 19 1. Jini service discovers LUS Jini Client (Consumer) LUS – Jini Lookup Service 4. Jini service discovers LUS Jini Event Model • Jini objects may also be interested in changes in other Jini objects i.e. want to be listeners for such changes. • Networked nature of Jini means need a different event model: – Network delivery is unreliable – Network delivery is time-dependent – A remote listener may have disappeared by the time the event occurs. Listeners have to be allowed to ``time out'', like services do. • Uses one event type RemoteEvent and small number of sublclasses – are serializable 20 Organization of Jini Services • Jini Services are organized as a federations of services i.e. communities • Grouping • similar to communities – groups are the names used to represent communities • Based around LUS -> client can search for specific groups • LUS can be members of many groups • not globally unique 21 Distributed Objects 1. RMI Overview a) What is RMI, Serialization, Broad Overview 2. Jini a) b) c) d) What is Jini Jini Scenario: An Overview Types of Jini Services Jini in Operation: Jini Protocols a) Discovery b) Join c) Lookup e) Jini Scenario: Filling in the Gaps f) Jini Scenario: More Detail … 3. Jini: other a) Jini Event Model b) Jini Groups 4. Focus a) To provide a context for distributed objects b) E,g, what are the difference between distributed objects and services? 22