Java Code Examples for java.rmi.registry.Registry

The following examples show how to use java.rmi.registry.Registry. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: spring-analysis-note   Source File: RmiServiceExporter.java    License: MIT License 6 votes vote down vote up
/**
 * Locate or create the RMI registry for this exporter.
 * @param registryPort the registry port to use
 * @return the RMI registry
 * @throws RemoteException if the registry couldn't be located or created
 */
protected Registry getRegistry(int registryPort) throws RemoteException {
	if (this.alwaysCreateRegistry) {
		logger.debug("Creating new RMI registry");
		return LocateRegistry.createRegistry(registryPort);
	}
	if (logger.isDebugEnabled()) {
		logger.debug("Looking for RMI registry at port '" + registryPort + "'");
	}
	synchronized (LocateRegistry.class) {
		try {
			// Retrieve existing registry.
			Registry reg = LocateRegistry.getRegistry(registryPort);
			testRegistry(reg);
			return reg;
		}
		catch (RemoteException ex) {
			logger.trace("RMI registry access threw exception", ex);
			logger.debug("Could not detect RMI registry - creating new one");
			// Assume no registry found -> create new one.
			return LocateRegistry.createRegistry(registryPort);
		}
	}
}
 
Example 2
Source Project: jdk8u60   Source File: JstatdTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private Registry startRegistry()
        throws InterruptedException, RemoteException {
    Registry registry = null;
    try {
        System.out.println("Start rmiregistry on port " + port);
        registry = LocateRegistry
                .createRegistry(Integer.parseInt(port));
    } catch (RemoteException e) {
        if (e.getMessage().contains("Port already in use")) {
            System.out.println("Port already in use. Trying to restart with a new one...");
            Thread.sleep(100);
            return null;
        } else {
            throw e;
        }
    }
    return registry;
}
 
Example 3
Source Project: spring4-understanding   Source File: RmiServiceExporter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Locate or create the RMI registry for this exporter.
 * @param registryHost the registry host to use (if this is specified,
 * no implicit creation of a RMI registry will happen)
 * @param registryPort the registry port to use
 * @param clientSocketFactory the RMI client socket factory for the registry (if any)
 * @param serverSocketFactory the RMI server socket factory for the registry (if any)
 * @return the RMI registry
 * @throws RemoteException if the registry couldn't be located or created
 */
protected Registry getRegistry(String registryHost, int registryPort,
		RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory)
		throws RemoteException {

	if (registryHost != null) {
		// Host explicitly specified: only lookup possible.
		if (logger.isInfoEnabled()) {
			logger.info("Looking for RMI registry at port '" + registryPort + "' of host [" + registryHost + "]");
		}
		Registry reg = LocateRegistry.getRegistry(registryHost, registryPort, clientSocketFactory);
		testRegistry(reg);
		return reg;
	}

	else {
		return getRegistry(registryPort, clientSocketFactory, serverSocketFactory);
	}
}
 
Example 4
Source Project: jdk8u_jdk   Source File: TestLibrary.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper method to determine if registry has started
 *
 * @param port The port number to check
 * @param msTimeout The amount of milliseconds to spend checking
 */

public static boolean checkIfRegistryRunning(int port, int msTimeout) {
    long stopTime = System.currentTimeMillis() + msTimeout;
    do {
        try {
            Registry r = LocateRegistry.getRegistry(port);
            String[] s = r.list();
            // no exception. We're now happy that registry is running
            return true;
        } catch (RemoteException e) {
            // problem - not ready ? Try again
            try {
                Thread.sleep(500);
            } catch (InterruptedException ie) {
                // not expected
            }
        }
    } while (stopTime > System.currentTimeMillis());
    return false;
}
 
Example 5
Source Project: JavaTutorial   Source File: RmiServer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param args [0]:绑定端口
 * @throws RemoteException 
 */
public static void main(String[] args) throws RemoteException {
    int port = Integer.parseInt(args[0]);
    UserService userService = new UserServiceImpl();
    Registry registry = createRegistry(port);
    if (null == registry) {
        System.exit(0);
    }
    
    String bindName = "UserService";
    try {
        registry.bind(bindName, userService);
    } catch (AlreadyBoundException e) {
        _logger.info("服务{}已经绑定过", bindName);
    }
    
    _logger.info("RMI Server started, listen port:{}", port);
}
 
Example 6
Source Project: jdk8u-jdk   Source File: JstatdTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private Registry startRegistry()
        throws InterruptedException, RemoteException {
    Registry registry = null;
    try {
        System.out.println("Start rmiregistry on port " + port);
        registry = LocateRegistry
                .createRegistry(Integer.parseInt(port));
    } catch (RemoteException e) {
        if (e.getMessage().contains("Port already in use")) {
            System.out.println("Port already in use. Trying to restart with a new one...");
            Thread.sleep(100);
            return null;
        } else {
            throw e;
        }
    }
    return registry;
}
 
Example 7
public synchronized Channel inheritedChannel() throws IOException {
    System.err.println("SP.inheritedChannel");
    if (channel == null) {
        channel = SocketChannel.open();
        Socket socket = channel.socket();
        System.err.println("socket = " + socket);

        /*
         * Notify test that inherited channel was created.
         */
        try {
            System.err.println("notify test...");
            Registry registry =
                LocateRegistry.getRegistry(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);
            Callback obj = (Callback) registry.lookup("Callback");
            obj.notifyTest();
        } catch (NotBoundException nbe) {
            throw (IOException)
                new IOException("callback object not bound").
                    initCause(nbe);
        }
    }
    return channel;
}
 
Example 8
Source Project: gemfirexd-oss   Source File: Bootstrapper.java    License: Apache License 2.0 6 votes vote down vote up
private static void bootstrap(int port) {
  Log.getLogWriter().info("Starting the bootstrapper.");
  Registry registry = RmiRegistryHelper.startRegistry(RMI_NAME, port);

  // create and register the bootstrapper proxy
  Log.getLogWriter().info("Creating the bootstrapper proxy");
  BootstrapperProxy bootstrapper;
  try {
    bootstrapper = new BootstrapperProxy();
  } catch (RemoteException e) {
    String s = "Bootstrapper proxy could not be created";
    throw new HydraRuntimeException(s, e);
  }
  Log.getLogWriter().info("Registering the bootstrapper proxy");
  RmiRegistryHelper.bind(registry, RMI_NAME, bootstrapper);
  Log.getLogWriter().info("Ready to roll");
}
 
Example 9
Source Project: hottub   Source File: RegistryContext.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the registry at a given host, port and socket factory.
 * If "host" is null, uses default host.
 * If "port" is non-positive, uses default port.
 * If "socketFactory" is null, uses the default socket.
 */
private static Registry getRegistry(String host, int port,
            RMIClientSocketFactory socketFactory)
        throws NamingException
{
    // %%% We could cache registry connections here.  The transport layer
    // may already reuse connections.
    try {
        if (socketFactory == null) {
            return LocateRegistry.getRegistry(host, port);
        } else {
            return LocateRegistry.getRegistry(host, port, socketFactory);
        }
    } catch (RemoteException e) {
        throw (NamingException)wrapRemoteException(e).fillInStackTrace();
    }
}
 
Example 10
public synchronized Channel inheritedChannel() throws IOException {
    System.err.println("SP.inheritedChannel");
    if (channel == null) {
        channel = SocketChannel.open();
        Socket socket = channel.socket();
        System.err.println("socket = " + socket);

        /*
         * Notify test that inherited channel was created.
         */
        try {
            System.err.println("notify test...");
            Registry registry =
                LocateRegistry.getRegistry(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);
            Callback obj = (Callback) registry.lookup("Callback");
            obj.notifyTest();
        } catch (NotBoundException nbe) {
            throw (IOException)
                new IOException("callback object not bound").
                    initCause(nbe);
        }
    }
    return channel;
}
 
Example 11
Source Project: jdk8u-jdk   Source File: ShutdownImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    try {
        int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port"));
        Registry registry =
            LocateRegistry.getRegistry("", registryPort);
        ShutdownMonitor monitor = (ShutdownMonitor)
            registry.lookup(KeepAliveDuringCall.BINDING);
        System.err.println("(ShutdownImpl) retrieved shutdown monitor");

        impl = new ShutdownImpl(monitor);
        Shutdown stub = (Shutdown) UnicastRemoteObject.exportObject(impl);
        System.err.println("(ShutdownImpl) exported shutdown object");

        monitor.submitShutdown(stub);
        System.err.println("(ShutdownImpl) submitted shutdown object");

    } catch (Exception e) {
        System.err.println("(ShutdownImpl) TEST SUBPROCESS FAILURE:");
        e.printStackTrace();
    }
}
 
Example 12
Source Project: TencentKona-8   Source File: ShutdownImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    try {
        int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port"));
        Registry registry =
            LocateRegistry.getRegistry("", registryPort);
        ShutdownMonitor monitor = (ShutdownMonitor)
            registry.lookup(KeepAliveDuringCall.BINDING);
        System.err.println("(ShutdownImpl) retrieved shutdown monitor");

        impl = new ShutdownImpl(monitor);
        Shutdown stub = (Shutdown) UnicastRemoteObject.exportObject(impl);
        System.err.println("(ShutdownImpl) exported shutdown object");

        monitor.submitShutdown(stub);
        System.err.println("(ShutdownImpl) submitted shutdown object");

    } catch (Exception e) {
        System.err.println("(ShutdownImpl) TEST SUBPROCESS FAILURE:");
        e.printStackTrace();
    }
}
 
Example 13
public static void main(String[] args) throws Exception {
    Registry registry = TestLibrary.createRegistryOnUnusedPort();
    int registryPort = TestLibrary.getRegistryPort(registry);
    System.out.println("Connecting to the default Registry...");
    // Connect to the default Registry.
    // Pass null as the JNDI environment properties (see final argument)
    RegistryContext ctx = new RegistryContext(null, registryPort, null);
}
 
Example 14
public static void main(String[] args) throws Exception {
    Registry registry = TestLibrary.createRegistryOnUnusedPort();
    int registryPort = TestLibrary.getRegistryPort(registry);
    Registry reg = LocateRegistry.getRegistry("", registryPort);
    FooImpl fooimpl = new FooImpl();
    UnicastRemoteObject.exportObject(fooimpl, 0);
    reg.rebind("foo", fooimpl);
    Foo foostub = (Foo) reg.lookup("foo");
    FooImpl fooimpl2 = new FooImpl();
    UnicastRemoteObject.exportObject(fooimpl2, 0);
    foostub.echo(fooimpl2);
    UnicastRemoteObject.unexportObject(fooimpl, true);
    UnicastRemoteObject.unexportObject(fooimpl2, true);
}
 
Example 15
Source Project: jdk8u60   Source File: CloseServerSocket.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
        System.err.println("\nRegression test for bug 4457683\n");

        verifyPortFree(PORT);
        Registry registry = LocateRegistry.createRegistry(PORT);
        System.err.println("- exported registry: " + registry);
        verifyPortInUse(PORT);
        UnicastRemoteObject.unexportObject(registry, true);
        System.err.println("- unexported registry");
        Thread.sleep(1000);        // work around BindException (bug?)
        verifyPortFree(PORT);

        /*
         * The follow portion of this test is disabled temporarily
         * because 4457683 was partially backed out because of
         * 6269166; for now, only server sockets originally opened for
         * exports on non-anonymous ports will be closed when all of
         * the corresponding remote objects have been exported.  A
         * separate bug will be filed to represent the remainder of
         * 4457683 for anonymous-port exports.
         */

//      SSF ssf = new SSF();
//      Remote impl = new CloseServerSocket();
//      Remote stub = UnicastRemoteObject.exportObject(impl, 0, null, ssf);
//      System.err.println("- exported object: " + stub);
//      UnicastRemoteObject.unexportObject(impl, true);
//      System.err.println("- unexported object");
//      synchronized (ssf) {
//          if (!ssf.serverSocketClosed) {
//              throw new RuntimeException("TEST FAILED: " +
//                                         "server socket not closed");
//          }
//      }

        System.err.println("TEST PASSED");
    }
 
Example 16
Source Project: jdk8u60   Source File: ReuseDefaultPort.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 6269166\n");
    RMISocketFactory.setSocketFactory(new SF());
    Remote impl = new ReuseDefaultPort();
    Remote stub = UnicastRemoteObject.exportObject(impl, 0);
    System.err.println("- exported object: " + stub);
    try {
        Registry registry = LocateRegistry.createRegistry(PORT);
        System.err.println("- exported registry: " + registry);
        System.err.println("TEST PASSED");
    } finally {
        UnicastRemoteObject.unexportObject(impl, true);
    }
}
 
Example 17
public static void main(String[] args) throws Exception {
    Registry registry = TestLibrary.createRegistryOnUnusedPort();
    int registryPort = TestLibrary.getRegistryPort(registry);
    System.out.println("Connecting to the default Registry...");
    // Connect to the default Registry.
    // Pass null as the JNDI environment properties (see final argument)
    RegistryContext ctx = new RegistryContext(null, registryPort, null);
}
 
Example 18
Source Project: FancyBing   Source File: Gtp.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Gtp(InputStream in, OutputStream out, int port) throws Exception {
	this.in = in;
	this.out = out;
	
	// regist RMI service
       Registry registry = null; 
       registry = LocateRegistry.getRegistry("127.0.0.1", port);
   	game = (IGame) registry.lookup("FancyBing"); 
}
 
Example 19
/**
 * Return a reference to the RMI registry, to make sure that
 * the stub for it can be deserialized in the test client VM.
 */
public Registry getRegistry() throws RemoteException {
    if (sameGroup) {
        System.out.println("in same group");
    } else {
        System.out.println("not in same group");
    }
    return registry;
}
 
Example 20
Source Project: openjdk-8   Source File: LegalRegistryNames.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * return a vector of valid legal RMI naming URLs.
 */
private static Vector getLegalForms() {
    String localHostAddress = null;
    String localHostName = null;

    // get the local host name and address
    try {
        localHostName = InetAddress.getLocalHost().getHostName();
        localHostAddress = InetAddress.getLocalHost().getHostAddress();
    } catch(UnknownHostException e) {
        TestLibrary.bomb("Test failed: unexpected exception", e);
    }

    Vector legalForms = new Vector();
    legalForms.add("///MyName");
    legalForms.add("//:" + Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("//" + localHostAddress + "/MyName");
    legalForms.add("//" + localHostAddress + ":" +
                   Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("//localhost/MyName");
    legalForms.add("//localhost:" + Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("//" + localHostName + "/MyName");
    legalForms.add("//" + localHostName + ":" + Registry.REGISTRY_PORT +
                   "/MyName");
    legalForms.add("MyName");
    legalForms.add("/MyName");
    legalForms.add("rmi:///MyName");
    legalForms.add("rmi://:" + Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("rmi://" + localHostAddress + "/MyName");
    legalForms.add("rmi://" + localHostAddress + ":" +
                   Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("rmi://localhost/MyName");
    legalForms.add("rmi://localhost:" + Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("rmi://" + localHostName + "/MyName");
    legalForms.add("rmi://" + localHostName + ":" +
                   Registry.REGISTRY_PORT + "/MyName");
    return legalForms;
}
 
Example 21
Source Project: openAGV   Source File: RemoteKernelServicePortalProxy.java    License: Apache License 2.0 5 votes vote down vote up
private void updateServiceLogins(Registry registry)
    throws RemoteException, NotBoundException {
  plantModelService
      .setClientId(getClientId())
      .setRemoteService((RemotePlantModelService) registry.lookup(REMOTE_PLANT_MODEL_SERVICE))
      .setServiceListener(this);

  transportOrderService
      .setClientId(getClientId())
      .setRemoteService((RemoteTransportOrderService) registry.lookup(REMOTE_TRANSPORT_ORDER_SERVICE))
      .setServiceListener(this);

  vehicleService
      .setClientId(getClientId())
      .setRemoteService((RemoteVehicleService) registry.lookup(REMOTE_VEHICLE_SERVICE))
      .setServiceListener(this);

  notificationService
      .setClientId(getClientId())
      .setRemoteService((RemoteNotificationService) registry.lookup(REMOTE_NOTIFICATION_SERVICE))
      .setServiceListener(this);

  dispatcherService
      .setClientId(getClientId())
      .setRemoteService((RemoteDispatcherService) registry.lookup(REMOTE_DISPATCHER_SERVICE))
      .setServiceListener(this);

  routerService
      .setClientId(getClientId())
      .setRemoteService((RemoteRouterService) registry.lookup(REMOTE_ROUTER_SERVICE))
      .setServiceListener(this);

  schedulerService
      .setClientId(getClientId())
      .setRemoteService((RemoteSchedulerService) registry.lookup(REMOTE_SCHEDULER_SERVICE))
      .setServiceListener(this);
}
 
Example 22
public static void main(String[] args) throws Exception {
    String[] names = {
        "fairly:simple", "somewhat:more/complicated",
        "multiple:colons:in:name"
    };

    Registry reg = TestLibrary.createRegistryOnUnusedPort();
    int port = TestLibrary.getRegistryPort(reg);

    for (int i = 0; i < names.length; i++) {
        reg.rebind(names[i], reg);
        Naming.lookup("rmi://localhost:" + port + "/" + names[i]);
    }
}
 
Example 23
Source Project: RentLio   Source File: ServerStart.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args){
    System.setProperty("java.rmi.server.hostname","127.0.0.1");
    try {
        if (HibernateUtil.getSessionFactory().isOpen()) {
            Registry registry = LocateRegistry.createRegistry(5050);
            registry.rebind("rentLio", ServicesFactoryImpl.getInstance());

            System.out.println("Server has been started successfully");
        } else {
            JOptionPane.showMessageDialog(null, "sql Saver is not connected", "Error", 1);
        }
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}
 
Example 24
Source Project: jdk8u60   Source File: LookupNameWithColon.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String[] names = {
        "fairly:simple", "somewhat:more/complicated",
        "multiple:colons:in:name"
    };

    Registry reg = TestLibrary.createRegistryOnUnusedPort();
    int port = TestLibrary.getRegistryPort(reg);

    for (int i = 0; i < names.length; i++) {
        reg.rebind(names[i], reg);
        Naming.lookup("rmi://localhost:" + port + "/" + names[i]);
    }
}
 
Example 25
Source Project: hottub   Source File: SelfTerminator.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        int registryPort =
            Integer.parseInt(System.getProperty("rmi.registry.port"));
        Registry registry =
            LocateRegistry.getRegistry("", registryPort);
        Remote stub = registry.lookup(LeaseCheckInterval.BINDING);
        Runtime.getRuntime().halt(0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 26
/**
 * return a vector of valid legal RMI naming URLs.
 */
private static Vector getLegalForms() {
    String localHostAddress = null;
    String localHostName = null;

    // get the local host name and address
    try {
        localHostName = InetAddress.getLocalHost().getHostName();
        localHostAddress = InetAddress.getLocalHost().getHostAddress();
    } catch(UnknownHostException e) {
        TestLibrary.bomb("Test failed: unexpected exception", e);
    }

    Vector legalForms = new Vector();
    legalForms.add("///MyName");
    legalForms.add("//:" + Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("//" + localHostAddress + "/MyName");
    legalForms.add("//" + localHostAddress + ":" +
                   Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("//localhost/MyName");
    legalForms.add("//localhost:" + Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("//" + localHostName + "/MyName");
    legalForms.add("//" + localHostName + ":" + Registry.REGISTRY_PORT +
                   "/MyName");
    legalForms.add("MyName");
    legalForms.add("/MyName");
    legalForms.add("rmi:///MyName");
    legalForms.add("rmi://:" + Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("rmi://" + localHostAddress + "/MyName");
    legalForms.add("rmi://" + localHostAddress + ":" +
                   Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("rmi://localhost/MyName");
    legalForms.add("rmi://localhost:" + Registry.REGISTRY_PORT + "/MyName");
    legalForms.add("rmi://" + localHostName + "/MyName");
    legalForms.add("rmi://" + localHostName + ":" +
                   Registry.REGISTRY_PORT + "/MyName");
    return legalForms;
}
 
Example 27
public static void main(String[] args) throws Exception {
    String[] names = {
        "fairly:simple", "somewhat:more/complicated",
        "multiple:colons:in:name"
    };

    Registry reg = TestLibrary.createRegistryOnUnusedPort();
    int port = TestLibrary.getRegistryPort(reg);

    for (int i = 0; i < names.length; i++) {
        reg.rebind(names[i], reg);
        Naming.lookup("rmi://localhost:" + port + "/" + names[i]);
    }
}
 
Example 28
Source Project: openjdk-jdk9   Source File: JstatdTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void verifyNoRmiRegistryOnDefaultPort() throws Exception {
    try {
        Registry registry = LocateRegistry.getRegistry();
        registry.list();
        throw new Exception("There is already RMI registry on the default port: " + registry);
    } catch (RemoteException e) {
        // No RMI registry on default port is detected
    }
}
 
Example 29
public void doTest() throws Throwable {
    ProcessThread jstatdThread = null;
    try {
        while (jstatdThread == null) {
            if (!useDefaultPort || withExternalRegistry) {
                port = Integer.toString(Utils.getFreePort());
            }

            if (withExternalRegistry) {
                Registry registry = startRegistry();
                if (registry == null) {
                    // The port is already in use. Cancel and try with new one.
                    continue;
                }
            }

            jstatdThread = tryToSetupJstatdProcess();
        }

        runToolsAndVerify();
    } finally {
        cleanUpThread(jstatdThread);
    }

    // Verify output from jstatd
    OutputAnalyzer output = jstatdThread.getOutput();
    assertTrue(output.getOutput().isEmpty(),
            "jstatd should get an empty output, got: "
            + Utils.NEW_LINE + output.getOutput());
    assertNotEquals(output.getExitValue(), 0,
            "jstatd process exited with unexpected exit code");
}
 
Example 30
Source Project: lams   Source File: RmiRegistryFactoryBean.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate or create the RMI registry.
 * @param registryPort the registry port to use
 * @param clientSocketFactory the RMI client socket factory for the registry (if any)
 * @param serverSocketFactory the RMI server socket factory for the registry (if any)
 * @return the RMI registry
 * @throws RemoteException if the registry couldn't be located or created
 */
protected Registry getRegistry(
		int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory)
		throws RemoteException {

	if (clientSocketFactory != null) {
		if (this.alwaysCreate) {
			logger.info("Creating new RMI registry");
			this.created = true;
			return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory);
		}
		if (logger.isInfoEnabled()) {
			logger.info("Looking for RMI registry at port '" + registryPort + "', using custom socket factory");
		}
		synchronized (LocateRegistry.class) {
			try {
				// Retrieve existing registry.
				Registry reg = LocateRegistry.getRegistry(null, registryPort, clientSocketFactory);
				testRegistry(reg);
				return reg;
			}
			catch (RemoteException ex) {
				logger.debug("RMI registry access threw exception", ex);
				logger.info("Could not detect RMI registry - creating new one");
				// Assume no registry found -> create new one.
				this.created = true;
				return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory);
			}
		}
	}

	else {
		return getRegistry(registryPort);
	}
}