Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sun’s Jini Lab 2 Service Registration Client Lookup.

Similar presentations


Presentation on theme: "Sun’s Jini Lab 2 Service Registration Client Lookup."— Presentation transcript:

1 Sun’s Jini Lab 2 Service Registration Client Lookup

2 Summary Service Registration Client lookup JiniHelloWorld Example Compiling/running Example

3 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");

4 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; }

5 Service Registration Lookup ServiceService Provider Service Object Registrar Service Object Service Uploaded Discover a Lookup Service Registrar Returned

6 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

7 Client Lookup ClientLookup Service Service Object Discover a Lookup Service Registrar Returned Request for a Service Service Object Service Returned

8 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

9 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( ) throws java.rmi.RemoteException { return "Hello Jini"; } }

10 HelloJini Example –Service Provider (3) Service Registration- Multicast Code: MulticastRegister.javaMulticastRegister.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.

11 HelloJini Example – Client Locate lookup service Search for HelloJini service Download proxy and invoke sayHello method Code: Client.javaClient.java Client must have access to HelloJiniInterface.class in order to find and use the HelloJini service

12 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)

13 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

14 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

15 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 herehere


Download ppt "Sun’s Jini Lab 2 Service Registration Client Lookup."

Similar presentations


Ads by Google