Developing
A Simple Jini Service
Gopalan Suresh Raj
Note |
To
work with any of these samples, you will need the
following: .........................................The Java 2 compiler and API - JDK 1.2 .........................................The Jini 1.x System Software |
This simple Jini service returns the current time in milliseconds when it's getTime() method in invoked.
The Steps involved in developing a Jini Service are
1. Code the Jini Service Interface
2. Code the Jini Service
3. Compile the Code and generate stubs
4. Start up the Service
1. Code the Jini Service Interface
MyServerInterface.java |
import
java.rmi.*; /***************************************************************************
public interface MyServerInterface
extends Remote { |
2. Code the Jini Service
MyServer.java |
import
net.jini.core.entry.*; import net.jini.core.lookup.*; import net.jini.core.discovery.*; import net.jini.lookup.entry.*; import net.jini.discovery.*; import com.sun.jini.lookup.*; import com.sun.jini.lease.*; import java.io.*; /*************************************************************************** MyServer -- The Jini Server Class ***************************************************************************/ public class MyServer
extends UnicastRemoteObject public
MyServer() throws RemoteException { super (); } public
long getTime() throws RemoteException { //
MyServiceInterface public
void serviceIDNotify (ServiceID serviceId) { } //
ServiceIDListener public static
void main (String[] args) { try { /* /* /* /* matches
= registrar.lookup(new ServiceTemplate (null, null,
null),50);
|
3. Compile the code and generate the RMI Stubs
H:\jini\TimeServer> H:\jini\TimeServer>set CLASSPATH=.;G:\sun\jini\jini1_0\lib\jini-core.jar;G:\sun\jini\jini1_0\lib\jini-ext.jar; G:\sun\jini\jini1_0\lib\mahalo.jar;G:\sun\jini\jini1_0\lib\mahalo-dl.jar; G:\sun\jini\jini1_0\lib\reggie.jar;G:\sun\jini\jini1_0\lib\reggie-dl.jar;G:\sun\jini\jini1_0\lib\sun-util.jar; G:\sun\jini\jini1_0\lib\tools.jar;%CLASSPATH% H:\jini\TimeServer>javac *.java H:\jini\TimeServer>rmic MyServer H:\jini\TimeServer> |
4. Startup the Jini Service
H:\jini\TimeServer>start java -jar
G:\sun\jini\jini1_0\lib\tools.jar -port 8080 -dir
G:\sun\jini\jini1_0\lib -verbose H:\jini\TimeServer>start rmid H:\jini\TimeServer>java -jar -Djava.security.policy=H:\jini\TimeServer\policy.all G:/sun/jini/jini1_0/lib/reggie.jar http://localhost:8080/reggie-dl.jar H:\jini\TimeServer\policy.all /reggie_log public using absolute dbdir path: H:\reggie_log H:\jini\TimeServer>java -Djava.security.policy=H:\jini\TimeServer\policy.all -Djava.rmi.server.codebase=http://localhost/ MyServer MyServer: JoinManager = com.sun.jini.lookup.JoinManager@1bfdd4c7 MyServer: LookupLocator = jini://localhost/ MyServer: LookupLocator.host = localhost MyServer: LookupLocator.port = 4160 MyServer: ServiceRegistrar = com.sun.jini.reggie.RegistrarProxy@2cd27317 MyServer: ServiceID = 88fc7d88-8ea6-4db9-9cac-ddeab6249ecc MyServer: ServiceMatches = net.jini.core.lookup.ServiceMatches@5f01d4c7 MyServer: num matches = 4 MyServer: svc item 0: net.jini.core.lookup.ServiceItem@4b5d4c7 MyServer: svc object 0: MyServer_Stub[RemoteStub [ref: [endpoint:[130.151.69.105:3924](remote),objID:[4c91d33d:d5fe eb8b2d:-8000, 0]]]] MyServer: svc item 1: net.jini.core.lookup.ServiceItem@7f49d4c7 MyServer: svc object 1: com.sun.jini.reggie.RegistrarProxy@2cd27317 MyServer: svc item 2: net.jini.core.lookup.ServiceItem@70a1d4c7 MyServer: svc object 2: MyServer_Stub[RemoteStub [ref: [endpoint:[130.151.69.105:3859](remote),objID:[4c91d3c4:d5fe e8b522:-8000, 0]]]] MyServer: svc item 3: net.jini.core.lookup.ServiceItem@6d19d4c7 MyServer: svc object 3: MyServer_Stub[RemoteStub [ref: [endpoint:[130.151.69.105:3980](remote),objID:[0]]]] *-----------------------------------------* ==================================================== MyServer: The method getTime() in MyServer was called MyServer: Time at server is 919104970506 msecs ==================================================== ==================================================== MyServer: The method getTime() in MyServer was called MyServer: Time at server is 919105007119 msecs ==================================================== ==================================================== MyServer: The method getTime() in MyServer was called MyServer: Time at server is 919105010724 msecs ==================================================== ==================================================== MyServer: The method getTime() in MyServer was called MyServer: Time at server is 919105014360 msecs ==================================================== ==================================================== MyServer: The method getTime() in MyServer was called MyServer: Time at server is 919105017744 msecs ==================================================== ==================================================== MyServer: The method getTime() in MyServer was called MyServer: Time at server is 919105021370 msecs ==================================================== ==================================================== MyServer: The method getTime() in MyServer was called MyServer: Time at server is 919105024785 msecs ==================================================== |
click here to go
to the Developing a Simple Jini Client Page... |
click here to go to My Jini HomePage... |
This site was developed and is maintained by Gopalan Suresh Raj This page has been visited times since February 12,1999. |
Last Updated : Feb 12, '99 |
Copyright (c) 1997-99, Gopalan Suresh Raj - All rights reserved. Terms of use. |
All products and companies mentioned at this site,are trademarks of their respective owners. |