Java Code Examples for java.rmi.Naming#lookup()

The following examples show how to use java.rmi.Naming#lookup() . 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 check out the related API usage on the sidebar.
Example 1
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 2
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 3
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 4
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);
    }

}
 
Example 5
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);
    }

}
 
Example 6
public static void main(String[] args) {
    String[] location = {"rmi://santafe.mightygumball.com/gumballmachine",
            "rmi://boulder.mightygumball.com/gumballmachine",
            "rmi://seattle.mightygumball.com/gumballmachine"};

    if (args.length >= 0) {
        location = new String[1];
        location[0] = "rmi://" + args[0] + "/gumballmachine";
    }

    GumballMonitor[] monitor = new GumballMonitor[location.length];


    for (int i = 0; i < location.length; i++) {
        try {
            GumballMachineRemote machine = (GumballMachineRemote) Naming.lookup(location[i]);
            monitor[i] = new GumballMonitor(machine);
            System.out.println(monitor[i]);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    for (int i = 0; i < monitor.length; i++) {
        monitor[i].report();
    }
}
 
Example 7
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 8
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 9
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);
    }

}
 
Example 10
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);
    }

}
 
Example 11
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);
    }

}
 
Example 12
/**
 * Returns the activation system for the VM. The activation system
 * may be set by the <code>setSystem</code> method. If the
 * activation system is not set via the <code>setSystem</code>
 * method, then the <code>getSystem</code> method attempts to
 * obtain a reference to the <code>ActivationSystem</code> by
 * looking up the name "java.rmi.activation.ActivationSystem" in
 * the Activator's registry. By default, the port number used to
 * look up the activation system is defined by
 * <code>ActivationSystem.SYSTEM_PORT</code>. This port can be
 * overridden by setting the property
 * <code>java.rmi.activation.port</code>.
 *
 * @return the activation system for the VM/group
 * @exception ActivationException if activation system cannot be
 *  obtained or is not bound
 * (means that it is not running)
 * @exception UnsupportedOperationException if and only if activation is
 * not supported by this implementation
 * @see #setSystem
 * @since 1.2
 */
public static synchronized ActivationSystem getSystem()
    throws ActivationException
{
    if (currSystem == null) {
        try {
            int port = AccessController.doPrivileged(
                new GetIntegerAction("java.rmi.activation.port",
                                     ActivationSystem.SYSTEM_PORT));
            currSystem = (ActivationSystem)
                Naming.lookup("//:" + port +
                              "/java.rmi.activation.ActivationSystem");
        } catch (Exception e) {
            throw new ActivationException(
                "unable to obtain ActivationSystem", e);
        }
    }
    return currSystem;
}
 
Example 13
/**
 * Returns the activation system for the VM. The activation system
 * may be set by the <code>setSystem</code> method. If the
 * activation system is not set via the <code>setSystem</code>
 * method, then the <code>getSystem</code> method attempts to
 * obtain a reference to the <code>ActivationSystem</code> by
 * looking up the name "java.rmi.activation.ActivationSystem" in
 * the Activator's registry. By default, the port number used to
 * look up the activation system is defined by
 * <code>ActivationSystem.SYSTEM_PORT</code>. This port can be
 * overridden by setting the property
 * <code>java.rmi.activation.port</code>.
 *
 * @return the activation system for the VM/group
 * @exception ActivationException if activation system cannot be
 *  obtained or is not bound
 * (means that it is not running)
 * @exception UnsupportedOperationException if and only if activation is
 * not supported by this implementation
 * @see #setSystem
 * @since 1.2
 */
public static synchronized ActivationSystem getSystem()
    throws ActivationException
{
    if (currSystem == null) {
        try {
            int port = AccessController.doPrivileged(
                new GetIntegerAction("java.rmi.activation.port",
                                     ActivationSystem.SYSTEM_PORT));
            currSystem = (ActivationSystem)
                Naming.lookup("//:" + port +
                              "/java.rmi.activation.ActivationSystem");
        } catch (Exception e) {
            throw new ActivationException(
                "unable to obtain ActivationSystem", e);
        }
    }
    return currSystem;
}
 
Example 14
/**
 * Returns the activation system for the VM. The activation system
 * may be set by the <code>setSystem</code> method. If the
 * activation system is not set via the <code>setSystem</code>
 * method, then the <code>getSystem</code> method attempts to
 * obtain a reference to the <code>ActivationSystem</code> by
 * looking up the name "java.rmi.activation.ActivationSystem" in
 * the Activator's registry. By default, the port number used to
 * look up the activation system is defined by
 * <code>ActivationSystem.SYSTEM_PORT</code>. This port can be
 * overridden by setting the property
 * <code>java.rmi.activation.port</code>.
 *
 * @return the activation system for the VM/group
 * @exception ActivationException if activation system cannot be
 *  obtained or is not bound
 * (means that it is not running)
 * @exception UnsupportedOperationException if and only if activation is
 * not supported by this implementation
 * @see #setSystem
 * @since 1.2
 */
public static synchronized ActivationSystem getSystem()
    throws ActivationException
{
    if (currSystem == null) {
        try {
            int port = AccessController.doPrivileged(
                new GetIntegerAction("java.rmi.activation.port",
                                     ActivationSystem.SYSTEM_PORT));
            currSystem = (ActivationSystem)
                Naming.lookup("//:" + port +
                              "/java.rmi.activation.ActivationSystem");
        } catch (Exception e) {
            throw new ActivationException(
                "unable to obtain ActivationSystem", e);
        }
    }
    return currSystem;
}
 
Example 15
/**
 * Check serverCallLog output
 */
private static void checkServerCallLog() throws Exception {
    ByteArrayOutputStream serverCallLog = new ByteArrayOutputStream();
    RemoteServer.setLog(serverCallLog);
    Naming.list(LOCATION);
    verifyLog(serverCallLog, "list");

    serverCallLog.reset();
    RemoteServer.setLog(null);
    PrintStream callStream = RemoteServer.getLog();
    if (callStream != null) {
        TestLibrary.bomb("call stream not null after calling " +
                         "setLog(null)");
    } else {
        System.err.println("call stream should be null and it is");
    }
    Naming.list(LOCATION);

    if (usingOld) {
        if (serverCallLog.toString().indexOf("UnicastServerRef") >= 0) {
            TestLibrary.bomb("server call logging not turned off");
        }
    } else if (serverCallLog.toByteArray().length != 0) {
        TestLibrary.bomb("call log contains output but it " +
                         "should be empty");
    }

    serverCallLog.reset();
    RemoteServer.setLog(serverCallLog);
    try {
        // generates a notbound exception
        Naming.lookup(LOCATION + "notthere");
    } catch (Exception e) {
    }
    verifyLog(serverCallLog, "exception");

    serverCallLog.reset();
    RemoteServer.setLog(serverCallLog);
    callStream = RemoteServer.getLog();
    callStream.println("bingo, this is a getLog test");
    verifyLog(serverCallLog, "bingo");
}
 
Example 16
/**
 * Check serverCallLog output
 */
private static void checkServerCallLog() throws Exception {
    ByteArrayOutputStream serverCallLog = new ByteArrayOutputStream();
    RemoteServer.setLog(serverCallLog);
    Naming.list(LOCATION);
    verifyLog(serverCallLog, "list");

    serverCallLog.reset();
    RemoteServer.setLog(null);
    PrintStream callStream = RemoteServer.getLog();
    if (callStream != null) {
        TestLibrary.bomb("call stream not null after calling " +
                         "setLog(null)");
    } else {
        System.err.println("call stream should be null and it is");
    }
    Naming.list(LOCATION);

    if (usingOld) {
        if (serverCallLog.toString().indexOf("UnicastServerRef") >= 0) {
            TestLibrary.bomb("server call logging not turned off");
        }
    } else if (serverCallLog.toByteArray().length != 0) {
        TestLibrary.bomb("call log contains output but it " +
                         "should be empty");
    }

    serverCallLog.reset();
    RemoteServer.setLog(serverCallLog);
    try {
        // generates a notbound exception
        Naming.lookup(LOCATION + "notthere");
    } catch (Exception e) {
    }
    verifyLog(serverCallLog, "exception");

    serverCallLog.reset();
    RemoteServer.setLog(serverCallLog);
    callStream = RemoteServer.getLog();
    callStream.println("bingo, this is a getLog test");
    verifyLog(serverCallLog, "bingo");
}
 
Example 17
/**
 * Returns the activation system for the VM. The activation system
 * may be set by the <code>setSystem</code> method. If the
 * activation system is not set via the <code>setSystem</code>
 * method, then the <code>getSystem</code> method attempts to
 * obtain a reference to the <code>ActivationSystem</code> by
 * looking up the name "java.rmi.activation.ActivationSystem" in
 * the Activator's registry. By default, the port number used to
 * look up the activation system is defined by
 * <code>ActivationSystem.SYSTEM_PORT</code>. This port can be
 * overridden by setting the property
 * <code>java.rmi.activation.port</code>.
 *
 * @return the activation system for the VM/group
 * @exception ActivationException if activation system cannot be
 *  obtained or is not bound
 * (means that it is not running)
 * @exception UnsupportedOperationException if and only if activation is
 * not supported by this implementation
 * @see #setSystem
 * @since 1.2
 */
public static synchronized ActivationSystem getSystem()
    throws ActivationException
{
    if (currSystem == null) {
        try {
            int port = AccessController.doPrivileged(
                new GetIntegerAction("java.rmi.activation.port",
                                     ActivationSystem.SYSTEM_PORT));
            currSystem = (ActivationSystem)
                Naming.lookup("//:" + port +
                              "/java.rmi.activation.ActivationSystem");
        } catch (Exception e) {
            throw new ActivationException(
                "unable to obtain ActivationSystem", e);
        }
    }
    return currSystem;
}
 
Example 18
/**
 * Check serverCallLog output
 */
private static void checkServerCallLog() throws Exception {
    ByteArrayOutputStream serverCallLog = new ByteArrayOutputStream();
    RemoteServer.setLog(serverCallLog);
    Naming.list(LOCATION);
    verifyLog(serverCallLog, "list");

    serverCallLog.reset();
    RemoteServer.setLog(null);
    PrintStream callStream = RemoteServer.getLog();
    if (callStream != null) {
        TestLibrary.bomb("call stream not null after calling " +
                         "setLog(null)");
    } else {
        System.err.println("call stream should be null and it is");
    }
    Naming.list(LOCATION);

    if (usingOld) {
        if (serverCallLog.toString().indexOf("UnicastServerRef") >= 0) {
            TestLibrary.bomb("server call logging not turned off");
        }
    } else if (serverCallLog.toByteArray().length != 0) {
        TestLibrary.bomb("call log contains output but it " +
                         "should be empty");
    }

    serverCallLog.reset();
    RemoteServer.setLog(serverCallLog);
    try {
        // generates a notbound exception
        Naming.lookup(LOCATION + "notthere");
    } catch (Exception e) {
    }
    verifyLog(serverCallLog, "exception");

    serverCallLog.reset();
    RemoteServer.setLog(serverCallLog);
    callStream = RemoteServer.getLog();
    callStream.println("bingo, this is a getLog test");
    verifyLog(serverCallLog, "bingo");
}
 
Example 19
/**
 * Check serverCallLog output
 */
private static void checkServerCallLog() throws Exception {
    ByteArrayOutputStream serverCallLog = new ByteArrayOutputStream();
    RemoteServer.setLog(serverCallLog);
    Naming.list(LOCATION);
    verifyLog(serverCallLog, "list");

    serverCallLog.reset();
    RemoteServer.setLog(null);
    PrintStream callStream = RemoteServer.getLog();
    if (callStream != null) {
        TestLibrary.bomb("call stream not null after calling " +
                         "setLog(null)");
    } else {
        System.err.println("call stream should be null and it is");
    }
    Naming.list(LOCATION);

    if (usingOld) {
        if (serverCallLog.toString().indexOf("UnicastServerRef") >= 0) {
            TestLibrary.bomb("server call logging not turned off");
        }
    } else if (serverCallLog.toByteArray().length != 0) {
        TestLibrary.bomb("call log contains output but it " +
                         "should be empty");
    }

    serverCallLog.reset();
    RemoteServer.setLog(serverCallLog);
    try {
        // generates a notbound exception
        Naming.lookup(LOCATION + "notthere");
    } catch (Exception e) {
    }
    verifyLog(serverCallLog, "exception");

    serverCallLog.reset();
    RemoteServer.setLog(serverCallLog);
    callStream = RemoteServer.getLog();
    callStream.println("bingo, this is a getLog test");
    verifyLog(serverCallLog, "bingo");
}
 
Example 20
protected Object getRMIProxy() throws RemoteException, NotBoundException, MalformedURLException {

        Entry<String, Integer> entry = slaveChooser.chooseSlave();

        String slaveIP = entry.getKey();
        int port = entry.getValue();

        System.out.println(getInvokeURL(slaveIP, port));
        return Naming.lookup(getInvokeURL(slaveIP, port));
    }