Package org.saf.remote

Source Code of org.saf.remote.RemoteServer

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.");
    }
  }
}
TOP

Related Classes of org.saf.remote.RemoteServer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.