Exemple #1
0
 /**
  * Return the JVM-level configured {@code RMISocketFactory}.
  *
  * <p>If a global socket factory has been set via the {@link
  * RMISocketFactory#setSocketFactory(RMISocketFactory)} method then that factory will be returned.
  * Otherwise the default socket factory as returned by {@link
  * RMISocketFactory#getDefaultSocketFactory()} is used instead.
  *
  * @return the configured @{code {@link RMISocketFactory}
  */
 public static RMISocketFactory getConfiguredRMISocketFactory() {
   RMISocketFactory globalSocketFactory = RMISocketFactory.getSocketFactory();
   if (globalSocketFactory == null) {
     return RMISocketFactory.getDefaultSocketFactory();
   } else {
     return globalSocketFactory;
   }
 }
  static {
    /* Add a custom socket factory to add a connect timeout */
    if (CentralPAPropertyRepository.PA_RMI_CONNECT_TIMEOUT.isSet()) {
      try {
        RMISocketFactory.setSocketFactory(
            new RMISocketFactory() {
              public Socket createSocket(String host, int port) throws IOException {
                Socket socket = new Socket();
                socket.connect(
                    new InetSocketAddress(host, port),
                    CentralPAPropertyRepository.PA_RMI_CONNECT_TIMEOUT.getValue());
                return socket;
              }

              public ServerSocket createServerSocket(int port) throws IOException {
                return new ServerSocket(port);
              }
            });
      } catch (IOException e) {
        LOGGER_RO.warn(
            "Failed to register a RMI socket factory supporting Connect timeout. The default one will be used",
            e);
        e.printStackTrace();
      }
    }

    createClassServer();
    createRegistry();
  }
 public static void main(String[] args) {
   if (System.getSecurityManager() == null) {
     System.setSecurityManager(new SecurityManager());
   }
   try {
     String name = "Compute";
     Compute engine = new ComputeEngine();
     RMISocketFactory.setSocketFactory(new FixedPortRMISocketFactory());
     Compute stub = (Compute) UnicastRemoteObject.exportObject(engine, 0);
     Registry registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
     registry.rebind(name, stub);
     System.out.println("ComputeEngine bound");
   } catch (Exception e) {
     System.err.println("ComputeEngine exception:");
     e.printStackTrace();
   }
 }
public RegistryImpl(int port) throws RemoteException {
	this(port, RMISocketFactory.getSocketFactory(), RMISocketFactory.getSocketFactory());
}