List of usage examples for java.rmi Naming rebind
public static void rebind(String name, Remote obj) throws RemoteException, java.net.MalformedURLException
From source file:SuperPeer.java
/** * The good stuff./*from ww w. j av a2 s.c o m*/ */ public static void main(String[] argv) { int mbits = 5; ArgumentHandler cli = new ArgumentHandler("SuperPeer [-h]", "Run a DHT SuperPeer and attached to the specified superpeer.", "Bala Subrahmanyam Kambala, Daniel William DaCosta - GPLv3 (http://www.gnu.org/copyleft/gpl.html)"); cli.addOption("h", "help", false, "Print this usage information."); cli.addOption("m", "mbits", true, "The maximum number of unique keys in terms of 2^m (Default is " + Integer.toString(mbits) + ")."); CommandLine commandLine = cli.parse(argv); if (commandLine.hasOption('h')) { cli.usage(""); System.exit(0); } if (commandLine.hasOption('m')) { //XXX:uncaught exception! mbits = Integer.parseInt((commandLine.getOptionValue('m'))); } try { Naming.rebind("SuperPeer", new SuperPeer(mbits)); } catch (Exception e) { System.out.println("SuperPeer failed: " + e); } }
From source file:com.xpn.xwiki.plugin.lucene.IndexSearchServer.java
public void run() { try {/*from w w w . j a v a 2s . c o m*/ this.searchables = createSearchers(this.indexDirs); LocateRegistry.createRegistry(Integer.parseInt(this.port)); this.multiSearcher = new MultiSearcher(this.searchables); this.multiImpl = new RemoteSearchable(this.multiSearcher); Naming.rebind("//" + this.hostname + ":" + this.port + "/" + this.serviceName, this.multiImpl); System.out.println("Lucene Search Server started with the name " + this.serviceName); } catch (Exception e) { System.out.println(e.toString()); } }
From source file:Peer.java
/** * The peer constructor.//from w w w . j ava2s . com */ public Peer(String sp) throws Exception { try { // Initialize of various members pred = null; succ = null; lock = false; // Find the SuperPeer superpeer = (SuperPeerInterface) Naming.lookup("//" + sp + "/SuperPeer"); // Initialize the node cache peercache = new HashMap<Key, PeerInterface>(); // Initialize word map dict = new HashMap<String, String>(); //////////////////////////////////////////////// // BEGIN CRITICAL SECTION // only one peer will be in this code at a time. superpeer.lock(); // Get this Peer's NodeID nodeid = superpeer.join(); //Start logger lg = new Logger("Peer:" + nodeid.toString()); lg.log(Level.FINER, "Peer started."); // Register with the RMI Registry. lg.log(Level.FINER, "Binding to local RMI registry with name " + nodeid.toString()); Naming.rebind(nodeid.toString(), this); // Get Successor succ = superpeer.getSuccessor(nodeid); // Get hasher lg.log(Level.FINER, "Retrieving Hash object"); hasher = superpeer.getHasher(); // Set mbits int mbits = hasher.getBitSize(); // Initialize finger table ft = new FingerTable(nodeid.succ(), nodeid); // Update finger table constructFingerTable(mbits); lock = true; // If we have a successor, start the notify cycle if (succ != null) { lg.log(Level.FINER, "Calling " + succ.toString()); getPeer(succ).notify(nodeid); } lock = false; superpeer.unlock(); // END CRITICAL SECTION //////////////////////////////////////////////// lg.log(Level.FINER, "Exit Critical Section"); lg.log(Level.INFO, "!!!! Peer " + nodeid + " at " + superpeer.getAddress(nodeid) + " started !!!!"); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.l2jfree.gameserver.elayne.RemoteAdministrationImpl.java
License:asdf
public void startServer() { if (Config.ALLOW_RMI_SERVER && _port != 0) { try {/* w w w . j av a2 s. c o m*/ _lReg = LocateRegistry.createRegistry(_port); _obj = new RemoteAdministrationImpl(); if (_pass.isEmpty()) { _log.info("No password defined for RMI Server"); _pass = generateRandomPassword(10); _log.info("A password has been automatically generated: " + _pass); } Naming.rebind("//localhost:" + _port + "/Elayne", _obj); _log.info("RMI Server started on port: " + _port + ", Password: " + _pass + "."); } catch (Exception e) { _log.error("RemoteAdministrationImpl error: ", e); e.printStackTrace(); } } else _log.info("RMI Server is currently disabled."); }
From source file:gridool.util.remoting.RemoteBase.java
protected void bind() throws RemoteException, NamingException { //if(System.getSecurityManager() == null) {// create and install a security manager // System.setSecurityManager(new RMISecurityManager()); //}/*from w w w. ja va 2 s. c om*/ final Remote stub; if (rmiProtocol.equals(RMI_PROTOCOL_JRMP_SSL)) { stub = UnicastRemoteObject.exportObject(this, exportPort, new SslRMIClientSocketFactory(), new SslRMIServerSocketFactory()); } else { assert (rmiProtocol.equals(RMI_PROTOCOL_JRMP)); stub = UnicastRemoteObject.exportObject(this, exportPort, TimeoutSocketProdiver.createClientSocketFactory(), null); } try {// bind the remote object's stub in the registry Naming.rebind(endpointUrl, stub); } catch (MalformedURLException e) { LOG.error("failed to bind: " + endpointUrl, e); throw new IllegalStateException("Illegal regist url: " + endpointUrl, e); } LOG.info("Remote object is bounded at " + endpointUrl + " for " + ObjectUtils.identityToString(this)); }
From source file:org.red5.server.war.SubContextLoaderServlet.java
/** * Main entry point for the Red5 Server as a war */// ww w . ja v a 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:edu.hku.sdb.driver.SdbDriver.java
private static void startConnectionPool(SdbConf sdbConf) { try {/*from w w w . ja v a 2 s .co m*/ ConnectionPool connectionPool = new ConnectionPool(sdbConf); ConnectionConf connectionConf = sdbConf.getConnectionConf(); LocateRegistry.createRegistry(connectionConf.getSdbPort()); String sdbConnectionUrl = connectionConf.getSdbAddress() + ":" + connectionConf.getSdbPort() + "/" + SERVICE_NAME; LOG.info("Starting SDB Proxy"); Naming.rebind(sdbConnectionUrl, connectionPool); } catch (RemoteException | MalformedURLException e) { e.printStackTrace(); } }
From source file:com.xpn.xwiki.plugin.lucene.IndexSearchServer.java
/** * Restart the search server, to use the updated index. *///w w w .j a v a2 s .c o m public void resetServer() { try { closeSearcher(this.searchables); this.multiSearcher.close(); this.multiImpl.close(); this.searchables = createSearchers(this.indexDirs); this.multiSearcher = new MultiSearcher(this.searchables); this.multiImpl = new RemoteSearchable(this.multiSearcher); //Naming.unbind("//"+this.hostname+":"+this.port+"/XWiki_LuceneMultiSearch"); Naming.unbind("//" + this.hostname + ":" + this.port + "/" + this.serviceName); Naming.rebind("//" + this.hostname + ":" + this.port + "/" + this.serviceName, multiImpl); } catch (Exception e) { System.out.println(e.toString()); } }
From source file:com.symbian.driver.remoting.master.TestMaster.java
/** * Start master./*from ww w . j a v a 2 s .c o m*/ */ public void start() { String bindingName = null; String jobsFolder = null; String lHostName = null; String lServiceName = null; // start rmi registry /* * The user can specify the ip@ or the host name at config --server */ try { TDConfig CONFIG = TDConfig.getInstance(); lHostName = CONFIG.getPreference(TDConfig.SERVER_NAME); lServiceName = CONFIG.getPreference(TDConfig.SERVICE); LOGGER.fine("Host: " + lHostName + " RMI Service: " + lServiceName); jobsFolder = CONFIG.getPreferenceFile(TDConfig.JOBS_FOLDER).getAbsolutePath(); if (lHostName.matches("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$")) { LOGGER.fine("Using host ip address for RMI from the config : " + lHostName); lHostName = InetAddress.getByName(lHostName).getHostName(); } if (lHostName == null) { LOGGER.log(Level.SEVERE, "Could not determine the Host Name. Please check your config."); System.exit(-1); } System.getProperties().setProperty("java.rmi.server.hostname", lHostName); Registry lRegistry = LocateRegistry.createRegistry(1099); LOGGER.fine("Master: RMI registry ready. " + lRegistry); } catch (ParseException lE) { LOGGER.log(Level.SEVERE, "Master: Can not parse configuration.", lE); System.exit(-1); } catch (UnknownHostException lUHE) { LOGGER.log(Level.SEVERE, "Invalid host name " + lHostName, lUHE); System.exit(-1); } catch (RemoteException lRemoteException) { LOGGER.log(Level.SEVERE, "Master: RMI registry failed to start " + lRemoteException.getMessage(), lRemoteException); System.exit(-1); } File storeFolder = new File(SERIALIZE_FOLDER); if (!(storeFolder.isDirectory())) { if (!(storeFolder.mkdirs())) { LOGGER.log(Level.SEVERE, "Master: Unable to create the store folder." + "Please ensure that the " + SERIALIZE_FOLDER + " folder exists. It is needed by Master for placing system restore files."); System.exit(-1); } } try { if (ClientRegister.getInstance().needRestore()) { LOGGER.info("Restoring Client register."); ClientRegister.getInstance().restoreSnapshot(); } if (JobTracker.getInstance().needRestore()) { LOGGER.info("Restoring Job tracker."); JobTracker.getInstance().restoreSnapshot(); } JobCounter jobCounter = new JobCounter(); if (jobCounter.needRestore()) { LOGGER.info("Restoring Job counter."); jobCounter.restoreSnapshot(); } QueuedExecutor queuedExecutor = new QueuedExecutor(); if (queuedExecutor.needRestore()) { LOGGER.info("Restoring execution queue."); queuedExecutor.restoreSnapshot(); } bindingName = "//" + lHostName + "/" + lServiceName; MasterRemote master = new MasterRemoteImpl(jobsFolder, jobCounter, queuedExecutor); Naming.rebind(bindingName, master); LOGGER.info("Remote Service Name : " + bindingName); } catch (RemoteException lRE) { LOGGER.log(Level.SEVERE, "Master: Problem with contacting the RMI Registry: ", lRE); System.exit(-1); } catch (IOException lE) { LOGGER.log(Level.SEVERE, "Master: Problem with starting up TestMaster: ", lE); System.exit(-1); } }
From source file:ComputeNode.java
public static void main(String[] argv) { String fileservername = "localhost"; String id = null;/*from w w w.j a va2s. c o m*/ Double underLoad = null; Double overLoad = null; Double failProb = null; Double constantload = null; Pair<Double, Double> gaussian = null; String fileName = null; ArgumentHandler cli = new ArgumentHandler( "FileServer [-h] [collector address] [-u underload] " + "[-o overload] [-c constant_load|-g mean variance] " + "[-p fail_prob] [-f configfile]", "Bala Subrahmanyam Kambala, Daniel William DaCosta - " + "GPLv3 (http://www.gnu.org/copyleft/gpl.html)", ""); cli.addOption("h", "help", false, "Print this usage information."); cli.addOption("u", "underLoad", true, "Under load threshold"); cli.addOption("o", "overLoad", true, "Over load threshold"); cli.addOption("c", "constant", true, "Generate constant load"); cli.addOption("p", "probability", true, "Fail Probability(0-100)"); cli.addOption("f", "configfile", true, "The configuration file to read parameters from. " + "The default is " + defaultconf + ". " + "Command line arguments will override config file " + "arguments."); cli.addOption(OptionBuilder.withLongOpt("gaussian").hasArgs(2) .withDescription("Generate a gaussian probability model for load " + "simulation. The first parameter is the mean " + "and the second parameter is the variance.") .create('g')); // parse command line CommandLine commandLine = cli.parse(argv); if (commandLine.hasOption('h')) { cli.usage(""); System.exit(0); } if (commandLine.hasOption('u')) { // TODO : Ensure the number is within range underLoad = Double.parseDouble(commandLine.getOptionValue('u')); } if (commandLine.hasOption('o')) { // TODO : Ensure the number is within range overLoad = Double.parseDouble(commandLine.getOptionValue('o')); } if (commandLine.hasOption('p')) { // TODO : Ensure the number is within range failProb = Double.parseDouble(commandLine.getOptionValue('p')); } if (commandLine.hasOption('c')) { // TODO : Ensure the number is within range constantload = Double.parseDouble(commandLine.getOptionValue('c')); } if (commandLine.hasOption('g')) { // TODO : Ensure the number is within range gaussian = new Pair<Double, Double>(Double.parseDouble(commandLine.getOptionValues('g')[0]), Double.parseDouble(commandLine.getOptionValues('g')[1])); } // TODO: If these flags are no longer mutually exclusive this // code should be adjusted to account for whatever constraint are // needed. if ((constantload != null) && (gaussian != null)) { cli.usage("-g -c switches are mutually exclusive!\n"); System.exit(1); } if (commandLine.hasOption('f')) { fileName = commandLine.getOptionValue('f'); } if (commandLine.getArgs().length != 0) fileservername = commandLine.getArgs()[0]; System.out.println(argv); try { ComputeNode node = new ComputeNode(fileservername, underLoad, overLoad, failProb, constantload, gaussian, fileName); Naming.rebind("ComputeNode" + Integer.toString(node.getID()), node); // Scheduling heart beat message handler Timer t = new Timer(); HeartBeatHandler h = node.new HeartBeatHandler(); t.schedule(h, 0, 1 * 1000); } catch (ConnectException ce) { //lg.log(Level.SEVERE, "Server is not alive"); ce.printStackTrace(); } catch (Exception e) { //lg.log(Level.SEVERE, "Exception in file server"); e.printStackTrace(); } }