Jini and Network-Enabled Devices
by Hinkmond Wong


Example 1:
(a)
rmid &

(b) 
rmiregistry &

(c)
java -jar <jinidir>/jini1_0/lib/tools.jar -port 8080 -dir <jinidir>/jini1_0/lib &

(d)
java -jar -Djava.security.policy=<jinidir>/jini1_0/example/lookup/policy.all <jinidir>/jini1_0/lib/reggie.jar  http://<host>:8080/reggie-dl.jar <jinidir>/jini1_0/example/lookup/policy.all /tmp/reggie_log

(e)
java -cp .:<jinidir>/jini1_0/lib/sun-util.jar:<jinidir>/jini1_0/lib/reggie.jar:<jinidir>/jini1_0/lib/mahalo.jar:<jinidir>/jini1_0/lib/jini.jar -Djava.rmi.server.codebase=http://<host>/<srcdir>/PrintService/ -Djava.security.policy=<srcdir>/PrintService/po.p
olicy Print

(f)
java -cp .:<jinidir>/jini1_0/lib/sun-util.jar:<jinidir>/jini1_0/lib/reggie.jar:<jinidir>/jini1_0/lib/mahalo.jar:<jinidir>/jini1_0/lib/jini.jar -Djava.rmi.server.codebase=http://<host>/<srcdir>/PrintService -Djava.security.policy=<srcdir>/PrintService/po.po
licy JiniPrintProxy 

(g)
java -cp .:<jinidir>/jini1_0/lib/sun-util.jar:<jinidir>/jini1_0/lib/reggie.jar:<jinidir>/jini1_0/lib/mahalo.jar:<jinidir>/jini1_0/lib/jini.jar -Djava.rmi.server.codebase=http://<host>/<srcdir>/PrintService -Djava.security.policy=<srcdir>/PrintService/po.po
licy JiniPrintProxy 

Example 2:

(a)
import java.rmi.RemoteException;
import java.rmi.Remote;
public interface PrintRemote extends Remote {
    String print(String printerName, String fileName) 
    throws RemoteException;
    String checkQueue(String printerName) 
    throws RemoteException;
}

(b)
javac PrintRemote.java

    
(c)
rmic PrintRemote


Listing One
import jini.net.JoinManager;
 ...
// PrintService extends UnicastRemoteObject and implements //   PrintRemote, Serializable
PrintService service = new PrintService(); 
ServiceInfo serviceInfo = new ServiceInfo(PRODUCT, MANUFACTURER, 
VENDOR, VERSION, "","");
BasicServiceType basicServiceType = new BasicServiceType("PrintService"); entry = new Entry[] {serviceInfo, basicServiceType};
try {
joinManager = new JoinManager(service, entry, new
ServiceIDHandler(), new LeaseRenewalManager());
} catch (java.io.IOException ioe) { } Listing Two
public PrintRemote getPrintService() { Socket          socket;
InputStream     inputStream;
ObjectInputStream   objInStream;
try {

// Open the socket for the ObjectInputStream socket = new Socket("<host>", PrintRemote.SOCKET); inputStream = socket.getInputStream();
objInStream = new ObjectInputStream(inputStream);

// Read the PrintRemote object from the server service = (PrintRemote) objInStream.readObject();

// Close the socket
socket.close();

} catch (Exception e) {
e.printStackTrace();
}
return(service);
}

Listing Three
public String printToJiniService(String printerName, String fileName) { String retStr = null;

if (service == null) {
// Get the PrintRemote object from the server service = getPrintService();
}
try {
retStr = service.print(printerName, fileName);
} catch (Exception e) {
e.printStackTrace();
}
return(retStr);
}






