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:de.tudarmstadt.lt.lm.app.ListServices.java
@Override public void run() { String[] services = new String[] {}; Registry registry = null;/* ww w . j av a 2 s . c om*/ try { 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 w w w. j a v a 2s . com _perp_processors.add(null); } } }
From source file:de.tudarmstadt.lt.lm.web.servlet.LanguageModelProviderServlet.java
private boolean connectToLanguageModel(String key) throws Exception { try {/*ww w. jav a2 s .c o m*/ int index = _lm_keys.get(key); Registry registry = LocateRegistry.getRegistry(_host, _port); StringProviderMXBean lmprvdr = (StringProviderMXBean) registry.lookup(key); if (lmprvdr.getModelReady()) { _lm_provider.set(index, lmprvdr); return true; } } catch (RemoteException e) { LOG.error("Unable to connect to rmi registry on {}:{}. {}: {}.", _host, _port, e.getClass().getSimpleName(), e.getMessage()); } catch (NotBoundException e) { LOG.error("Unable to connect to service {}. {}: {}.", key, e.getClass().getSimpleName(), e.getMessage()); } return false; }
From source file:edu.umd.lib.servlets.permissions.PermissionsServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); parseInitParameters(config);//from w w w.ja v a 2s . c om System.setProperty(SYSTEM_SERVLETCONFIG_PROPERTY, repositoryConfig); try { // get the local embedded repository repository = HippoRepositoryFactory.getHippoRepository(storageLocation); HippoRepositoryFactory.setDefaultRepository(repository); if (startRemoteServer) { // the the remote repository RepositoryUrl url = new RepositoryUrl(bindingAddress); rmiRepository = new ServerServicingAdapterFactory(url) .getRemoteRepository(repository.getRepository()); System.setProperty("java.rmi.server.useCodebaseOnly", "true"); // Get or start registry and bind the remote repository try { registry = LocateRegistry.getRegistry(url.getHost(), url.getPort()); registry.rebind(url.getName(), rmiRepository); // connection exception // happens here log.info("Using existing rmi server on " + url.getHost() + ":" + url.getPort()); } catch (ConnectException e) { registry = LocateRegistry.createRegistry(url.getPort()); registry.rebind(url.getName(), rmiRepository); log.info("Started an RMI registry on port " + url.getPort()); registryIsEmbedded = true; } } repositoryService = HippoServiceRegistry.getService(RepositoryService.class); if (repositoryService == null) { HippoServiceRegistry.registerService( repositoryService = (RepositoryService) repository.getRepository(), RepositoryService.class); } repositoryClusterService = HippoServiceRegistry.getService(RepositoryClusterService.class); if (repositoryClusterService == null) { HippoServiceRegistry.registerService(repositoryClusterService = new RepositoryClusterService() { @Override public boolean isExternalEvent(final Event event) { if (!(event instanceof JackrabbitEvent)) { throw new IllegalArgumentException("Event is not an instance of JackrabbitEvent"); } return ((JackrabbitEvent) event).isExternal(); } }, RepositoryClusterService.class); } } catch (MalformedURLException ex) { log.error("MalformedURLException exception: " + bindingAddress, ex); throw new ServletException("RemoteException: " + ex.getMessage()); } catch (RemoteException ex) { log.error("Generic remoting exception: " + bindingAddress, ex); throw new ServletException("RemoteException: " + ex.getMessage()); } catch (RepositoryException ex) { log.error("Error while setting up JCR repository: ", ex); throw new ServletException("RepositoryException: " + ex.getMessage()); } freeMarkerConfiguration = createFreemarkerConfiguration(); }
From source file:com.piketec.jenkins.plugins.tpt.Utils.java
private static TptApi connectToTPT(TptLogger logger, int tptPort, String tptBindingName, String hostName) throws RemoteException, NotBoundException, AccessException { Registry registry;/*w ww . j a v a 2s .c o m*/ registry = LocateRegistry.getRegistry(hostName, tptPort); TptApi remoteApi = (TptApi) registry.lookup(tptBindingName); try { logger.info("Connected to TPT \"" + remoteApi.getTptVersion() + "\""); } catch (ApiException e) { logger.error(e.getMessage()); // should not happen } return remoteApi; }
From source file:de.clusteval.serverclient.BackendClient.java
/** * Instantiates a new eval client./*from w ww . j a v a2 s. c om*/ * * <p> * If no port is specified in the options, the default 1099 will be used. * * <p> * If no ip is specified, the localhost will be used. * * <p> * If no clientId is specified, the client will retrieve a new one from the * server. * * @param params * The command line parameters for this client (see * {@link #params}). * * @throws ConnectException * @throws ParseException */ public BackendClient(final String[] params) throws ConnectException, ParseException { super(); this.log = LoggerFactory.getLogger(this.getClass()); try { this.params = parseParams(params, true); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ClustEvalFramework_Client.jar", "", clientCLIOptions, "Available commands are:", false); throw e; } /** * Keep a list of not parsed arguments. This has to be done, to maintain * the - of options passed, since they are not kept in the * CommandLine#args attribute. */ List<String> notParsedArgs = new ArrayList<String>(); for (String s : params) { String raw; if (s.startsWith("-")) raw = s.substring(1); else raw = s; if (this.params.getArgList().contains(raw) || this.params.getArgList().contains(s)) notParsedArgs.add(s); } this.args = notParsedArgs.toArray(new String[0]); if (this.params.hasOption("clientId")) this.clientId = this.params.getOptionValue("clientId"); if (this.params.hasOption("port")) this.port = this.params.getOptionValue("port"); else // default port this.port = "1099"; try { Registry registry; if (this.ip == null) registry = LocateRegistry.getRegistry(null, Integer.parseInt(this.port)); else registry = LocateRegistry.getRegistry(this.ip, Integer.parseInt(this.port)); server = (IBackendServer) registry.lookup("EvalServer"); if (this.clientId == null) this.clientId = server.getClientId(); this.log.debug("Connected to server using ClientId=" + this.clientId); } catch (ConnectException e) { this.log.error("Could not connect to server"); throw e; } catch (RemoteException e) { e.printStackTrace(); } catch (NotBoundException e) { e.printStackTrace(); } this.start(); }
From source file:de.tudarmstadt.lt.lm.app.StartLM.java
void startRMI() { // create own registry, alternative: use 'rmiregistry' command in class output folder try {/*from ww w . j ava 2 s. c o m*/ _registry = LocateRegistry.getRegistry(_host, _rmiRegistryPort); _registry.lookup(_name); } catch (RemoteException e) { try { _registry = LocateRegistry.createRegistry(_rmiRegistryPort); LOG.info("Publishing RMI."); } catch (RemoteException e1) { e1.printStackTrace(); exit(); } _app_serves_rmi_registry = true; } catch (NotBoundException e) { // That's what we want } LOG.info("Connected to RMI."); }
From source file:net.sqs2.omr.session.service.AbstractRemoteExecutorManager.java
private AbstractTaskTracker<T, D> createRemoteTaskTracker(String uriString, long remoteKey, long sessionID) { try {//from w ww.j ava2 s .c om 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:net.timewalker.ffmq4.jmx.rmi.JMXOverRMIAgent.java
private void init() throws JMSException { try {//from w w w . ja va 2s. c o m log.info("Starting JMX agent"); // Get or create an RMI registry if (rmiListenAddr == null || rmiListenAddr.equals("auto")) rmiListenAddr = InetAddress.getLocalHost().getHostName(); // Connector JNDI name String jndiName = "jmxconnector-" + agentName; try { registry = LocateRegistry.getRegistry(rmiListenAddr, jndiRmiPort); registry.lookup(jndiName); // Remove the old registered connector registry.unbind(jndiName); log.debug("RMI registry found at " + rmiListenAddr + ":" + jndiRmiPort + " with connector already registered"); } catch (NotBoundException e) { // Registry already exists log.debug("RMI registry found at " + rmiListenAddr + ":" + jndiRmiPort); } catch (RemoteException e) { log.debug("Creating RMI registry at " + rmiListenAddr + ":" + jndiRmiPort); RMIServerSocketFactory ssf = new JMXOverRMIServerSocketFactory(10, rmiListenAddr, false); registry = LocateRegistry.createRegistry(jndiRmiPort, null, ssf); } // Get the JVM MBean server mBeanServer = ManagementFactory.getPlatformMBeanServer(); // Service URL JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://" + rmiListenAddr + "/jndi/rmi://" + rmiListenAddr + ":" + jndiRmiPort + "/" + jndiName); log.info("JMX Service URL : " + url); // Create and start the RMIConnectorServer Map<String, Object> env = new HashMap<>(); mBeanServerSocketFactory = new JMXOverRMIServerSocketFactory(10, rmiListenAddr, true); env.put(RMIConnectorServer.JNDI_REBIND_ATTRIBUTE, "true"); //env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, new JMXRMIClientSocketFactory(rmiListenAddr)); env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, mBeanServerSocketFactory); connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mBeanServer); connectorServer.start(); } catch (Exception e) { throw new FFMQException("Could not initialize JMX agent", "JMX_ERROR", e); } }
From source file:org.apache.hadoop.distributedloadsimulator.sls.SLSRunner.java
private void getAllRemoteConnections() { Registry remoteRegistry = null; for (String rmiIp : listOfRMIIpAddress) { while (true) { try { remoteRegistry = LocateRegistry.getRegistry(rmiIp, rmiPort); AMNMCommonObject remoteConnection = (AMNMCommonObject) remoteRegistry .lookup("AMNMCommonObject"); remoteConnections.put(rmiIp, remoteConnection); break; } catch (RemoteException ex) { LOG.error(ex, ex);//from ww w. j a v a 2 s. c o m } catch (NotBoundException ex) { LOG.error(ex, ex); } } } }