java.rmi.registry.Registry Java Examples
The following examples show how to use
java.rmi.registry.Registry.
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: RegistryContext.java From hottub with GNU General Public License v2.0 | 7 votes |
/** * 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 #2
Source File: Bootstrapper.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private static void bootstrap(int port) { Log.getLogWriter().info("Starting the bootstrapper."); Registry registry = RmiRegistryHelper.startRegistry(RMI_NAME, port); // create and register the bootstrapper proxy Log.getLogWriter().info("Creating the bootstrapper proxy"); BootstrapperProxy bootstrapper; try { bootstrapper = new BootstrapperProxy(); } catch (RemoteException e) { String s = "Bootstrapper proxy could not be created"; throw new HydraRuntimeException(s, e); } Log.getLogWriter().info("Registering the bootstrapper proxy"); RmiRegistryHelper.bind(registry, RMI_NAME, bootstrapper); Log.getLogWriter().info("Ready to roll"); }
Example #3
Source File: JstatdTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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 #4
Source File: InheritedChannelNotServerSocket.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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 #5
Source File: ShutdownImpl.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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 #6
Source File: InheritedChannelNotServerSocket.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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 #7
Source File: ShutdownImpl.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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 #8
Source File: RmiServer.java From JavaTutorial with Apache License 2.0 | 6 votes |
/** * @param args [0]:绑定端口 * @throws RemoteException */ public static void main(String[] args) throws RemoteException { int port = Integer.parseInt(args[0]); UserService userService = new UserServiceImpl(); Registry registry = createRegistry(port); if (null == registry) { System.exit(0); } String bindName = "UserService"; try { registry.bind(bindName, userService); } catch (AlreadyBoundException e) { _logger.info("服务{}已经绑定过", bindName); } _logger.info("RMI Server started, listen port:{}", port); }
Example #9
Source File: RmiServiceExporter.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * 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, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) throws RemoteException { if (registryHost != null) { // Host explicitly specified: only lookup possible. if (logger.isInfoEnabled()) { logger.info("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 #10
Source File: JstatdTest.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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 #11
Source File: TestLibrary.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * 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 #12
Source File: RmiServiceExporter.java From spring-analysis-note with MIT License | 6 votes |
/** * 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 #13
Source File: SelfTerminator.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { try { int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port")); Registry registry = LocateRegistry.getRegistry("", registryPort); Remote stub = registry.lookup(LeaseCheckInterval.BINDING); Runtime.getRuntime().halt(0); } catch (Exception e) { e.printStackTrace(); } }
Example #14
Source File: ContextWithNullProperties.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Registry registry = TestLibrary.createRegistryOnUnusedPort(); int registryPort = TestLibrary.getRegistryPort(registry); System.out.println("Connecting to the default Registry..."); // Connect to the default Registry. // Pass null as the JNDI environment properties (see final argument) RegistryContext ctx = new RegistryContext(null, registryPort, null); }
Example #15
Source File: SelfTerminator.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { try { int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port")); Registry registry = LocateRegistry.getRegistry("", registryPort); Remote stub = registry.lookup(LeaseCheckInterval.BINDING); Runtime.getRuntime().halt(0); } catch (Exception e) { e.printStackTrace(); } }
Example #16
Source File: CloseServerSocket.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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"); Thread.sleep(1000); // work around BindException (bug?) 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"); }
Example #17
Source File: Client.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public String testStub() throws Exception { try { Registry registry = LocateRegistry.getRegistry(port); Hello stub = (Hello) registry.lookup("Hello"); String response = stub.sayHello(); return response; } catch (Exception e) { System.err.println("Client exception: " + e.toString()); throw e; } }
Example #18
Source File: AboutCommand.java From sis with Apache License 2.0 | 5 votes |
/** * Creates a {@code "service:jmx:rmi:///jndi/rmi://host:port/jmxrmi"} URL for the given host name. * The host name can optionally be followed by a port number. */ static String toRemoteURL(final String host) { final StringBuilder buffer = new StringBuilder(60).append("service:jmx:rmi:///jndi/rmi://") .append(host, host.regionMatches(true, 0, "localhost", 0, 9) ? 9 : 0, host.length()); if (host.lastIndexOf(':') < 0) { buffer.append(':').append(Registry.REGISTRY_PORT); } return buffer.append("/jmxrmi").toString(); }
Example #19
Source File: ServerConnectTask.java From ghidra with Apache License 2.0 | 5 votes |
private static void checkServerBindNames(Registry reg) throws RemoteException { String requiredVersion = GhidraServerHandle.MIN_GHIDRA_VERSION; if (!Application.getApplicationVersion().startsWith(requiredVersion)) { requiredVersion = requiredVersion + " - " + Application.getApplicationVersion(); } String[] regList = reg.list(); RemoteException exc = null; int badVerCount = 0; for (String name : regList) { if (name.equals(GhidraServerHandle.BIND_NAME)) { return; // found it } else if (name.startsWith(GhidraServerHandle.BIND_NAME_PREFIX)) { String version = name.substring(GhidraServerHandle.BIND_NAME_PREFIX.length()); if (version.length() == 0) { version = "4.3.x (or older)"; } exc = new RemoteException( "Incompatible Ghidra Server interface, detected interface version " + version + ",\nthis client requires server version " + requiredVersion); ++badVerCount; } } if (exc != null) { if (badVerCount == 1) { throw exc; } throw new RemoteException("Incompatible Ghidra Server interface, detected " + badVerCount + " incompatible server versions" + ",\nthis client requires server version " + requiredVersion); } throw new RemoteException("Ghidra Server not found."); }
Example #20
Source File: RmidViaInheritedChannel.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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 #21
Source File: NoConsoleOutput.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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 #22
Source File: NoConsoleOutput.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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 #23
Source File: JndiContext.java From jqm with Apache License 2.0 | 5 votes |
/** * Will register the given Registry as a provider for the RMI: context. If there is already a registered Registry, the call is ignored. * * @param r */ void registerRmiContext(Registry r) { if (this.r == null) { this.r = r; } }
Example #24
Source File: RMICommChannelFactory.java From jolie with GNU Lesser General Public License v2.1 | 5 votes |
public CommChannel createChannel( URI location, OutputPort port ) throws IOException { try { Registry registry = LocateRegistry.getRegistry( location.getHost(), location.getPort() ); JolieRemote remote = (JolieRemote) registry.lookup( location.getPath() ); return new RMICommChannel( remote.createRemoteBasicChannel() ); } catch( NotBoundException e ) { throw new IOException( e ); } }
Example #25
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 #26
Source File: Client.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public String testStub() throws Exception { try { Registry registry = LocateRegistry.getRegistry(port); Hello stub = (Hello) registry.lookup("Hello"); String response = stub.sayHello(); return response; } catch (Exception e) { System.err.println("Client exception: " + e.toString()); throw e; } }
Example #27
Source File: JstatdTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public void doTest() throws Throwable { ProcessThread jstatdThread = null; try { while (jstatdThread == null) { if (!useDefaultPort || withExternalRegistry) { port = Integer.toString(Utils.getFreePort()); } if (withExternalRegistry) { Registry registry = startRegistry(); if (registry == null) { // The port is already in use. Cancel and try with new one. continue; } } jstatdThread = tryToSetupJstatdProcess(); } runToolsAndVerify(); } finally { cleanUpThread(jstatdThread); } // Verify output from jstatd OutputAnalyzer output = jstatdThread.getOutput(); assertTrue(output.getOutput().isEmpty(), "jstatd should get an empty output, got: " + Utils.NEW_LINE + output.getOutput()); assertNotEquals(output.getExitValue(), 0, "jstatd process exited with unexpected exit code"); }
Example #28
Source File: DUnitLauncher.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private static void launch() throws URISyntaxException, AlreadyBoundException, IOException, InterruptedException, NotBoundException { // initialize the log writer that hydra uses LogWriter log = Log.createLogWriter( "dunit-master", LOG_LEVEL ); locatorPort = AvailablePortHelper.getRandomAvailableTCPPort(); //create an RMI registry and add an object to share our tests config int namingPort = AvailablePortHelper.getRandomAvailableTCPPort(); Registry registry = LocateRegistry.createRegistry(namingPort); Master master = new Master(); registry.bind(MASTER_PARAM, master); final ProcessManager processManager = new ProcessManager(NUM_VMS + 1, namingPort); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { processManager.killVMs(); } }); //launch the remote VMS processManager.launchVMs(); //wait for the VMS to start up if(!master.waitForVMs(STARTUP_TIMEOUT)) { throw new RuntimeException("VMs did not start up with 30 seconds"); } //populate the Host class with our stubs. The tests use this host class EclipseDUnitHost host = new EclipseDUnitHost(InetAddress.getLocalHost().getCanonicalHostName(), NUM_VMS); host.init(registry); initSystemProperties(log); startLocator(registry); }
Example #29
Source File: RmiRegistryFactoryBean.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Locate or create the RMI registry. * @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( int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) throws RemoteException { if (clientSocketFactory != null) { if (this.alwaysCreate) { logger.info("Creating new RMI registry"); this.created = true; return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory); } if (logger.isInfoEnabled()) { logger.info("Looking for RMI registry at port '" + registryPort + "', using custom socket factory"); } synchronized (LocateRegistry.class) { try { // Retrieve existing registry. Registry reg = LocateRegistry.getRegistry(null, registryPort, clientSocketFactory); testRegistry(reg); return reg; } catch (RemoteException ex) { logger.debug("RMI registry access threw exception", ex); logger.info("Could not detect RMI registry - creating new one"); // Assume no registry found -> create new one. this.created = true; return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory); } } } else { return getRegistry(registryPort); } }
Example #30
Source File: readTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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(); } }