List of usage examples for java.rmi Naming bind
public static void bind(String name, Remote obj) throws AlreadyBoundException, java.net.MalformedURLException, RemoteException
name
to a remote object. From source file:org.red5.server.war.SubContextLoaderServlet.java
/** * Main entry point for the Red5 Server as a war *//*from w w w . j a va 2 s . c o m*/ // Notification that the web application is ready to process requests @Override public void contextInitialized(ServletContextEvent sce) { if (null != servletContext) { return; } System.setProperty("red5.deployment.type", "war"); servletContext = sce.getServletContext(); String prefix = servletContext.getRealPath("/"); initRegistry(servletContext); long time = System.currentTimeMillis(); logger.info("RED5 Server subcontext loader"); logger.debug("Path: " + prefix); try { String[] configArray = servletContext.getInitParameter(ContextLoader.CONFIG_LOCATION_PARAM) .split("[,\\s]"); logger.debug("Config location files: " + configArray.length); WebSettings settings = new WebSettings(); settings.setPath(prefix); // prefix the config file paths so they can be found later String[] subConfigs = new String[configArray.length]; for (int s = 0; s < configArray.length; s++) { String cfg = "file:/" + prefix + configArray[s]; logger.debug("Sub config location: " + cfg); subConfigs[s] = cfg; } settings.setConfigs(subConfigs); settings.setWebAppKey(servletContext.getInitParameter("webAppRootKey")); // store this contexts settings in the registry IRemotableList remote = null; boolean firstReg = false; try { remote = (IRemotableList) Naming.lookup("rmi://localhost:" + rmiPort + "/subContextList"); } catch (Exception e) { logger.warn("Lookup failed: " + e.getMessage()); } if (remote == null) { remote = new RemotableList(); firstReg = true; } logger.debug("Adding child web settings"); remote.addChild(settings); logger.debug("Remote list size: " + remote.numChildren()); if (firstReg) { Naming.bind("rmi://localhost:" + rmiPort + "/subContextList", remote); } else { Naming.rebind("rmi://localhost:" + rmiPort + "/subContextList", remote); } } catch (Throwable t) { logger.error(t); } long startupIn = System.currentTimeMillis() - time; logger.info("Startup done in: " + startupIn + " ms"); }
From source file:net.sf.mpaxs.spi.computeHost.Host.java
/** * Erstellt ein RemoteObject vom Typ IRemoteHost und trgt es in die lokale * RMI Registry ein. ber dieses RemoteObject knnen Jobs an diesen * ComputeHoste gesendet werden./* w ww . j a v a 2 s . c om*/ */ private void getReadyForClients() { Logger.getLogger(Host.class.getName()).log(Level.FINE, "Trying to create registry at {0}:{1}", new Object[] { settings.getLocalIp(), settings.getLocalPort() }); try { LocateRegistry.createRegistry(settings.getLocalPort()); Logger.getLogger(Host.class.getName()).log(Level.FINE, "Started own RMI-Registry on port {0}", settings.getLocalPort()); } catch (RemoteException ex) { if (!settings.getSilentMode()) { Logger.getLogger(Host.class.getName()).log(Level.FINE, "RMI-Registry already running on port {0}.", settings.getLocalPort()); Logger.getLogger(Host.class.getName()).log(Level.FINE, "ComputeHost will use the already running Registry."); } } try { // RemoteObject erstellen IComputeHost remObj = new ComputeHostImpl(this, settings); String bindString = "//" + settings.getLocalIp() + ":" + settings.getLocalPort() + "/" + settings.getName(); Logger.getLogger(Host.class.getName()).log(Level.FINE, "Trying to bind {0}", bindString); Naming.bind(bindString, remObj); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } }