List of usage examples for java.rmi.registry LocateRegistry getRegistry
public static Registry getRegistry(String host) throws RemoteException
Registry
on the specified host
on the default registry port of 1099. From source file:com.taobao.tddl.common.util.TDDLMBeanServer.java
private TDDLMBeanServer() { // MBServer/*from www. j a v a2 s.c o m*/ String hostName = null; try { InetAddress addr = InetAddress.getLocalHost(); hostName = addr.getHostName(); } catch (IOException e) { log.error(LogPrefix + "Get HostName Error", e); hostName = "localhost"; } String host = System.getProperty("hostName", hostName); try { boolean useJmx = Boolean.parseBoolean(System.getProperty("tddl.useJMX", "true")); if (useJmx) { mbs = ManagementFactory.getPlatformMBeanServer(); int port = Integer.parseInt(System.getProperty("tddl.rmi.port", "6679")); String rmiName = System.getProperty("tddl.rmi.name", "tddlJmxServer"); Registry reg = null; try { reg = LocateRegistry.getRegistry(port); reg.list(); } catch (Exception e) { reg = null; } if (null == reg) { reg = LocateRegistry.createRegistry(port); } reg.list(); String serverURL = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/" + rmiName; JMXServiceURL url = new JMXServiceURL(serverURL); final JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); connectorServer.start(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { System.err.println("JMXConnector stop"); connectorServer.stop(); } catch (IOException e) { log.error(LogPrefix + e); } } }); log.warn(LogPrefix + "jmx url: " + serverURL); } } catch (Exception e) { log.error(LogPrefix + "create MBServer error", e); } }
From source file:com.feedzai.fos.server.FosServer.java
/** * Binds the Manager and Scorer to the RMI Registry. * <p/> Also registers a shutdown hook for closing and removing the items from the registry. * * @throws RemoteException when binding was not possible. *//* w ww . j av a 2 s . c om*/ public void bind() throws RemoteException { registry = LocateRegistry.getRegistry(parameters.getRegistryPort()); registry.rebind(IRemoteManager.class.getSimpleName(), UnicastRemoteObject.exportObject(remoteManager, parameters.getRegistryPort())); registry.rebind(RemoteScorer.class.getSimpleName(), UnicastRemoteObject.exportObject(remoteManager.getScorer(), parameters.getRegistryPort())); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { unbind(); } }); }
From source file:gridool.util.remoting.RemoteBase.java
private static Registry prepareRegistry(int port) throws RemoteException { Registry registry;/*from w w w . j a va2 s. c o m*/ try { registry = LocateRegistry.createRegistry(port); LOG.info("created local rmi-registry at port: " + port); } catch (RemoteException e) { registry = LocateRegistry.getRegistry(port); LOG.info("re-used existing local rmi-registry of port: " + port); } assert (registry != null); return registry; }
From source file:com.cisco.oss.foundation.monitoring.RegistryFinder.java
private Registry internalProcessStart(final Configuration configuration, final int port, final String command) throws IOException, RemoteException, AccessException { String maxHeapArg = "-J-Xmx" + configuration.getInt(FoundationMonitoringConstants.RMIREGISTRY_MAXHEAPSIZE) + "m"; // start rmiregistry process if (System.getProperty("os.name").toLowerCase(Locale.getDefault()).contains("windows")) { String[] commandArgsArr = new String[] { command, maxHeapArg, String.valueOf(port) }; List<String> commandArgs = Arrays.asList(commandArgsArr); LOGGER.info("running command: " + commandArgs); new ProcessBuilder(commandArgsArr).start(); } else {/*www . j a v a 2 s. co m*/ // support background process to prevent zombies String[] commandArgsArr = new String[] { "/bin/sh", "-c", command + maxHeapArg + " " + port + "&" }; List<String> commandArgs = Arrays.asList(commandArgsArr); LOGGER.info("running command: " + commandArgs); new ProcessBuilder(commandArgsArr).start(); } try { // wait for the process to start properly Thread.sleep(1000); } catch (InterruptedException e) { LOGGER.warn("The sleep for rmi registry to end has been interrupted: " + e.toString()); } // get registry final Registry registry = LocateRegistry.getRegistry(port); // test registry registry.list(); LOGGER.info("New RMI Registry created using port: " + port); return registry; }
From source file:net.sf.ehcache.distribution.RMICacheManagerPeerListener.java
/** * Start the rmiregistry./*from w w w.jav a 2 s . c o m*/ * <p/> * The alternative is to use the <code>rmiregistry</code> binary, in which case: * <ol/> * <li>rmiregistry running * <li>-Djava.rmi.server.codebase="file:///Users/gluck/work/ehcache/build/classes/ file:///Users/gluck/work/ehcache/lib/commons-logging-1.0.4.jar" * </ol> * * @throws RemoteException */ protected void startRegistry() throws RemoteException { try { registry = LocateRegistry.getRegistry(port.intValue()); try { registry.list(); } catch (RemoteException e) { //may not be created. Let's create it. registry = LocateRegistry.createRegistry(port.intValue()); registryCreated = true; } } catch (ExportException exception) { LOG.fatal("Exception starting RMI registry. Error was " + exception.getMessage(), exception); } }
From source file:org.red5.server.war.RootContextLoaderServlet.java
protected void initRegistry(ServletContext ctx) { Registry r = null;/*from w w w . java 2 s .co m*/ try { Object o = ctx.getInitParameter("rmiPort"); if (o != null) { rmiPort = Integer.valueOf((String) o); } if (System.getSecurityManager() != null) { System.setSecurityManager(new RMISecurityManager()); } // lookup the registry r = LocateRegistry.getRegistry(rmiPort); // ensure we are not already registered with the registry for (String regName : r.list()) { logger.debug("Registry entry: " + regName); } } catch (RemoteException re) { logger.info("RMI Registry server was not found on port " + rmiPort); // if we didnt find the registry and the user wants it created try { logger.info("Starting an internal RMI registry"); // create registry for rmi r = LocateRegistry.createRegistry(rmiPort); } catch (RemoteException e) { logger.info("RMI Registry server was not started on port " + rmiPort); } } }
From source file:com.redsqirl.auth.UserInfoBean.java
/** * createRegistry//ww w . j a v a 2 s. com * * Method to create the connection to the server rmi. Retrieve objects and * places them in the context of the application. * * @return * @author Igor.Souza */ public boolean createRegistry() { logger.warn("createRegistry"); List<String> beans = new ArrayList<String>(); beans.add("wfm"); beans.add("ssharray"); beans.add("jdbc"); beans.add("hcat"); beans.add("oozie"); beans.add("hdfs"); beans.add("prefs"); beans.add("hdfsbrowser"); beans.add("samanager"); FacesContext fCtx = FacesContext.getCurrentInstance(); ServletContext sc = (ServletContext) fCtx.getExternalContext().getContext(); HttpSession session = (HttpSession) fCtx.getExternalContext().getSession(false); try { try { registry = LocateRegistry.getRegistry(port); } catch (Exception e) { registry = LocateRegistry.createRegistry(port); } Iterator<String> beanIt = beans.iterator(); while (beanIt.hasNext()) { String bean = beanIt.next(); try { registry.unbind(userName + "@" + beanIt.next()); } catch (NotBoundException e) { logger.warn("Object " + bean + " unable to unbind: " + e.getMessage()); } catch (Exception e) { logger.warn("Object " + bean + " unable to unbind: " + e.getMessage()); } } if (th != null) { String pid = new WorkflowProcessesManager(userName).getPid(); logger.warn("Kill the process " + pid); th.kill(pid); } th = new ServerProcess(port); logger.warn("Sys home is : " + WorkflowPrefManager.pathSysHome); th.run(userName, sessionSSH); logger.warn("Sys home is : " + WorkflowPrefManager.pathSysHome); if (sessionSSH != null) { sc.setAttribute("UserInfo", sessionSSH.getUserInfo()); } logger.info("update progressbar"); setValueProgressBar(10); session.setAttribute("serverThread", th); sc.setAttribute("registry", registry); Iterator<String> itBean = beans.iterator(); while (itBean.hasNext() && !cancel) { String beanName = itBean.next(); logger.warn("createRegistry - " + beanName); if (beanName.equalsIgnoreCase("wfm")) { boolean error = true; int tryNumb = 0; while (error && !cancel) { ++tryNumb; try { DataFlowInterface dfi = (DataFlowInterface) registry.lookup(userName + "@" + beanName); dfi.addWorkflow("test"); error = false; dfi.removeWorkflow("test"); //FIXME size cluster aws // if(!dfi.checkNumberCluster(getNumberCluster())){ // setErrorNumberCluster(getMessageResources("error_number_cluster")); // return false; // } logger.warn("workflow is running "); } catch (Exception e) { logger.info("workflow not running "); Thread.sleep(500); if (tryNumb > 1 * 60 * 2000000) { throw e; } if (getValueProgressBar() < 45) { logger.info("update progressbar"); setValueProgressBar(Math.min(79, getValueProgressBar() + 3)); } else { setValueProgressBar(Math.min(79, getValueProgressBar() + 2)); } } } logger.info("update progressbar"); setValueProgressBar(80); } boolean error = true; int cont = 0; while (error && !cancel) { cont++; try { Remote remoteObject = registry.lookup(userName + "@" + beanName); error = false; session.setAttribute(beanName, remoteObject); } catch (Exception e) { Thread.sleep(500); logger.error(e.getMessage()); // Time out after 3 minutes if (cont > 1 * 60 * 2000000) { throw e; } } } } return true; } catch (Exception e) { logger.error("Fail to initialise registry, Exception: " + e.getMessage(), e); return false; } }
From source file:de.clusteval.framework.ClustevalBackendServer.java
/** * A helper method for {@link #ClusteringEvalFramework(Repository)}, which * registers the new backend server instance in the RMI registry. * /* w w w. j ava 2 s .c om*/ * @param framework * The backend server to register. * @return True, if the server has been registered successfully */ protected static boolean registerServer(ClustevalBackendServer framework) { Logger log = LoggerFactory.getLogger(ClustevalBackendServer.class); try { LocateRegistry.createRegistry(port); IBackendServer stub = (IBackendServer) UnicastRemoteObject.exportObject(framework, port); Registry registry = LocateRegistry.getRegistry(port); registry.bind("EvalServer", stub); log.info("Framework up and listening on port " + port); log.info("Used number of processors: " + config.numberOfThreads); return true; } catch (AlreadyBoundException e) { log.error("Another instance is already running..."); return false; } catch (RemoteException e) { log.error("Another instance is already running..."); return false; } }
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 .ja v a 2 s.c o 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.aeroivr.rsmc.common.ServiceLocator.java
public Registry getRmiRegistry(final int port) throws RemoteException { return LocateRegistry.getRegistry(port); }