Title: Jini Lecture
1Jini Lecture
- RMI Overview
- What is RMI
- Serialization to disk, sockets and in RMI
- RMI in Action A Broad Overview
- Jini
- What is Jini
- Jini Scenario An Overview
- Types of Jini Services
- Jini in Operation Jini Protocols
- Discovery
- Join
- Lookup
- Jini Scenario Filling in the Gaps
- Jini Scenario More Detail
- Jini other
- Jini Event Model
- Jini Groups
2What 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
- Similar to RPC but uses Java Serialization to
pack objects
3Serialization 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
Java Object
Disk File
Serialize (ByteStream/String)
Deserialize (ByteStream/String)
TCP Socket
RMI Argument/ Parameter
4Serialize/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()
5Serializing a Class
To Implement Default Serialization
import java.io.Serializable public class
PersistentClass implements Serializable
transient private String notToCopy private
String name public PersistentClass()
notToCopy whatever    name
PersitentObject  Â
To tag Instance variables which should not be
copied
6RMI In Action A Broad Overview
4. Call Remote Function by using Proxy
7What is Jini?
Historically, operating systems rely on disk
drives
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
- Provides Discovery of Jini Services
- Published RMI stub -gt RMI proxy
- Distributed Service concepts e.g.
- Searching,
- Leasing and Grouping
- Distributed Events
8Jini
- Jini Players
- Broad Overview
- Joining and Using a Jini Network
- Discovery
- Join
- Leasing
- Lookup
- A Jini Scenario Filling in the gaps
- Jini Scenario More Detail..
9Jini Players
Jini defines a runtime infrastructure that
provides mechanisms that enable you to add,
remove, locate, and access services. There are
three main players
and yes, and the network connecting all three -
generally be running TCP/IP
10Jini Scenario Broad Overview
Jini Service
Jini Client (Consumer)
LUS Lookup Service
the network (TCP/IP)
11Using Jini Services
- Several ways proxies interact with the service
- Proxy performs the service itself Java proxy
code is completely self-contained - does not require any remote functionality
- Similar to ?
- 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 RMI
transfers this call and arguments to the remote
object on the service provider, where the actual
execution is made - Proxy is a Smart Adapter Proxy contains code
that decides where to execute it e.g. could use - sockets
- Corba
- JXTA
- gain access to hardware devices that have their
own communication protocol - contact services written in other programming
languages
12Jini Federations
- Federation of services available on the Jini
network - cleints enlist the help of services to
accomplish their tasks
13Joining 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.
14Discovery
- 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.
15The Join Process
Allows services to register as Jini services with
the LUS
register(ServiceItem, long)
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
16Leasing 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
2
4
2
4
2
4
1
3
1
3
1
3
17Lookup
- When a service has registered - its available
for use by clients - Clients use lookup to find services
Lookup(ServiceTemplate t)
Jini Client (Consumer)
(Obtain ServiceRegistrar using Discovery)
- ServiceTemplate
- contains the search query
- typically search using Java type (i.e. interface)
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
18Jini Scenario Filling the Gaps
Jini Service
Jini Client (Consumer)
LUS Lookup Service
the network (TCP/IP)
19Jini Scenario More Detail.
20Jini 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
21Organization 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 -gt client can search for
specific groups - LUS can be members of many groups
- not globally unique
22Jini Lecture
- RMI Overview
- What is RMI, Serialization, Broad Overview
- Jini
- What is Jini
- Jini Scenario An Overview
- Types of Jini Services
- Jini in Operation Jini Protocols
- Discovery
- Join
- Lookup
- Jini Scenario Filling in the Gaps
- Jini Scenario More Detail
- Jini other
- Jini Event Model
- Jini Groups
- Focus
- Detailed Jini Scenario, details of protocols