java.rmi.registry.LocateRegistry Java Examples

The following examples show how to use java.rmi.registry.LocateRegistry. 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 check out the related API usage on the sidebar.
Example #1
Source File: InheritedChannelNotServerSocket.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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 #2
Source File: RmiServiceExporter.java    From spring-analysis-note with 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 #3
Source File: RmiServiceExporter.java    From java-technology-stack with 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 #4
Source File: RegistryContext.java    From dragonwell8_jdk with 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 #5
Source File: InheritedChannelNotServerSocket.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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 #6
Source File: RmiRegistryFactoryBean.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Locate or create the RMI registry.
 * @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.alwaysCreate) {
		logger.debug("Creating new RMI registry");
		this.created = true;
		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.
			this.created = true;
			return LocateRegistry.createRegistry(registryPort);
		}
	}
}
 
Example #7
Source File: PolicyNetService.java    From FancyBing with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
	Nd4j.getMemoryManager().setAutoGcWindow(2000);
	CudaEnvironment.getInstance().getConfiguration()
		.setMaximumDeviceCacheableLength(1024 * 1024 * 1024L)
		.setMaximumDeviceCache(2L * 1024 * 1024 * 1024L)
		.setMaximumHostCacheableLength(1024 * 1024 * 1024L)
		.setMaximumHostCache(8L * 1024 * 1024 * 1024L);
	
	// Register services, bind services in multi ports for better performance
	Registry registry = null;
	for (int i = 0; i < Global.NETWORK_THREADS_NUM; i++) {
		try {
			registry = LocateRegistry.createRegistry(Global.POLICYNET_RMI_PORT + i);
			PolicyNetService policyNet = new PolicyNetService();
			registry.rebind(Global.NAME + "Policy", policyNet);
			
			System.out.println("Bind FancyBingPolicy server on " + (Global.POLICYNET_RMI_PORT + i));
			System.out.println("FancyBingPolicy server started.");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
Example #8
Source File: JstatdTest.java    From openjdk-jdk8u with 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 #9
Source File: RmiRegistryFactoryBean.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Locate or create the RMI registry.
 * @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.alwaysCreate) {
		logger.debug("Creating new RMI registry");
		this.created = true;
		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.
			this.created = true;
			return LocateRegistry.createRegistry(registryPort);
		}
	}
}
 
Example #10
Source File: RMIRegistries.java    From openAGV with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a reference to a working registry on the given host and port, if there is one.
 *
 * @param host The host to check.
 * @param port The port to check.
 * @return A reference to a working registry on the given host and port, if a
 * working one was found there.
 */
public Optional<Registry> lookupRegistry(String host, int port) {
  Registry registry;
  LOG.debug("Checking for working RMI registry on {}:{}", host, port);
  try {
    registry = LocateRegistry.getRegistry(host,
                                          port,
                                          socketFactoryProvider.getClientSocketFactory());
    String[] boundNames = registry.list();
  }
  catch (RemoteException exc) {
    LOG.debug("RMI registry on {}:{} unavailable", host, port);
    return Optional.empty();
  }
  return Optional.of(registry);
}
 
Example #11
Source File: RegistryContext.java    From jdk8u60 with 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 #12
Source File: RmiRegistryFactoryBean.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Locate or create the RMI registry.
 * @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 java.rmi.RemoteException if the registry couldn't be located or created
 */
protected Registry getRegistry(String registryHost, int registryPort,
		@Nullable RMIClientSocketFactory clientSocketFactory, @Nullable RMIServerSocketFactory serverSocketFactory)
		throws RemoteException {

	if (registryHost != null) {
		// Host explicitly specified: only lookup possible.
		if (logger.isDebugEnabled()) {
			logger.debug("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 #13
Source File: RmiServiceExporter.java    From java-technology-stack with MIT License 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,
		@Nullable RMIClientSocketFactory clientSocketFactory, @Nullable RMIServerSocketFactory serverSocketFactory)
		throws RemoteException {

	if (registryHost != null) {
		// Host explicitly specified: only lookup possible.
		if (logger.isDebugEnabled()) {
			logger.debug("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 #14
Source File: RMIConnectorLogAttributesTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private JMXConnectorServer startServer(int rmiPort) throws Exception {
    System.out.println("DEBUG: Create RMI registry on port " + rmiPort);
    LocateRegistry.createRegistry(rmiPort);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

    HashMap<String,Object> env = new HashMap<String,Object>();

    JMXServiceURL url =
            new JMXServiceURL("service:jmx:rmi:///jndi/rmi://127.0.0.1:" + rmiPort + "/jmxrmi");
    JMXConnectorServer cs =
            JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);

    cs.start();
    System.out.println("DEBUG: Started the RMI connector server");
    return cs;
}
 
Example #15
Source File: TestLibrary.java    From jdk8u60 with 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 #16
Source File: AddrInUse.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public void run() {

        /*
         * Attempt to create (i.e. export) a registry on the port that
         * has already been bound, and record the result.
         */
        try {
            LocateRegistry.createRegistry(port);
            synchronized (this) {
                exportSucceeded = true;
                notifyAll();
            }
        } catch (Throwable t) {
            synchronized (this) {
                exportException = t;
                notifyAll();
            }
        }
    }
 
Example #17
Source File: RegistryContext.java    From TencentKona-8 with 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 #18
Source File: InheritedChannelNotServerSocket.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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 #19
Source File: RMIConnectorLogAttributesTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private JMXConnectorServer startServer(int rmiPort) throws Exception {
    System.out.println("DEBUG: Create RMI registry on port " + rmiPort);
    LocateRegistry.createRegistry(rmiPort);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

    HashMap<String,Object> env = new HashMap<String,Object>();

    JMXServiceURL url =
            new JMXServiceURL("service:jmx:rmi:///jndi/rmi://127.0.0.1:" + rmiPort + "/jmxrmi");
    JMXConnectorServer cs =
            JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);

    cs.start();
    System.out.println("DEBUG: Started the RMI connector server");
    return cs;
}
 
Example #20
Source File: TestLibrary.java    From openjdk-jdk8u with 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 #21
Source File: ShutdownImpl.java    From TencentKona-8 with 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 #22
Source File: AddrInUse.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void run() {

        /*
         * Attempt to create (i.e. export) a registry on the port that
         * has already been bound, and record the result.
         */
        try {
            LocateRegistry.createRegistry(port);
            synchronized (this) {
                exportSucceeded = true;
                notifyAll();
            }
        } catch (Throwable t) {
            synchronized (this) {
                exportException = t;
                notifyAll();
            }
        }
    }
 
Example #23
Source File: TestLibrary.java    From TencentKona-8 with 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 #24
Source File: AddrInUse.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public void run() {

        /*
         * Attempt to create (i.e. export) a registry on the port that
         * has already been bound, and record the result.
         */
        try {
            LocateRegistry.createRegistry(port);
            synchronized (this) {
                exportSucceeded = true;
                notifyAll();
            }
        } catch (Throwable t) {
            synchronized (this) {
                exportException = t;
                notifyAll();
            }
        }
    }
 
Example #25
Source File: ShutdownImpl.java    From jdk8u60 with 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 #26
Source File: InheritedChannelNotServerSocket.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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 #27
Source File: NoConsoleOutput.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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 #28
Source File: RmidViaInheritedChannel.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public synchronized Channel inheritedChannel() throws IOException {
    System.err.println("RmidSelectorProvider.inheritedChannel");
    if (channel == null) {
        /*
         * Create server socket channel and bind server socket.
         */
        channel = ServerSocketChannel.open();
        ServerSocket serverSocket = channel.socket();
        serverSocket.bind(
             new InetSocketAddress(InetAddress.getLocalHost(),
             TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));
        System.err.println("serverSocket = " + serverSocket);

        /*
         * Notify test that inherited channel was created.
         */
        try {
            System.err.println("notify test...");
            Registry registry =
                LocateRegistry.getRegistry(TestLibrary.RMIDVIAINHERITEDCHANNEL_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 #29
Source File: readTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    try {
        testPkg.Server obj = new testPkg.Server();
        testPkg.Hello stub = (testPkg.Hello) UnicastRemoteObject.exportObject(obj, 0);
        // Bind the remote object's stub in the registry
        Registry registry =
            LocateRegistry.getRegistry(TestLibrary.READTEST_REGISTRY_PORT);
        registry.bind("Hello", stub);

        System.err.println("Server ready");

        // now, let's test client
        testPkg.Client client =
            new testPkg.Client(TestLibrary.READTEST_REGISTRY_PORT);
        String testStubReturn = client.testStub();
        if(!testStubReturn.equals(obj.hello)) {
            throw new RuntimeException("Test Fails : unexpected string from stub call");
        } else {
            System.out.println("Test passed");
        }
        registry.unbind("Hello");

    } catch (Exception e) {
        System.err.println("Server exception: " + e.toString());
        e.printStackTrace();
    }

}
 
Example #30
Source File: RmidViaInheritedChannel.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public synchronized Channel inheritedChannel() throws IOException {
    System.err.println("RmidSelectorProvider.inheritedChannel");
    if (channel == null) {
        /*
         * Create server socket channel and bind server socket.
         */
        channel = ServerSocketChannel.open();
        ServerSocket serverSocket = channel.socket();
        serverSocket.bind(
             new InetSocketAddress(InetAddress.getLocalHost(),
             TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));
        System.err.println("serverSocket = " + serverSocket);

        /*
         * Notify test that inherited channel was created.
         */
        try {
            System.err.println("notify test...");
            Registry registry =
                LocateRegistry.getRegistry(TestLibrary.RMIDVIAINHERITEDCHANNEL_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;
}