package org.saf.remote;
import java.net.InetAddress;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import org.apache.log4j.Logger;
public abstract class RemoteServer extends UnicastRemoteObject implements
RemoteInterface {
protected static final Logger logger =
Logger.getLogger(RemoteServer.class);
private final static long serialVersionUID = 15l;
private int port = 0;
protected RemoteServer(int port) throws RemoteException {
this.port = port;
}
public void start() throws RemoteException {
String address;
if(this.port > 0) {
Registry registry;
try {
address = (InetAddress.getLocalHost()).toString();
}
catch(Exception e) {
throw new RemoteException("can't get inet address.");
}
logger.info("this address = " + address + ", port = " + this.port);
registry = LocateRegistry.createRegistry(this.port);
registry.rebind("RemoteServer", this);
} else {
logger.fatal("no starting remote server cause no port definition.");
}
}
}