package info.walnutstreet.vs.ps05vt;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import net.jini.core.discovery.LookupLocator;
import net.jini.core.entry.Entry;
import net.jini.core.lease.Lease;
import net.jini.core.lookup.ServiceItem;
import net.jini.core.lookup.ServiceRegistrar;
import net.jini.lookup.entry.Name;
import net.jini.lookup.entry.ServiceInfo;
public class RoomLightNeon extends UnicastRemoteObject implements RoomLight {
/**
*
*/
private static final long serialVersionUID = -5254055472721882155L;
private boolean on;
public RoomLightNeon () throws RemoteException {
super ();
this.on = false;
}
public String sayHello () throws RemoteException { // MyServiceInterface
System.out.println ("server: The method sayHello() in MyService was " + "called");
return ("Hello World from MyService!");
}
public static void main (String[] args) {
RoomLight myServer;
LookupLocator lookup;
ServiceRegistrar registrar;
ServiceItem serviceItem;
try {
/* Set the security manager to allow the RMI class loader
to go to the codebase for classes that are not available
locally. */
System.setSecurityManager (new RMISecurityManager ());
/* Create the attributes (an array of entry objects) that describe this
server and use it to register this server with the lookup service.
JoinManager finds and registers with the lookup service */
Entry[] attr = new Entry[2];
attr[0] = new Name("Neon Light");
attr[1] = new ServiceInfo("Name", "Manufactor", "vendor","version","model","serial");
myServer = new RoomLightNeon ();
serviceItem = new ServiceItem(null, myServer, attr);
lookup = new LookupLocator ("jini://localhost");
registrar = lookup.getRegistrar();
registrar.register(serviceItem, Lease.FOREVER);
System.out.println("Serrrrrrrrrrvice Ready ...");
} catch (Exception e)
{
System.out.println("server: MyService.main(): Exception " + e);
}
}
@Override
public boolean isOn() throws RemoteException {
return this.on;
}
@Override
public void switchOff() throws RemoteException {
this.on = false;
}
@Override
public void switchOn() throws RemoteException {
this.on = true;
}
@Override
public boolean toggle() throws RemoteException {
if (this.isOn())
this.switchOff();
else
this.switchOn();
return true;
}
}