Search in sources :

Example 86 with Registry

use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.

the class UnderscoreHost method main.

public static void main(String[] args) {
    UnderscoreHost t = null;
    try {
        HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory();
        RMISocketFactory.setSocketFactory(hvf);
        Registry r = TestLibrary.createRegistryOnUnusedPort();
        int port = TestLibrary.getRegistryPort(r);
        t = new UnderscoreHost();
        r.rebind(NAME, t);
        Naming.lookup("rmi://" + HOSTNAME + ":" + port + "/" + NAME);
        /*
             * This test is coded to pass whether java.net.URI obeys
             * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.).
             *
             * If java.net.URI obeys RFC 3986, so host names may
             * contain underscores, then the Naming.lookup invocation
             * should succeed-- but the host actually connected to
             * must equal HOSTNAME.
             */
        if (!hvf.host.equals(HOSTNAME)) {
            throw new RuntimeException("java.rmi.Naming Parsing error:" + hvf.host + ":" + HOSTNAME);
        }
    } catch (MalformedURLException e) {
    /*
             * If java.net.URI obeys RFC 2396, so host names must not
             * contain underscores, then the Naming.lookup invocation
             * should throw MalformedURLException-- so this is OK.
             */
    } catch (IOException ioe) {
        TestLibrary.bomb(ioe);
    } catch (java.rmi.NotBoundException nbe) {
        TestLibrary.bomb(nbe);
    } finally {
        TestLibrary.unexport(t);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) IOException(java.io.IOException)

Example 87 with Registry

use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.

the class DefaultRegistryPort method main.

public static void main(String[] args) {
    Registry registry = null;
    try {
        System.err.println("Starting registry on default port REGISTRY_PORT=" + Registry.REGISTRY_PORT);
        registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
        System.err.println("Created registry=" + registry);
    } catch (java.rmi.RemoteException e) {
        try {
            System.err.println("Failed to create a registry, try using existing one");
            registry = LocateRegistry.getRegistry();
            System.err.println("Found registry=" + registry);
        } catch (Exception ge) {
            TestLibrary.bomb("Test Failed: cound not find or create a registry");
        }
    }
    try {
        if (registry != null) {
            registry.rebind("myself", registry);
            Remote myself = Naming.lookup("rmi://localhost/myself");
            System.err.println("Test PASSED");
        } else {
            TestLibrary.bomb("Test Failed: cound not find or create a registry");
        }
    } catch (java.rmi.NotBoundException e) {
        TestLibrary.bomb("Test Failed: could not find myself");
    } catch (Exception e) {
        e.printStackTrace();
        TestLibrary.bomb("Test failed: unexpected exception");
    }
}
Also used : Remote(java.rmi.Remote) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry)

Example 88 with Registry

use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.

the class ApplicationServer method run.

/*
     * On initialization, export remote objects and register
     * them with server.
     */
public void run() {
    try {
        int i = 0;
        /*
             * Locate apple user object in registry.  The lookup will
             * occur until it is successful or fails LOOKUP_ATTEMPTS times.
             * These repeated attempts allow the ApplicationServer
             * to be started before the AppleUserImpl.
             */
        Exception exc = null;
        for (i = 0; i < LOOKUP_ATTEMPTS; i++) {
            try {
                Registry registry = LocateRegistry.getRegistry(registryHost, registryPort);
                user = (AppleUser) registry.lookup("AppleUser");
                user.startTest();
                //successfully obtained AppleUser
                break;
            } catch (Exception e) {
                exc = e;
                //sleep 10 seconds and try again
                Thread.sleep(10000);
            }
        }
        if (user == null) {
            logger.log(Level.SEVERE, "Failed to lookup AppleUser:", exc);
            return;
        }
        /*
             * Create and export apple implementations.
             */
        try {
            for (i = 0; i < numApples; i++) {
                apples[i] = new AppleImpl("AppleImpl #" + (i + 1));
            }
        } catch (RemoteException e) {
            logger.log(Level.SEVERE, "Failed to create AppleImpl #" + (i + 1) + ":", e);
            user.reportException(e);
            return;
        }
        /*
             * Hand apple objects to apple user.
             */
        try {
            for (i = 0; i < numApples; i++) {
                user.useApple(apples[i]);
            }
        } catch (RemoteException e) {
            logger.log(Level.SEVERE, "Failed to register callbacks for " + apples[i] + ":", e);
            user.reportException(e);
            return;
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Unexpected exception:", e);
    }
}
Also used : LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) RemoteException(java.rmi.RemoteException) RemoteException(java.rmi.RemoteException)

Example 89 with Registry

use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.

the class HandshakeFailure method main.

public static void main(String[] args) throws Exception {
    /*
         * Listen on port...
         */
    ServerSocket serverSocket = new ServerSocket(PORT);
    /*
         * (Attempt RMI call to port in separate thread.)
         */
    Registry registry = LocateRegistry.getRegistry(PORT);
    Connector connector = new Connector(registry);
    Thread t = new Thread(connector);
    t.setDaemon(true);
    t.start();
    /*
         * ...accept one connection from port and send non-JRMP data.
         */
    Socket socket = serverSocket.accept();
    socket.getOutputStream().write("Wrong way".getBytes());
    socket.close();
    /*
         * Wait for call attempt to finish, and analyze result.
         */
    t.join(TIMEOUT);
    synchronized (connector) {
        if (connector.success) {
            throw new RuntimeException("TEST FAILED: remote call succeeded??");
        }
        if (connector.exception == null) {
            throw new RuntimeException("TEST FAILED: remote call did not time out");
        } else {
            System.err.println("remote call failed with exception:");
            connector.exception.printStackTrace();
            System.err.println();
            if (connector.exception instanceof MarshalException) {
                System.err.println("TEST FAILED: MarshalException thrown, expecting " + "java.rmi.ConnectException or ConnectIOException");
            } else if (connector.exception instanceof ConnectException || connector.exception instanceof ConnectIOException) {
                System.err.println("TEST PASSED: java.rmi.ConnectException or " + "ConnectIOException thrown");
            } else {
                throw new RuntimeException("TEST FAILED: unexpected Exception thrown", connector.exception);
            }
        }
    }
}
Also used : MarshalException(java.rmi.MarshalException) ConnectIOException(java.rmi.ConnectIOException) ServerSocket(java.net.ServerSocket) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) ConnectException(java.rmi.ConnectException)

Example 90 with Registry

use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.

the class CloseServerSocket method main.

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");
    // work around BindException (bug?)
    Thread.sleep(1000);
    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");
}
Also used : LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry)

Aggregations

Registry (java.rmi.registry.Registry)128 LocateRegistry (java.rmi.registry.LocateRegistry)119 RemoteException (java.rmi.RemoteException)43 IOException (java.io.IOException)20 Remote (java.rmi.Remote)16 NodeRegisterRMIStub (org.mobicents.tools.sip.balancer.NodeRegisterRMIStub)14 UnknownHostException (java.net.UnknownHostException)13 JMXServiceURL (javax.management.remote.JMXServiceURL)12 HashMap (java.util.HashMap)10 NotBoundException (java.rmi.NotBoundException)9 JMXConnector (javax.management.remote.JMXConnector)9 DistributedRMICounter (examples.mvc.rmi.duplex.DistributedRMICounter)8 SocketException (java.net.SocketException)8 AlreadyBoundException (java.rmi.AlreadyBoundException)8 MBeanServerConnection (javax.management.MBeanServerConnection)8 JMXConnectorServer (javax.management.remote.JMXConnectorServer)8 Test (org.junit.Test)8 MBeanServer (javax.management.MBeanServer)7 InetAddress (java.net.InetAddress)6 MalformedURLException (java.net.MalformedURLException)6