List of usage examples for java.rmi.registry LocateRegistry getRegistry
public static Registry getRegistry(String host, int port) throws RemoteException
Registry
on the specified host
and port
. From source file:org.lnicholls.galleon.gui.Galleon.java
private static void createAndShowGUI() { try {//from w w w . j a v a 2 s . com System.setProperty("os.user.home", System.getProperty("user.home")); ArrayList errors = new ArrayList(); Server.setup(errors); log = Server.setupLog("org.lnicholls.galleon.gui.Galleon", "GuiTrace", "GuiFile", Constants.GUI_LOG_FILE); // log = Logger.getLogger(Galleon.class.getName()); printSystemProperties(); UIManager.put("ClassLoader", (com.jgoodies.plaf.LookUtils.class).getClassLoader()); UIManager.put("Application.useSystemFontSettings", Boolean.TRUE); Options.setGlobalFontSizeHints(FontSizeHints.MIXED2); Options.setDefaultIconSize(new Dimension(18, 18)); try { UIManager.setLookAndFeel( LookUtils.IS_OS_WINDOWS_XP ? "com.jgoodies.plaf.plastic.PlasticXPLookAndFeel" : Options.getSystemLookAndFeelClassName()); } catch (Exception e) { Tools.logException(Galleon.class, e); } /* * mServerConfiguration = new ServerConfiguration(); if * (mConfigureDir != null) { log.info("Configuration Dir=" + * mConfigureDir.getAbsolutePath()); new * Configurator(mServerConfiguration).load(mAppManager, * mConfigureDir); } else new * Configurator(mServerConfiguration).load(mAppManager); mAddress = * mServerConfiguration.getIPAddress(); if (mAddress == null || * mAddress.length() == 0) mAddress = "127.0.0.1"; */ log.info("Server address: " + mServerAddress); for (int i = 0; i < 100; i++) { try { mRegistry = LocateRegistry.getRegistry(mServerAddress, 1099 + i); String[] names = mRegistry.list(); ServerControl serverControl = (ServerControl) mRegistry.lookup("serverControl"); log.info("Found server at: " + mServerAddress + " on " + (1099 + i)); break; } catch (Throwable ex) { if (log.isDebugEnabled()) Tools.logException(Galleon.class, ex); } } File directory = new File(System.getProperty("apps")); if (!directory.exists() || !directory.isDirectory()) { String message = "App Class Loader directory not found: " + System.getProperty("apps"); InstantiationException exception = new InstantiationException(message); log.error(message, exception); throw exception; } File[] files = directory.listFiles(new FileFilter() { public final boolean accept(File file) { return !file.isDirectory() && !file.isHidden() && file.getName().toLowerCase().endsWith(".jar"); } }); ArrayList urls = new ArrayList(); for (int i = 0; i < files.length; ++i) { try { URL url = files[i].toURI().toURL(); urls.add(url); log.debug(url); } catch (Exception ex) { // should never happen } } directory = new File(System.getProperty("hme")); if (directory.exists()) { files = directory.listFiles(new FileFilter() { public final boolean accept(File file) { return !file.isDirectory() && !file.isHidden() && file.getName().toLowerCase().endsWith(".jar"); } }); for (int i = 0; i < files.length; ++i) { try { URL url = files[i].toURI().toURL(); urls.add(url); log.debug(url); } catch (Exception ex) { // should never happen } } } File currentDirectory = new File("."); directory = new File(currentDirectory.getAbsolutePath() + "/../lib"); // TODO Handle reloading; what if list changes? files = directory.listFiles(new FileFilter() { public final boolean accept(File file) { return !file.isDirectory() && !file.isHidden() && file.getName().toLowerCase().endsWith(".jar"); } }); for (int i = 0; i < files.length; ++i) { try { URL url = files[i].toURI().toURL(); urls.add(url); log.debug(url); } catch (Exception ex) { // should never happen } } URLClassLoader classLoader = new URLClassLoader((URL[]) urls.toArray(new URL[0])); Thread.currentThread().setContextClassLoader(classLoader); mMainFrame = new MainFrame(Tools.getVersion()); splashWindow.setVisible(false); mMainFrame.setVisible(true); /* * javax.swing.SwingUtilities.invokeLater(new Runnable() { public * void run() { mToGo.getRecordings(); } }); */ if (!isCurrentVersion()) { if (JOptionPane.showConfirmDialog(mMainFrame, "A new version of Galleon is available. Do you want to download the latest version?", "New Version", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { try { BrowserLauncher.openURL("http://galleon.tv"); } catch (Exception ex) { Tools.logException(Galleon.class, ex); } } } } catch (Exception ex) { Tools.logException(Galleon.class, ex); System.exit(0); } }
From source file:org.mule.module.management.agent.AbstractJmxAgent.java
protected void initRMI() throws Exception { String connectUri = (connectorServerUrl != null ? connectorServerUrl : StringUtils.EMPTY); if (connectUri.contains("jmx:rmi")) { int i = connectUri.lastIndexOf("rmi://"); URI uri = new URI(connectUri.substring(i)); if (rmiRegistry == null) { try { if (isCreateRmiRegistry()) { try { rmiRegistry = LocateRegistry.createRegistry(uri.getPort()); } catch (ExportException e) { logger.info("Registry on " + uri + " already bound. Attempting to use that instead"); rmiRegistry = LocateRegistry.getRegistry(uri.getHost(), uri.getPort()); }//from w w w.ja v a 2s . c o m } else { rmiRegistry = LocateRegistry.getRegistry(uri.getHost(), uri.getPort()); } } catch (RemoteException e) { throw new InitialisationException(e, this); } } } }
From source file:org.mule.module.management.agent.RmiRegistryAgent.java
public void start() throws MuleException { if (serverUri == null) { throw new InitialisationException(MessageFactory.createStaticMessage( "serverUri has not been set, this agent has not been initialized properly."), this); }/* w w w . j a v a2 s.co m*/ URI uri; try { uri = new URI(serverUri); } catch (URISyntaxException e) { throw new InitialisationException(e, this); } if (rmiRegistry == null) { try { if (createRegistry) { try { rmiRegistry = LocateRegistry.createRegistry(uri.getPort()); } catch (ExportException e) { logger.info("Registry on " + serverUri + " already bound. Attempting to use that instead"); rmiRegistry = LocateRegistry.getRegistry(uri.getHost(), uri.getPort()); } } else { rmiRegistry = LocateRegistry.getRegistry(uri.getHost(), uri.getPort()); } } catch (RemoteException e) { throw new InitialisationException(e, this); } } }
From source file:org.openadaptor.auxil.connector.rmi.RMIReadConnector.java
public void connect() { if (createRegistry) { try {//from w w w . j a v a 2s .c o m log.info("starting rmi registry on port " + registryPort); LocateRegistry.createRegistry(registryPort); registryHost = NetUtil.getLocalHostname(); } catch (RemoteException e) { throw new ConnectionException("failed to create rmi registry", e, this); } } try { rmiServer = new RMIDataProcessor(); } catch (RemoteException e) { throw new ConnectionException("failed to create rmi server", e, this); } try { log.info("binding rmi server " + serviceName + " on " + registryHost + ":" + registryPort); LocateRegistry.getRegistry(registryHost, registryPort).rebind(serviceName, rmiServer); } catch (Exception e) { rmiServer = null; throw new ConnectionException("failed to bind ", e, this); } }
From source file:org.openadaptor.auxil.connector.rmi.RMIReadConnector.java
public void disconnect() { try {/*ww w. jav a2 s . co m*/ LocateRegistry.getRegistry(registryHost, registryPort).unbind(serviceName); } catch (Exception e) { throw new ConnectionException("failed to unbind", e, this); } finally { rmiServer = null; } }
From source file:org.openadaptor.auxil.connector.rmi.RMIWriteConnector.java
/** * Look up service on Registry Host and attempt to connect to service *///from w w w .jav a 2 s . c o m public void connect() { try { log.info(getId() + " looking up " + serviceName + " on " + registryHost + ":" + registryPort); rmiServer = (IRemoteDataProcessor) LocateRegistry.getRegistry(registryHost, registryPort) .lookup(serviceName); } catch (Exception e) { throw new ConnectionException("failed to lookup rmi server", e, this); } }
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.ublog.benchmark.social.SocialBenchmark.java
private GraphInterface getRemoteGraphServer(String serverName, int serverPort) { if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); }/*www. j a va 2 s .com*/ try { if (logger.isInfoEnabled()) { logger.info("Trying to connect to graph server"); } Registry reg = LocateRegistry.getRegistry(serverName, serverPort); System.out.println("reg " + reg.list().toString()); return (GraphInterface) reg.lookup("Graph"); } catch (NotBoundException ex) { Logger.getLogger("global").log(null, ex); return null; } catch (RemoteException ex) { ex.printStackTrace(); Logger.getLogger("global").log(null, ex); return null; } }