List of usage examples for java.rmi.registry Registry unbind
public void unbind(String name) throws RemoteException, NotBoundException, AccessException;
name
in this registry. From source file:de.clusteval.framework.ClustevalBackendServer.java
/** * A helper method for {@link #shutdown(String, long)}, which terminates * this framework after a certain timeout. * /*from w w w. j ava 2 s.co m*/ * <p> * This method first interrupts the supervisor thread (see * {@link SupervisorThread}) and waits for its termination until the timeout * was reached. * * <p> * Then the backend server instance is unregistered from the RMI registry * and the repository of this framework is removed from the set of all * registered repositories. * * @throws InterruptedException * */ private void terminate(final long forceTimeout) throws InterruptedException { this.repository.terminateSupervisorThread(); try { Registry registry = LocateRegistry.getRegistry(port); registry.unbind("EvalServer"); UnicastRemoteObject.unexportObject(this, true); } catch (NoSuchObjectException e) { e.printStackTrace(); } catch (AccessException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } catch (NotBoundException e) { e.printStackTrace(); } /* * unregister repository */ Repository.unregister(this.repository); // should work without, just to be sure // System.exit(0); }
From source file:org.jgentleframework.integration.remoting.rmi.support.RmiExecutor.java
/** * Stop service.//from w ww .j av a2 s. c o m * * @param rmiExporter * the rmi exporter * @throws AccessException * the access exception * @throws RemoteException * the remote exception * @throws NotBoundException * the not bound exception */ public static void stopService(RmiExporter rmiExporter) throws AccessException, RemoteException, NotBoundException { Registry registry = rmiExporter.getRegistry(); String serviceName = rmiExporter.getServiceName(); int servicePort = rmiExporter.getServicePort(); int registryPort = rmiExporter.getRegistryPort(); if (log.isInfoEnabled()) { log.info("Unbinding RMI service '" + serviceName + "' from registry at port '" + servicePort + "'"); } try { registry.unbind(serviceName); } catch (NotBoundException ex) { if (log.isWarnEnabled()) { log.warn("RMI service '" + serviceName + "' is not bound to registry at port '" + registryPort + "' anymore", ex); } } finally { unexportObjectBeanService(rmiExporter); } }
From source file:org.kchine.rpf.ManagedServantAbstract.java
public ManagedServantAbstract(String name, String prefix, Registry registry, int port) throws RemoteException { super(port);// w w w . j av a2 s . co m _registry = registry; try { registry.list(); log.info("ping registry:ok"); } catch (ConnectException ce) { String message = "can't connect to the naming server, make sure an instance of rmiregistry is running"; log.info(message); throw new RemoteException(message); } catch (Exception e) { e.printStackTrace(); } String newname = null; if (name == null) { while (true) { newname = makeName(prefix, registry); try { registry.bind(newname, java.rmi.server.RemoteObject.toStub(this)); break; } catch (AlreadyBoundException e) { } } } else { // if (!name.startsWith(prefix)) throw new // RemoteException("The server name must start with :" + prefix); ManagedServant oldServant = null; try { oldServant = ((ManagedServant) registry.lookup(name)); } catch (NotBoundException e) { } if (oldServant != null) { log.info("Found an old servant with this name. Killing old servant."); try { PoolUtils.die(oldServant); } catch (RemoteException re) { log.info("Old servant wouldn't die! "); } } registry.rebind(name, java.rmi.server.RemoteObject.toStub(this)); } _servantName = name == null ? newname : name; final Registry reg = registry; Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { try { log.info("Shutting Down"); reg.unbind(_servantName); } catch (Exception e) { e.printStackTrace(); } } })); }
From source file:org.quartz.core.QuartzScheduler.java
/** * <p>//from www.j a v a 2 s. c o m * Un-bind the scheduler from an RMI registry. * </p> */ private void unBind() throws RemoteException { String host = resources.getRMIRegistryHost(); // don't un-export if we're not configured to do so... if (host == null || host.length() == 0) { return; } Registry registry = LocateRegistry.getRegistry(resources.getRMIRegistryHost(), resources.getRMIRegistryPort()); String bindName = resources.getRMIBindName(); try { registry.unbind(bindName); UnicastRemoteObject.unexportObject(this, true); } catch (java.rmi.NotBoundException nbe) { } getLog().info("Scheduler un-bound from name '" + bindName + "' in RMI registry"); }
From source file:org.red5.server.jmx.JMXAgent.java
public void init() { //environmental var holder HashMap env = null;//from ww w. ja va 2 s . c om if (enableHtmlAdapter) { // setup the adapter try { //instance an html adaptor int port = htmlAdapterPort == null ? 8082 : Integer.valueOf(htmlAdapterPort); html = new HtmlAdaptorServer(port); ObjectName htmlName = new ObjectName( JMXFactory.getDefaultDomain() + ":type=HtmlAdaptorServer,port=" + port); log.debug("Created HTML adaptor on port: " + port); //add the adaptor to the server mbs.registerMBean(html, htmlName); //start the adaptor html.start(); log.info("JMX HTML connector server successfully started"); } catch (Exception e) { log.error("Error in setup of JMX subsystem (HTML adapter)", e); } } else { log.info("JMX HTML adapter was not enabled"); } if (enableRmiAdapter) { // Create an RMI connector server log.debug("Create an RMI connector server"); try { Registry r = null; try { //lookup the registry r = LocateRegistry.getRegistry(Integer.valueOf(rmiAdapterPort)); //ensure we are not already registered with the registry for (String regName : r.list()) { if (regName.equals("red5")) { //unbind connector from rmi registry r.unbind("red5"); } } } catch (RemoteException re) { log.info("RMI Registry server was not found on port " + rmiAdapterPort); //if we didnt find the registry and the user wants it created if (startRegistry) { log.info("Starting an internal RMI registry"); // create registry for rmi port 9999 r = LocateRegistry.createRegistry(Integer.valueOf(rmiAdapterPort)); } } JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:" + rmiAdapterPort + "/red5"); //if SSL is requested to secure rmi connections if (enableSsl) { // Environment map log.debug("Initialize the environment map"); env = new HashMap(); // Provide SSL-based RMI socket factories SslRMIClientSocketFactory csf = new SslRMIClientSocketFactory(); SslRMIServerSocketFactory ssf = new SslRMIServerSocketFactory(); env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf); env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf); } //if authentication is requested if (StringUtils.isNotBlank(remoteAccessProperties)) { //if ssl is not used this will be null if (null == env) { env = new HashMap(); } //check the existance of the files //in the war version the full path is needed File file = new File(remoteAccessProperties); if (!file.exists()) { log.debug("Access file was not found on path, will prepend config_root"); //pre-pend the system property set in war startup remoteAccessProperties = System.getProperty("red5.config_root") + '/' + remoteAccessProperties; remotePasswordProperties = System.getProperty("red5.config_root") + '/' + remotePasswordProperties; } env.put("jmx.remote.x.access.file", remoteAccessProperties); env.put("jmx.remote.x.password.file", remotePasswordProperties); } // create the connector server cs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs); // add a listener for shutdown cs.addNotificationListener(this, null, null); // Start the RMI connector server log.debug("Start the RMI connector server"); cs.start(); log.info("JMX RMI connector server successfully started"); } catch (ConnectException e) { log.warn("Could not establish RMI connection to port " + rmiAdapterPort + ", please make sure \"rmiregistry\" is running and configured to listen on this port."); } catch (IOException e) { String errMsg = e.getMessage(); if (errMsg.indexOf("NameAlreadyBoundException") != -1) { log.error("JMX connector (red5) already registered, you will need to restart your rmiregistry"); } else { log.error("{}", e); } } catch (Exception e) { log.error("Error in setup of JMX subsystem (RMI connector)", e); } } else { log.info("JMX RMI adapter was not enabled"); } }
From source file:org.springframework.remoting.rmi.RmiServiceExporter.java
public void destroy() throws RemoteException, NotBoundException { logger.info("Unbinding RMI service '" + this.serviceName + "' from registry at port '" + this.registryPort + "'"); Registry registry = LocateRegistry.getRegistry(this.registryPort); registry.unbind(this.serviceName); UnicastRemoteObject.unexportObject(this.exportedObject, true); }