Download Lab2: Service Registration - CS-UCY

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Sun’s Jini
Lab 2
Service Registration
Client Lookup
Summary




Service Registration
Client lookup
JiniHelloWorld Example
Compiling/running Example
Service Registration

Service provider
–
–
–

Creates the object that implements the service
Registers service object with lookup services
Plays server role to provide the service
Entry
–
–
–
–
Service providers can specify a set of entries for their services
Entries give information about services such as name, provider, location,
description of functionality
Clients can search for services by matching these entries
Jini defines a set of entries but service providers can define their own
entries
Entry[] identityingAttributes = new Entry[1];
identityingAttributes[0] = new Name("HelloWorld");
Service Registration (2)

Registered service manipulated using
ServiceRegistration
public interface ServiceRegistration {
ServiceID getServiceID();
Lease getLease();
void addAttributes(Entry[] attrSets)
throws UnknownLeaseException, RemoteException;
void modifyAttributes(Entry[] attrSetTemplates,
Entry[] attrSets)
throws UnknownLeaseException, RemoteException;
void setAttributes(Entry[] attrSets)
throws UnknownLeaseException, RemoteException;
}
Service Registration
Lookup Service
Service Provider
Service Uploaded
Service
Object
Service
Object
Registrar
Returned
Registrar
Discover a Lookup Service
Client Lookup

Querying the Lookup Service
Matching service: use ServiceTemplate:

public class ServiceTemplate implements Serializable {
public ServiceTemplate(ServiceID serviceID,
Class[] serviceTypes,
Entry[]
attributeSetTemplates) {...}
public ServiceID serviceID;
public Class[] serviceTypes;
public Entry[] attributeSetTemplates;
}


A non-null value must be matched exactly
A null value act as a wild card
Client Lookup
Client
Lookup Service
Service
Service
Object
Returned
Service
Object
Request for a Service
Registrar
Registrar
Returned
Discover a Lookup Service
HelloJini Example –Service Provider
Service Interface
import java.rmi.Remote;
public interface HelloJiniInterface extends Remote{
public String sayHello()
throws RemoteException;
}
Service interface must extend Remote class
All defined methods must throw RemoteException
HelloJini Example –Service Provider(2)
Service Implementation
import java.rmi.server.UnicastRemoteObject;
public class HelloJiniImpl extends UnicastRemoteObject
implements HelloJiniInterface {
public HelloJiniImpl() throws java.rmi.RemoteException {
// empty constructor required by RMI
}
public String sayHello( )
return "Hello Jini";
}
}
throws java.rmi.RemoteException {
HelloJini Example –Service Provider (3)
Service Registration- Multicast
Code: MulticastRegister.java




MulticastRegister inmplements DiscoveryListener because
it uses multicast discovery of lookup service
It also implements LeaseListener in order to be notified
when service registration leasing has been expired
Service provider must produce the rmi proxy of the
HelloJiniImpl.class. (HelloJiniImpl_Stub.class)
Before registering service, the service proxy
(HelloJiniImpl_Stub.class) must be placed on an http
server in order to be available to clients for download.
HelloJini Example – Client



Locate lookup service
Search for HelloJini service
Download proxy and invoke sayHello method
Code: Client.java
Client must have access to HelloJiniInterface.class
in order to find and use the HelloJini service
Compiling/Running JiniExample
Service Provider
Compile service file(s) (service interface, service implementation)
javac
-classpath .;%JINI_HOME%\lib\jini-core.jar;
%JINI_HOME%\lib\jini-ext.jar *.java
Generate rmi proxy (stub) of service using the RMI compiler
rmic –v1.2 HelloJiniImpl
This will create a stub file named HelloJiniImpl_Stub.class
Place needed files to http server


Create a directory e.g hello_jini under the http server root directory
(%JINI_HOME\lib)
Copy service proxy class file to this directory (i.e.
HelloJiniImpl_Stub.class)
Compiling/Running JiniExample(2)
Register service
java
-Djava.security.policy=
%JINI_HOME%\example\lookup\policy.all
-cp .;%JINI_HOME%\lib\jini-core.jar;
%JINI_HOME%\lib\jini-ext.jar
-Djava.rmi.server.codebase=
http://localhost:8081/hello_jini/
MulticastRegister
Compiling/Running JiniExample(3)
Client
Compile
javac
-classpath .;
%JINI_HOME%\lib\jini-core.jar;
%JINI_HOME%\lib\jini-ext.jar;
Client.java
Run
java
-cp .;%JINI_HOME%\lib\jini-core.jar;
%JINI_HOME%\lib\jini-ext.jar;
-Djava.security.policy=%JINI_HOME%\example\lookup\policy.all
Client
Compiling/Running JiniExample(3)





If server and client are running on the same machine place
them at different directories
Client directory must include HelloJiniInterface.class
and Client.class (NOT the stub file)
Service Provider directory must include
HelloInterface.class, HelloJiniImpl.class and
HelloJiniImpl_Stub.class
HelloJiniImpl_Stub.class must be available for
download through the http server
Download JiniExample files from here