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.act.index.server.MetaService.java

public int backupCore(Address dst, int coreId) {
    String name = "core" + coreId + "@server" + dst.getServerId();
    int port = dst.getAddr().getPort() + coreId + 1;
    String url = "rmi://" + dst.getAddr().getAddress().getHostAddress() + ":" + port + "/" + name;
    String path = ServerParam.SOLR_HOME + "/core" + coreId + "/data/index/";
    FileSelection dir = new FileSelection(path, coreId);
    dir.doBackup(dst.getAddr().getAddress(), dst.getAddr().getPort() - 1);
    try {//from  w  w  w  . ja  va  2s .co  m
        ISolrService solrService = (ISolrService) Naming.lookup(url);
        solrService.commit();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NotBoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return GlobalMessage.ISS_SUCCESS;
}

From source file:se.trixon.jota.client.Client.java

void connectToServer() throws NotBoundException, MalformedURLException, RemoteException,
        java.rmi.ConnectException, java.rmi.ConnectIOException, java.rmi.UnknownHostException, SocketException {
    mRmiNameServer = JotaHelper.getRmiName(mHost, mPortHost, JotaServer.class);
    mServerCommander = (ServerCommander) Naming.lookup(mRmiNameServer);
    mManager.setServerCommander(mServerCommander);
    mClientVmid = new VMID();

    Xlog.timedOut(String.format("server found at %s.", mRmiNameServer));
    Xlog.timedOut(String.format("server vmid: %s", mServerCommander.getVMID()));
    Xlog.timedOut(String.format("client connected to %s", mRmiNameServer));
    Xlog.timedOut(String.format("client vmid: %s", mClientVmid.toString()));

    mServerCommander.registerClient(this, SystemHelper.getHostname());
}

From source file:com.stimulus.archiva.search.StandardSearch.java

protected Searcher getVolumeSearchers() throws MessageSearchException {

    logger.debug("getVolumeSearchers()");
    boolean searcherPresent = false;
    Hashtable<String, String> remoteServers = new Hashtable<String, String>();
    List<Volume> volumes = Config.getConfig().getVolumes().getVolumes();
    LinkedList<Searchable> searchers = new LinkedList<Searchable>();
    Iterator<Volume> vl = volumes.iterator();
    logger.debug("searching for suitable searchers");
    while (vl.hasNext()) {
        Volume volume = (Volume) vl.next();
        logger.debug("should search volume? {" + volume + "}");
        try {/*from w w  w . j  a v  a  2  s.  c om*/
            Searchable volsearcher;
            if (shouldSearch(volume)) {
                try {
                    volsearcher = new IndexSearcher(volume.getIndexPath());
                    logger.debug("adding volume to search {indexpath='" + volume.getIndexPath() + "'}");
                    searchers.add(volsearcher);
                    searcherPresent = true;
                } catch (Exception e) {
                    logger.error("failed to volume to search{" + volume + "}: " + e.getMessage(), e);
                }
            } else {
                logger.debug("deliberately not searching inside volume {" + volume.getIndexPath() + "}");
            }
        } catch (Exception io) {
            logger.error("failed to open index for search {" + volume + "}.", io);
        }

    }

    if (!searcherPresent)
        return null;

    for (String remotePath : remoteServers.values()) {
        try {
            Searchable volsearcher = (Searchable) Naming.lookup(remotePath);
            searchers.add(volsearcher);
        } catch (Exception e) {
            logger.error("failed to add volume searcher", e);
        }
    }
    Searchable[] searcherarraytype = new Searchable[searchers.size()];
    Searchable[] allsearchers = (Searchable[]) (searchers.toArray(searcherarraytype));

    Searcher searcher;
    try {
        searcher = new ParallelMultiSearcher(allsearchers);
    } catch (IOException io) {
        throw new MessageSearchException("failed to open/create one or more index searchers", logger);
    }
    return searcher;
}

From source file:com.vmware.identity.SharedUtils.java

private ILoginManager getLoginManager() throws NotBoundException, MalformedURLException, RemoteException {
    String endpointURL = String.format("rmi://%s:%d/IdentityManager", this._realIdmHostName, Tenant.RMI_PORT);

    boolean bNotBound = false;
    boolean bRemoteException = false;

    for (int i = 0; i < RETRY_COUNT; i++) {
        bNotBound = false;//from ww w.  j  av a 2s  . co m
        bRemoteException = false;

        try {
            return (ILoginManager) Naming.lookup(endpointURL);
        } catch (NotBoundException e) {
            bNotBound = true;
        } catch (RemoteException e) {
            bRemoteException = true;
        }

        try {
            Thread.sleep(RETRY_TIMEOUT_SECS * 1000);
        } catch (InterruptedException e) {
        }
    }

    if (bNotBound) {
        throw new NotBoundException(
                String.format("Failed to bind to [%s] after [%d] attempts", endpointURL, RETRY_COUNT));
    } else if (bRemoteException) {
        throw new RemoteException(
                String.format("Failed due to remote exception when looking up " + "[%s] after [%d] attempts",
                        endpointURL, RETRY_COUNT));
    } else {
        throw new RuntimeException(
                String.format("Failed to contact [%s] after [%d] attempts", endpointURL, RETRY_COUNT));
    }
}

From source file:je3.rmi.MudClient.java

 /** 
  * This remote method moves the specified RemoteMudPerson from this place
  * in the named direction (i.e. through the named exit) to whatever place
  * is there.  It throws exceptions if the specified person isn't in this
  * place to begin with, or if they are already in the place through the 
  * exit or if the exit doesn't exist, or if the exit links to another MUD 
  * server and the server is not functioning.
  **///from   www  . j  a  v a2 s  . c om
 public RemoteMudPlace go(RemoteMudPerson who, String direction) 
throws RemoteException, NotThere, AlreadyThere, NoSuchExit, LinkFailed
 {
     // Make sure the direction is valid, and get destination if it is
     Object destination;
     synchronized(exits) {
         int i = exits.indexOf(direction);
         if (i == -1) throw new NoSuchExit();
         destination = destinations.elementAt(i);
     }
   
     // If destination is a string, it is a place on another server, so
     // connect to that server.  Otherwise, it is a place already on this
     // server.  Throw an exception if we can't connect to the server.
     RemoteMudPlace newplace;
     if (destination instanceof String) {
         try { 
             String t = (String) destination;
             int pos = t.indexOf('@');
             String url = t.substring(0, pos);
             String placename = t.substring(pos+1);
             RemoteMudServer s = (RemoteMudServer) Naming.lookup(url);
             newplace = s.getNamedPlace(placename);
         } 
         catch (Exception e) { throw new LinkFailed(); } 
     }
     // If the destination is not a string, then it is a Place
     else newplace = (RemoteMudPlace) destination;
   
     // Make sure the person is here and get their name.  
     // Throw an exception if they are not here
     String name = verifyPresence(who);
   
     // Move the person out of here, and tell everyone who remains about it.
     this.exit(who, name + " has gone " + direction);
   
     // Put the person into the new place.  
     // Send a message to everyone already in that new place
     String fromwhere;
     if (newplace instanceof MudPlace) // going to a local place
         fromwhere = placename;
     else
         fromwhere = server.getMudName() + "." + placename;
     newplace.enter(who, name, name + " has arrived from: " + fromwhere);
   
     // Return the new RemoteMudPlace object to the client so they
     // know where they are now at.
     return newplace;
 }

From source file:je3.rmi.MudClient.java

 /**
  * Create a new exit from this mud, linked to a named place in a named
  * MUD on a named host (this can also be used to link to a named place in 
  * the current MUD, of course).  Because of the possibilities of deadlock,
  * this method only links from here to there; it does not create a return
  * exit from there to here.  That must be done with a separate call.
  **///from  www  .  j  ava  2 s.  c om
 public void linkTo(RemoteMudPerson linker, String exit, 
          String hostname, String mudname, String placename) 
throws RemoteException, NotThere, ExitAlreadyExists, NoSuchPlace
 {
     // Verify that the linker is actually here 
     String name = verifyPresence(linker);
   
     // Check that the link target actually exists.  Throw NoSuchPlace if
     // not.  Note that NoSuchPlace may also mean "NoSuchMud" or
     // "MudNotResponding".
     String url = "rmi://" + hostname + '/' + Mud.mudPrefix + mudname;
     try {
         RemoteMudServer s = (RemoteMudServer) Naming.lookup(url);
         RemoteMudPlace destination = s.getNamedPlace(placename);
     }
     catch (Exception e) { throw new NoSuchPlace(); }
        
     synchronized(exits) {
         // Check that the exit doesn't already exist.
         if (exits.indexOf(exit) != -1) throw new ExitAlreadyExists();
         // Add the exit, to the list of exit names
         exits.addElement(exit);
         // And add the destination to the list of destinations.  Note that
         // the destination is stored as a string rather than as a
         // RemoteMudPlace.  This is because if the remote server goes down
         // then comes back up again, a RemoteMudPlace is not valid, but the
         // string still is.
         destinations.addElement(url + '@' + placename);
     }
     // Let everyone know about the new exit and where it leads
     tellEveryone(name + " has linked " + exit + " to " + 
        "'" + placename + "' in MUD '" + mudname + 
        "' on host " + hostname);
 }