Search in sources :

Example 81 with Registry

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

the class readTest method main.

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();
    }
}
Also used : LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) RemoteException(java.rmi.RemoteException)

Example 82 with Registry

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

the class InvalidName method main.

public static void main(String[] args) {
    String testName;
    // ensure that an exception is thrown for Naming URL with '#'
    try {
        System.err.println("\nRegression test for bugs " + "4136563 and 4208801\n");
        testName = new String("rmi://#/MyRMI");
        Naming.lookup(testName);
        System.err.println("no exception thrown for URL: " + testName);
        throw new RuntimeException("test failed");
    } catch (MalformedURLException e) {
        // should have received malformed URL exception
        System.err.println("Correctly received instance of " + "MalformedURLException:");
        System.err.println(e.getMessage());
        e.printStackTrace();
    } catch (Exception e) {
        TestLibrary.bomb(e);
    }
    // the local host's ip address are .equals()
    try {
        String localAddress = InetAddress.getLocalHost().getHostAddress();
        Registry registry = (Registry) Naming.lookup("rmi:///");
        if (registry.toString().indexOf(localAddress) >= 0) {
            System.err.println("verified registry endpoint contains ipaddress");
        } else {
            TestLibrary.bomb("registry endpoint does not contain ipaddress");
        }
    } catch (Exception e) {
        TestLibrary.bomb(e);
    }
    System.err.println("test passed");
}
Also used : MalformedURLException(java.net.MalformedURLException) Registry(java.rmi.registry.Registry) MalformedURLException(java.net.MalformedURLException)

Example 83 with Registry

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

the class TestLibrary method checkIfRegistryRunning.

/**
     * 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;
}
Also used : Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry) RemoteException(java.rmi.RemoteException)

Example 84 with Registry

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

the class ShutdownImpl method main.

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();
    }
}
Also used : LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry)

Example 85 with Registry

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

the class UnbindIdempotent method main.

public static void main(String[] args) throws Exception {
    Registry registry = TestLibrary.createRegistryOnUnusedPort();
    int registryPort = TestLibrary.getRegistryPort(registry);
    InitialContext ictx = new InitialContext();
    Context rctx;
    try {
        rctx = (Context) ictx.lookup("rmi://localhost:" + Integer.toString(registryPort));
    } catch (NamingException e) {
        // Unable to set up for test.
        return;
    }
    // Attempt to unbind a name that is not already bound.
    try {
        rctx.unbind("_bogus_4278121_");
    } catch (NameNotFoundException e) {
        throw new Exception("Test failed:  unbind() call not idempotent");
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) NamingException(javax.naming.NamingException) Registry(java.rmi.registry.Registry) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) NameNotFoundException(javax.naming.NameNotFoundException)

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