Jini for DistJava
Jan Newmarch
jan@newmarch.name
Monash University
Background
Communication
-
In socket-level programming all communication between client
and server is coded by the programmer
-
In RPC, the code for communication is generated from a specification.
The client includes this generated code and makes calls on it.
The server code is generated and calls implementation code
-
In CORBA, a specification is used to generate a server and client half-objects.
The client calls methods on the half-object which does communication to the
server which calls a server-side object
-
Java RMI does the same, but also allows copies of objects to be made across
the network, so that the programmer can deal with local objects, remote
references, or copies of remote objects
-
Jini adds the possibility of making the remote references into remote
copies, so that there are more choices of remote object: "dumb" references
or "smart" proxies
Lookup
-
In socket-level programming, you need to know the location and port of
a service in order to connect to it
-
In RPC, you need to know the host. The
portmapper
service
is a well-known service that handles RPC calls on a standard port
-
CORBA has three methods to locate services
-
A string format, which can be passed by e.g. email
-
A naming service running anywhere in the network that stores
name/reference pairs. A service is told the host name and port
of the naming service and registers with it.
A server is also told the host name and port of the naming
service and looks up services on it
-
A trader running anywhere in the network, that clients and services
know about
-
RMI has a naming service which runs on the same machine as the service.
Clients must know this hostname
-
Jini has a lookup service which is either located by multicast on a local
network or is on a host known to clients and services
OVERVIEW
What is Jini?
-
Jini brings ``network plug and play'' to hardware devices
and software services
-
Jini is in pure Java
-
It makes hardware and software available as Java networked services
-
``Legacy'' systems can be wrapped in a Java proxy
-
Jini has competitors including CORBA Trader, DCOM, HP's Chai,
Enterprise Java Beans, JNDI, etc
Jini Federation
-
A Jini federation or ``djinn'' consists of a number of clients,
services and service locators
-
Typically connected by TCP/IP
-
Objects are moved around from service to locator to client using
MarshalledObject's
Figure 1: Components of a Jini federation
Service Registration
Figure 2: Querying for a service locator
Figure 3: Registrar returned
Figure 4: Service uploaded
Client Lookup
Figure 5: Querying for a service locator
Figure 6: Registrar returned
Figure 7: Asking for a service
Figure 8: Service returned
Support Services
-
Jini objects are moved in ``marshalled'' form
-
Class files may need to follow these for proper activation
-
The class files may need to be available from HTTP servers
-
Security permissions will need to be set using JDK 1.2
security model
Proxies
-
A toaster will be controlled by some service software
-
The service software will be moved across the network to the client
-
The mobile code must be a proxy for the real service code
-
The proxy may be explicitly written or be an RMI proxy stub
-
Remote calls from the proxy may be RMI Remote calls, or by some
other mechanism such as private TCP connection
Attribute Registration
-
A service is uploaded to a locator as an instance of a class
-
Additional information such as address may also be uploaded
as instances of Entry classes
-
Service registration is done using a leasing system
Service Location
-
A client asks for a service as an instance of a class,
typically of an interface
-
A client may ask for additional Entry attributes
-
Matching on fields is exact
-
You can ask for a printer with a certain speed, but not for
one greater than a certain speed
-
Additional services may be used if complex boolean expressions
are needed
Leasing
-
Because services can come and go, network connections can be lost, etc,
a distributed garbage collection mechanism is needed
-
Services which register are granted a lease
-
Registration lasts for as long as the lease
-
When the lease expires, the service is removed
-
Leases can be renewed
Non-distributed Application
Distributed Version
Client Structure
Internally a client will look like
prepare for discovery
|
discover a lookup service
|
prepare a template for lookup search
|
lookup a service
|
call the service
|
Server Structure
prepare for discovery
|
discover a lookup service
|
create information about a service
|
export a service
|
renew leasing periodically
|
ENTRIES
Entry class
Creating entries
Interfaces, implementations and entries
-
A client looks for an instance of an interface
-
It may qualify the search with entries
-
A service exports an implementation of this interface
-
A service will also export additional entry information, as much
as it can
SIMPLE SYSTEM
Jini Converter Service
-
This shows a Jini version of the
Converter
service
-
It is as minimal as possible!
-
Some poor practises are used, like throwing exceptions out to the main
process
Jini Service Specification
Jini Service Implementation
Jini Server
Jini Client
Jini Environment
-
There must be a Jini lookup service running to act as the "billboard"
-
The Jini distribution contains one, called
reggie
-
An HTTP server should be running, to deliver class files
-
The converter server runs with one set of class files
-
Converter
-
ConverterImpl
-
Server
-
The converter client runs with another set of class files
-
These files should be on the HTTP server so that clients can find the class
definitions
SECURITY
JDK 1.2 Security
Service requirements
grant {
permission net.jini.discovery.DiscoveryPermission "*";
// multicast request address
permission java.net.SocketPermission "224.0.1.85", "connect,accept";
// multicast announcement address
permission java.net.SocketPermission "224.0.1.84", "connect,accept";
// RMI connections
permission java.net.SocketPermission "*.dstc.edu.au:1024-", "connect,accept";
permission java.net.SocketPermission "130.102.176.249:1024-", "connect,accept";
permission java.net.SocketPermission "127.0.0.1:1024-", "connect,accept";
// reading parameters
// like net.jini.discovery.debug!
permission java.util.PropertyPermission "net.jini.discovery.*", "read";
};
Client requirements
The client is most at risk as it imports remote objects into its address space
Client policy
grant {
permission net.jini.discovery.DiscoveryPermission "*";
// multicast request address
permission java.net.SocketPermission "224.0.1.85", "connect,accept";
// multicast announcement address
permission java.net.SocketPermission "224.0.1.84", "connect,accept";
// RMI connections
permission java.net.SocketPermission "127.0.0.1:1024-", "connect,accept";
permission java.net.SocketPermission "*.dstc.edu.au:1024-", "connect,accept";
permission java.net.SocketPermission "130.102.176.249:1024-", "connect,accept";
// DANGER
// HTTP connections - this is where external code may come in - careful!!!
permission java.net.SocketPermission "127.0.0.1:80", "connect,accept";
permission java.net.SocketPermission "*.dstc.edu.au:80", "connect,accept";
// reading parameters
// like net.jini.discovery.debug!
permission java.util.PropertyPermission "net.jini.discovery.*", "read";
};
Running things
Jini classes
The common classes needed by all of reggie, the clients and
servers are
-
jsk-lib.jar
-
jsk-platform.jar
These are not part of standard Java. They must be downloaded
from Sun, and are in the Jini lib
directory.
Jini Lookup Service
The command Launch-All
in the Jini installverify
directory will start the needed support services.
Client
The client needs to have the following classes in its CLASSPATH,
in addition to the Jini classes
-
The
Converter
interface
-
The class
Client
The client can then be run by
java -Djava.security.policy=policy.all Client
Server
The server needs to have the following classes in its CLASSPATH,
in addition to the Jini classes
-
The
Converter
interface
-
The class
Server
-
The class
ConverterImpl
The server can then be run by
java -Djava.rmi.server.codebase=http://hostname/classes \
-Djava.security.policy=policy.all \
Server
Variations
-
If the implementation implements
Serializable
and the implementation itself is advertised, then a
copy of the service is run on the client
-
Same as above, but the copy communicates to a third party service
by e.g. SOAP
URLs
-
Jini: http://www.jini.org
-
Jini FAQ: http://www.artima.com/jini/faq.html
-
Jini tutorial: http://jan.newmarch.name/java/jini/tutorial/Jini.xml
Jan Newmarch (http://jan.newmarch.name)
jan@newmarch.name
Last modified: Mon Oct 2 14:31:53 EST 2006
Copyright ©Jan Newmarch