Java Code Examples for java.rmi.Naming#lookup()
The following examples show how to use
java.rmi.Naming#lookup() .
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: LookupNameWithColon.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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
Source File: UnderscoreHost.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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 3
Source File: UnderscoreHost.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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 4
Source File: UnderscoreHost.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
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
Source File: LookupNameWithColon.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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 6
Source File: GumballMonitorTestDrive.java From head-first-design-patterns-Java with MIT License | 5 votes |
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
Source File: UnderscoreHost.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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 8
Source File: UnderscoreHost.java From hottub with GNU General Public License v2.0 | 5 votes |
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 9
Source File: LookupNameWithColon.java From hottub with GNU General Public License v2.0 | 5 votes |
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 10
Source File: LookupNameWithColon.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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 11
Source File: LookupNameWithColon.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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 12
Source File: ActivationGroup.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * 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
Source File: ActivationGroup.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
/** * 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
Source File: CheckLogging.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * 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 15
Source File: CheckLogging.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * 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
Source File: ActivationGroup.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
/** * 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 17
Source File: CheckLogging.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * 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 18
Source File: CheckLogging.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * 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
Source File: ActivationGroup.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * 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 20
Source File: AbstractRemoteService.java From XueQiuSuperSpider with MIT License | 3 votes |
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)); }