This code imports a ping server owned by a process running in the
machine myhost which listens to requests on port 2001.
String urladdr= "http://myhost:2001/pingServer";
PingServer server= (PingServer)Manager.lookup(url);
String text= server.ping();
where NetInterface is a network interface supported by the network object and url is a url address taking the form:
The interface must extends the interface NetObj:
All the methods must throw NetException.
public interface PingServer extends NetObj {
public String ping() throws NetException;
}
public class ConcretePingServer
extends ConcreteNetObj
implements PingServer {
public String ping() throws NetException {
return "Hello World!";
}
}
ConcretePingServer server= new ConcretePingServer();
Manager.bind("pingServer", server);
The general form for exporting a network object is:
import netobj.*;
class Manager {
public static void bind(String objname, NetObj netObj)
throws NetException;
public static NetObj lookup(String urladdr)
throws MalformedURLException, NetException,
UnknownHostException;
public static void setSocketPort(int port);
}
The factory runs on myhost and builds ping servers running also
on myhost.
String url= "http://myhost:2001/pingServerFactory";
factory= (Factory)Manager.lookup(url);
PingServer server1= factory.makePingServer();
PingServer server2= factory.makePingServer();
A remote invocation can return a network reference.
public interface Factory extends NetObj {
public PingServer makePingServer() throws NetException;
}
makePingServer cannot return a ConcretePingServer.
public class ConcreteFactory extends ConcreteNetObj
implements Factory {
public PingServer makePingServer() throws NetException {
return new ConcretePingServer();
}
}
ConcreteFactory factory= new ConcreteFactory();
Manager.bind("pingServerFactory", factory);