List of usage examples for java.rmi.registry Registry list
public String[] list() throws RemoteException, AccessException;
From source file:edu.cornell.med.icb.R.RConfigurationServer.java
public static void main(final String[] args) throws RemoteException { if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); }/* w w w .j a va2s . c om*/ final String name = "RConfiguration"; final RConfiguration engine = new RConfigurationServer(); final RConfiguration stub = (RConfiguration) UnicastRemoteObject.exportObject(engine, 0); final Registry registry = LocateRegistry.getRegistry(); System.out.println(ArrayUtils.toString(registry.list())); registry.rebind(name, stub); System.out.println("RConfiguration bound"); }
From source file:uk.co.moonsit.rmi.GraphClient.java
@SuppressWarnings("SleepWhileInLoop") public static void main(String args[]) { Properties p = new Properties(); try {/* www . jav a 2 s. com*/ p.load(new FileReader("graph.properties")); } catch (IOException ex) { Logger.getLogger(GraphClient.class.getName()).log(Level.SEVERE, null, ex); } //String[] labels = p.getProperty("labels").split(","); GraphClient demo = null; int type = 0; boolean log = false; if (args[0].equals("-l")) { log = true; } switch (type) { case 0: try { System.setProperty("java.security.policy", "file:./client.policy"); if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } String name = "GraphServer"; String host = p.getProperty("host"); System.out.println(host); Registry registry = LocateRegistry.getRegistry(host); String[] list = registry.list(); for (String s : list) { System.out.println(s); } GraphDataInterface gs = null; boolean bound = false; while (!bound) { try { gs = (GraphDataInterface) registry.lookup(name); bound = true; } catch (NotBoundException e) { System.err.println("GraphServer exception:" + e.toString()); Thread.sleep(500); } } @SuppressWarnings("null") String config = gs.getConfig(); System.out.println(config); /*float[] fs = gs.getValues(); for (float f : fs) { System.out.println(f); }*/ demo = new GraphClient(gs, 1000, 700, Float.parseFloat(p.getProperty("frequency")), log); demo.init(config); demo.run(); } catch (RemoteException e) { System.err.println("GraphClient exception:" + e.toString()); } catch (FileNotFoundException ex) { Logger.getLogger(GraphClient.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GraphClient.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(GraphClient.class.getName()).log(Level.SEVERE, null, ex); } finally { if (demo != null) { demo.close(); } } break; case 1: try { demo = new GraphClient(1000, 700, Float.parseFloat(p.getProperty("frequency"))); demo.init("A^B|Time|Error|-360|360"); demo.addData(0, 1, 100); demo.addData(0, 2, 200); demo.addData(1, 1, 50); demo.addData(1, 2, 450); } catch (FileNotFoundException ex) { Logger.getLogger(GraphClient.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GraphClient.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(GraphClient.class.getName()).log(Level.SEVERE, null, ex); } break; } }
From source file:com.cisco.oss.foundation.monitoring.RMIRegistryManager.java
/** * Checks if rmiregistry is running on the specified port. * * @param port/*from w w w. j av a2 s .c o m*/ * @return true if rmiregistry is running on the specified port, false * otherwise */ public static boolean isRMIRegistryRunning(Configuration configuration, int port) { try { final Registry registry = RegistryFinder.getInstance().getRegistry(configuration, port); registry.list(); return true; } catch (RemoteException ex) { return false; } catch (Exception e) { return false; } }
From source file:com.cisco.oss.foundation.monitoring.RMIRegistryManager.java
/** * Checks if a service is exported on the rmi registry with specified port. * * @param port/*from w ww . ja v a 2 s. c o m*/ * @return true if rmiregistry is running on the specified port and service * is exported on the rmi registry, false otherwise */ public static boolean isServiceExported(Configuration configuration, int port, String serviceName) { if (serviceName == null) return false; try { final Registry registry = RegistryFinder.getInstance().getRegistry(configuration, port); String[] list = registry.list(); if (list != null) { for (int i = 0; i < list.length; i++) { if (serviceName.equals(list[i])) return true; } } } catch (RemoteException ex) { return false; } catch (Exception e) { return false; } return false; }
From source file:com.cisco.oss.foundation.monitoring.RegistryFinder.java
/** * @see org.springframework.beans.factory.FactoryBean#getObject() *//*from w w w . j a v a 2 s.c om*/ public Registry getRegistry(Configuration configuration, int port) throws Exception {// NOPMD try { // try to get existing registry final Registry registry = LocateRegistry.getRegistry(port); // test the registry registry.list(); LOGGER.trace("using existing registry"); return registry; } catch (RemoteException ex) { // if registry does not exist, create a new one. return startRmiRegistryProcess(configuration, port); } }
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 {/*from w ww.ja v a2s .c o 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:com.taobao.tddl.common.util.TDDLMBeanServer.java
private TDDLMBeanServer() { // MBServer// ww w .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:de.tudarmstadt.lt.lm.app.ListServices.java
@Override public void run() { String[] services = new String[] {}; Registry registry = null; try {// w ww.java 2 s .c o m registry = LocateRegistry.getRegistry(_host, _port); } catch (Exception e) { LOG.error("Could not connect to registry.", e); System.exit(1); } try { services = registry.list(); } catch (Exception e) { LOG.error("Could not lookup services from registry.", e); System.exit(1); } LOG.info("{} services available.", services.length); for (String name : services) { Remote r = null; try { r = registry.lookup(name); } catch (NotBoundException | RemoteException e) { continue; } StringBuilder b = new StringBuilder(); for (Class<?> clazz : r.getClass().getInterfaces()) b.append(", ").append(clazz.getName()); String status = "status:unknown"; try { if (r instanceof StringProviderMXBean) status = ((StringProviderMXBean) r).getModelReady() ? "status:running" : "status:loading"; } catch (RemoteException e) { } System.out.format("%s\t(%s)\t[%s] %n", name, b.length() > 0 ? b.substring(2) : "", status); } }
From source file:de.tudarmstadt.lt.lm.web.servlet.LanguageModelProviderServlet.java
private void scanForLanguageModels() throws RemoteException, NotBoundException { Registry registry = LocateRegistry.getRegistry(_host, _port); Set<String> services = new HashSet<String>(Arrays.asList(registry.list())); if (services.size() == 0) System.out.println("no services available"); for (String name : services) { // if (_lm_keys.containsKey(name)) // continue; Remote r = registry.lookup(name); if (r instanceof StringProviderMXBean) { // StringProviderMBean strprvdr = (StringProviderMBean) r; _lm_keys.put(name, _lm_keys.size()); _lm_provider.add(null);//from ww w.j ava 2 s.com _perp_processors.add(null); } } }
From source file:org.red5.server.war.RootContextLoaderServlet.java
protected void initRegistry(ServletContext ctx) { Registry r = null; try {/*from w w w .j a v a 2s . c o m*/ 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); } } }