Example usage for java.rmi Naming lookup

List of usage examples for java.rmi Naming lookup

Introduction

In this page you can find the example usage for java.rmi Naming lookup.

Prototype

public static Remote lookup(String name)
        throws NotBoundException, java.net.MalformedURLException, RemoteException 

Source Link

Document

Returns a reference, a stub, for the remote object associated with the specified name.

Usage

From source file:org.olanto.mySelfQD.server.UploadServlet.java

private String convertFileWithRMI(byte[] bytes, String fileName) {
    String ret = "MYCAT: Seems not working, RMI server down?";
    _logger.info("Request to convert file: " + fileName);
    System.out.println("Request to convert file: " + fileName);

    try {//from www. j ava  2s  .  c o  m
        Remote r = Naming.lookup("rmi://localhost/CONVSRV");
        if (r instanceof ConvertService) {
            ConvertService is = (ConvertService) r;

            int pos = fileName.lastIndexOf('\\');
            if (pos >= 0) {
                fileName = fileName.substring(pos + 1);
            }

            ret = is.File2HtmlUTF8(bytes, fileName);
        } else {
            return "CONVSRV Service not found or not compatible.";
        }
    } catch (NotBoundException | MalformedURLException | RemoteException ex) {
        _logger.error(ex);
    }
    return ret;
}

From source file:org.red5.server.war.SubContextLoaderServlet.java

/**
 * Main entry point for the Red5 Server as a war
 *//*from   w w  w .ja v a 2 s .co  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:net.sf.ehcache.distribution.RMICacheManagerPeerProvider.java

/**
 * The use of one-time registry creation and Naming.rebind should mean we can create as many listeneres as we like.
 * They will simply replace the ones that were there.
 *//*from ww w. j a v  a  2s . c  o m*/
public CachePeer lookupRemoteCachePeer(String url)
        throws MalformedURLException, NotBoundException, RemoteException {
    return (CachePeer) Naming.lookup(url);
}

From source file:org.olanto.TranslationText.server.UploadServlet.java

private String convertFileWithRMI(byte[] bytes, String fileName) {
    String ret = "Warning: System seems to be unavailable, please contact the Translation Support Section";
    _logger.info("Request to convert file: " + fileName);
    System.out.println("Request to convert file: " + fileName);

    try {// w  w w  . j av a2s .  c o  m
        Remote r = Naming.lookup("rmi://localhost/CONVSRV");
        if (r instanceof ConvertService) {
            ConvertService is = (ConvertService) r;
            // ret = is.getInformation();

            int pos = fileName.lastIndexOf('\\');

            if (pos >= 0) {
                fileName = fileName.substring(pos + 1);
            }

            ret = is.File2Txt(bytes, fileName);
        } else {
            return "CONVSRV Service not found or not compatible.";
        }

    } catch (NotBoundException | MalformedURLException | RemoteException ex) {
        _logger.error(ex);
    }

    return ret;
}

From source file:com.xpn.xwiki.plugin.lucene.RemoteIndexesSearcher.java

private Searchable lookupRemote(String IPandPort, String name) throws Exception {
    return (Searchable) Naming.lookup("//" + IPandPort + "/" + name);
}

From source file:net.sf.mpaxs.spi.server.HostRegister.java

/**
 * Shutdown the host register.//from  ww  w.  j  a  va 2 s.  c o m
 *
 * @param timeout  maximum time to wait before hard shutdown
 * @param timeUnit time unit for timeout
 * @throws InterruptedException
 */
public void shutdown(long timeout, TimeUnit timeUnit) throws InterruptedException {
    HashMap<UUID, Host> hosts = getHosts();
    try {
        for (Iterator<UUID> i = hosts.keySet().iterator(); i.hasNext();) {
            Host host = hosts.get(i.next());
            IComputeHost remRef;
            try {

                remRef = (IComputeHost) Naming
                        .lookup("//" + host.getIP() + ":" + settings.getLocalPort() + "/" + host.getName());
                remRef.masterServerShuttingDown(
                        UUID.fromString(settings.getString(ConfigurationKeys.KEY_AUTH_TOKEN)));

            } catch (NotBoundException ex) {
                EventLogger.getInstance().getLogger().log(Level.SEVERE, "Not Bound Exception!", ex);
            } catch (MalformedURLException ex) {
                EventLogger.getInstance().getLogger().log(Level.SEVERE, "MalformedURLException!", ex);
            } catch (RemoteException ex) {
                EventLogger.getInstance().getLogger().log(Level.SEVERE, "RemoteException!", ex);
            }
        }
    } catch (Exception e) {
        EventLogger.getInstance().getLogger().log(Level.SEVERE, "Exception while shutting down hosts!", e);
        throw new RuntimeException(e);
    } finally {
        //we need to shut down the executor and event service
        //we can not throw the interrupted exceptions however, since
        //that would
        try {
            EventLogger.getInstance().getLogger().log(Level.INFO,
                    "Shutting down host register executor service");
            executorService.shutdown();
            if (!executorService.awaitTermination(timeout, timeUnit)) {
                executorService.shutdownNow();
            }
        } catch (InterruptedException ie) {
            executorService.shutdownNow();
            Thread.currentThread().interrupt();
        } finally {
            try {
                EventLogger.getInstance().getLogger().log(Level.INFO,
                        "Shutting down host register event service");
                eventService.shutdown();
                if (!eventService.awaitTermination(timeout, timeUnit)) {
                    eventService.shutdownNow();
                }
            } catch (InterruptedException ie) {
                eventService.shutdownNow();
                Thread.currentThread().interrupt();
            }
        }
    }
}

From source file:org.apache.jcs.auxiliary.remote.RemoteCacheManager.java

/**
 * Constructs an instance to with the given remote connection parameters. If the connection
 * cannot be made, "zombie" services will be temporarily used until a successful re-connection
 * is made by the monitoring daemon./*from  w w w .  j av  a2 s .  co  m*/
 * <p>
 * @param host
 * @param port
 * @param service
 * @param cacheMgr
 */
private RemoteCacheManager(String host, int port, String service, ICompositeCacheManager cacheMgr) {
    this.host = host;
    this.port = port;
    this.service = service;
    this.cacheMgr = cacheMgr;

    // register shutdown observer
    // TODO add the shutdown observable methods to the interface
    if (this.cacheMgr instanceof CompositeCacheManager) {
        ((CompositeCacheManager) this.cacheMgr).registerShutdownObserver(this);
    }

    this.registry = "//" + host + ":" + port + "/" + service;
    if (log.isDebugEnabled()) {
        log.debug("looking up server " + registry);
    }
    try {
        Object obj = Naming.lookup(registry);
        if (log.isDebugEnabled()) {
            log.debug("server found");
        }
        // Successful connection to the remote server.
        remoteService = (IRemoteCacheService) obj;
        if (log.isDebugEnabled()) {
            log.debug("remoteService = " + remoteService);
        }

        remoteWatch = new RemoteCacheWatchRepairable();
        remoteWatch.setCacheWatch((IRemoteCacheObserver) obj);
    } catch (Exception ex) {
        // Failed to connect to the remote server.
        // Configure this RemoteCacheManager instance to use the "zombie"
        // services.
        log.error("Problem finding server at [" + registry + "]", ex);
        remoteService = new ZombieRemoteCacheService();
        remoteWatch = new RemoteCacheWatchRepairable();
        remoteWatch.setCacheWatch(new ZombieRemoteCacheWatch());
        // Notify the cache monitor about the error, and kick off the
        // recovery process.
        RemoteCacheMonitor.getInstance().notifyError();
    }
}

From source file:edu.clemson.cs.nestbed.client.gui.MessageMonitorFrame.java

private final void lookupRemoteManagers() throws RemoteException, NotBoundException, MalformedURLException {

    messageManager = (MessageManager) Naming.lookup(RMI_BASE_URL + "MessageManager");

    progMsgSymManager = (ProgramMessageSymbolManager) Naming
            .lookup(RMI_BASE_URL + "ProgramMessageSymbolManager");
}

From source file:Peer.java

/**
* Used with trying to get a remote object to a peer.
* It will check a local cache for a the object and if it does exist
* it will ask the super peer for the location of the peer and store it.
* @return PeerInterface or null if some error occurs.
*//*from  w  w  w. j a  va2s.  c  o m*/
private PeerInterface getPeer(Key node) throws Exception {
    lg.log(Level.FINEST, "getPeer Entry");
    PeerInterface peer = peercache.get(node);
    try {
        if (peer == null) {
            lg.log(Level.FINER, "Peer " + node + " not found in cache asking superpeer.");
            String addy = superpeer.getAddress(node);
            lg.log(Level.FINER, "//" + addy + "/" + node.toString());
            if (addy != null) {
                peer = (PeerInterface) Naming.lookup("//" + addy + "/" + node.toString());

                peercache.put(node, peer);
            }

        } else
            lg.log(Level.FINER, "Peer " + node + " found in cache.");

    } catch (Exception e) {
        e.printStackTrace();
    }
    if (peer == null)
        lg.log(Level.WARNING, "getPeer attempt on " + node + " unsuccessful.");

    lg.log(Level.FINEST, "getPeer Exit");
    return peer;
}

From source file:xbird.engine.XQEngineClient.java

private synchronized void prepare() {
    if (engineRef == null) {
        final XQEngine ref;
        try {/*from   ww w . ja  v a 2s . c  o m*/
            ref = (XQEngine) Naming.lookup(remoteEndpoint);
        } catch (MalformedURLException mue) {
            LOG.error(mue);
            throw new IllegalStateException("lookup failed: " + remoteEndpoint, mue);
        } catch (RemoteException re) {
            LOG.error(re);
            throw new IllegalStateException("lookup failed: " + remoteEndpoint, re);
        } catch (NotBoundException nbe) {
            LOG.error(nbe);
            throw new IllegalStateException("lookup failed: " + remoteEndpoint, nbe);
        }
        this.engineRef = ref;
    }
}