List of usage examples for java.rmi.registry Registry list
public String[] list() throws RemoteException, AccessException;
From source file:net.sqs2.omr.session.service.AbstractRemoteExecutorManager.java
private AbstractTaskTracker<T, D> createRemoteTaskTracker(String uriString, long remoteKey, long sessionID) { try {//www . j a v a 2 s. c o m URI uri = new URI(uriString); Registry registry = LocateRegistry.getRegistry(uri.getHost(), uri.getPort()); Logger.getLogger(getClass().getName()) .info("REGISTRY:\n" + StringUtil.join(registry.list(), "\n") + "\nLOOKUP:\n" + uri.getPath()); RemoteSessionSourceServer remoteSessionService = (RemoteSessionSourceServer) registry .lookup(uri.getPath()); long result = remoteSessionService.ping(remoteKey); // authentication if (AbstractTaskTracker.DEBUG_CLUSTER_MODE) { Logger.getLogger("executor").info("RemoteSessionService.URI=" + uri); Logger.getLogger("executor").info("Hello=" + result); } AbstractTaskTracker<T, D> remoteTaskTracker = createTaskTracker(this.taskTracker, remoteSessionService, remoteKey); this.remoteTaskTrackerMap.put(uriString, remoteTaskTracker); return remoteTaskTracker; } catch (ConnectException ex) { Logger.getLogger("executor").severe("ConnectException:" + uriString); } catch (RemoteException ex) { Logger.getLogger("executor").severe("RemoteException:" + uriString); } catch (NullPointerException ex) { Logger.getLogger("executor").severe("NullPointerException:" + uriString); } catch (NotBoundException ex) { ex.printStackTrace(); Logger.getLogger("executor").severe("NotBoundException:" + uriString); } catch (URISyntaxException ex) { Logger.getLogger("executor").severe("URISyntaxException:" + ex.getMessage()); } return null; }
From source file:org.jgentleframework.integration.remoting.rmi.support.RmiExecutor.java
/** * Test registry.// ww w . java 2 s. c om * * @param registry * the registry * @throws RemoteException * the remote exception */ protected static void testRegistry(Registry registry) throws RemoteException { registry.list(); }
From source file:org.kchine.rpf.KillAll.java
public static void main(String[] args) throws Exception { String stub = System.getProperty("stub"); if (stub == null || stub.equals("")) { Registry rmiRegistry = null; final String dburl = System.getProperty("db.url"); if (dburl != null && !dburl.equals("")) { final String user = System.getProperty("db.user"); final String password = System.getProperty("db.password"); System.out.println("DB url:" + dburl); System.out.println("DB user:" + user); System.out.println("DB password:" + password); Class.forName(System.getProperty("db.driver")); rmiRegistry = DBLayer.getLayer(getDBType(dburl), new ConnectionProvider() { public Connection newConnection() throws java.sql.SQLException { return DriverManager.getConnection(dburl, user, password); };//from w w w. ja v a 2 s. com }); } else { rmiRegistry = LocateRegistry.getRegistry(_registryHost, _registryPort); } String[] servantNames = rmiRegistry.list(); for (int i = 0; i < servantNames.length; ++i) { if (PoolUtils.shortRmiName(servantNames[i]).startsWith(_servantPoolPrefix)) { try { ((ManagedServant) rmiRegistry.lookup(servantNames[i])).die(); } catch (Exception e) { // e.printStackTrace(); } } } } else { ((ManagedServant) PoolUtils.hexToStub(stub, KillAll.class.getClassLoader())).die(); } }
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 a v a 2s .c o 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.kchine.rpf.ManagedServantAbstract.java
/** * Obtain the name this servant is registered under * //from w ww. j av a 2s . c o m * @return Servant's name, if any. * @throws java.rmi.RemoteException */ public static String makeName(String servantPoolPrefix, Registry rmiRegistry) throws RemoteException { String servantName = null; String[] servantNames = rmiRegistry.list(); Vector<Integer> idsVector = new Vector<Integer>(); for (int i = 0; i < servantNames.length; ++i) { String name = PoolUtils.shortRmiName(servantNames[i]); if (name.startsWith(servantPoolPrefix)) { String prefix = name.substring(servantPoolPrefix.length()); try { idsVector.add(Integer.decode(prefix)); } catch (Exception e) { } } } if (idsVector.size() == 0) { servantName = servantPoolPrefix + "1"; } else { idsVector.add(0); int[] ids = new int[idsVector.size()]; for (int i = 0; i < ids.length; ++i) { ids[i] = idsVector.elementAt(i); } Arrays.sort(ids); for (int i = 0; i < ids.length - 1; ++i) { if (ids[i + 1] > (ids[i] + 1)) { servantName = servantPoolPrefix + (ids[i] + 1); break; } } if (servantName == null) { servantName = servantPoolPrefix + (ids[ids.length - 1] + 1); } } return servantName; }
From source file:org.quartz.core.QuartzScheduler.java
/** * <p>//from www . ja v a 2s. c o m * Bind the scheduler to an RMI registry. * </p> */ private void bind() throws RemoteException { String host = resources.getRMIRegistryHost(); // don't export if we're not configured to do so... if (host == null || host.length() == 0) { return; } RemotableQuartzScheduler exportable = null; if (resources.getRMIServerPort() > 0) { exportable = (RemotableQuartzScheduler) UnicastRemoteObject.exportObject(this, resources.getRMIServerPort()); } else { exportable = (RemotableQuartzScheduler) UnicastRemoteObject.exportObject(this); } Registry registry = null; if (resources.getRMICreateRegistryStrategy().equals(QuartzSchedulerResources.CREATE_REGISTRY_AS_NEEDED)) { try { // First try to get an existing one, instead of creating it, // since if // we're in a web-app being 'hot' re-depoloyed, then the JVM // still // has the registry that we created above the first time... registry = LocateRegistry.getRegistry(resources.getRMIRegistryPort()); registry.list(); } catch (Exception e) { registry = LocateRegistry.createRegistry(resources.getRMIRegistryPort()); } } else if (resources.getRMICreateRegistryStrategy() .equals(QuartzSchedulerResources.CREATE_REGISTRY_ALWAYS)) { try { registry = LocateRegistry.createRegistry(resources.getRMIRegistryPort()); } catch (Exception e) { // Fall back to an existing one, instead of creating it, since // if // we're in a web-app being 'hot' re-depoloyed, then the JVM // still // has the registry that we created above the first time... registry = LocateRegistry.getRegistry(resources.getRMIRegistryPort()); } } else { registry = LocateRegistry.getRegistry(resources.getRMIRegistryHost(), resources.getRMIRegistryPort()); } String bindName = resources.getRMIBindName(); registry.rebind(bindName, exportable); getLog().info("Scheduler bound to RMI registry under name '" + bindName + "'"); }
From source file:org.red5.server.jmx.JMXAgent.java
public void init() { //environmental var holder HashMap env = null;//from w w w .ja va 2 s . co m 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.RmiRegistryFactoryBean.java
/** * Test the given RMI registry, calling some operation on it to * check whether it is still active.// w w w. ja va 2s. c om * <p>Default implementation calls {@code Registry.list()}. * @param registry the RMI registry to test * @throws RemoteException if thrown by registry methods * @see java.rmi.registry.Registry#list() */ protected void testRegistry(Registry registry) throws RemoteException { registry.list(); }
From source file:org.springframework.remoting.rmi.RmiServiceExporter.java
/** * Register the service as RMI object.//from w w w . j ava2s . co m * Creates an RMI registry on the specified port if none exists. */ public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); if (this.serviceName == null) { throw new IllegalArgumentException("serviceName is required"); } if (this.clientSocketFactory instanceof RMIServerSocketFactory) { this.serverSocketFactory = (RMIServerSocketFactory) this.clientSocketFactory; } if ((this.clientSocketFactory != null && this.serverSocketFactory == null) || (this.clientSocketFactory == null && this.serverSocketFactory != null)) { throw new IllegalArgumentException( "Both RMIClientSocketFactory and RMIServerSocketFactory or none required"); } Registry registry = null; logger.info("Looking for RMI registry at port '" + this.registryPort + "'"); try { // retrieve registry registry = LocateRegistry.getRegistry(this.registryPort); registry.list(); } catch (RemoteException ex) { logger.debug("RMI registry access threw exception", ex); logger.warn("Could not detect RMI registry - creating new one"); // assume no registry found -> create new one registry = LocateRegistry.createRegistry(this.registryPort); } // determine remote object if (getService() instanceof Remote) { // conventional RMI service this.exportedObject = (Remote) getService(); } else { // RMI invoker logger.info("RMI object '" + this.serviceName + "' is an RMI invoker"); this.exportedObject = new RmiInvocationWrapper(getProxyForService(), this); } // export remote object and bind it to registry logger.info( "Binding RMI service '" + this.serviceName + "' to registry at port '" + this.registryPort + "'"); if (this.clientSocketFactory != null) { UnicastRemoteObject.exportObject(this.exportedObject, this.servicePort, this.clientSocketFactory, this.serverSocketFactory); } else { UnicastRemoteObject.exportObject(this.exportedObject, this.servicePort); } registry.rebind(this.serviceName, this.exportedObject); }
From source file:org.ublog.benchmark.social.SocialBenchmark.java
private GraphInterface getRemoteGraphServer(String serverName, int serverPort) { if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); }/*from w w w . j a va2 s . c om*/ 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; } }