Example usage for java.rmi.registry Registry lookup

List of usage examples for java.rmi.registry Registry lookup

Introduction

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

Prototype

public Remote lookup(String name) throws RemoteException, NotBoundException, AccessException;

Source Link

Document

Returns the remote reference bound to the specified name in this registry.

Usage

From source file:client.ComputePi.java

public static void main(String args[]) {
    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new SecurityManager());
    }//from   w w w  .j  a v a 2 s. c  o m
    try {
        String name = "Compute";
        Registry registry = LocateRegistry.getRegistry(args[0]);
        Compute comp = (Compute) registry.lookup(name);
        Pi task = new Pi(Integer.parseInt(args[1]));
        BigDecimal pi = comp.executeTask(task);
        System.out.println(pi);
    } catch (Exception e) {
        System.err.println("ComputePi exception:");
        e.printStackTrace();
    }
}

From source file:mytubermiserver.MyTubeRMIClient.java

/**
 * @param args the command line arguments
 */// w w w  .  ja  v  a  2 s.c  o  m

public static void main(String[] args) {

    System.setProperty("com.healthmarketscience.rmiio.exporter.port", "6667");

    try {
        Registry registry = LocateRegistry.getRegistry("192.168.0.145"); //ENDERECO
        Server server = (Server) registry.lookup("MyTubeRMI");

        System.out.println(server.testConnection());
        /*
                    //ENVIAR ARQUIVO PRO SERVER
                            
                    InputStream istream = new FileInputStream("e://music.mp3");
                    // call server (note export() call to get actual remote interface)
                    OutputStream ostream = RemoteOutputStreamClient.wrap(server.uploadOutputStream("arthur"));
                
                    ostream.write(IOUtils.toByteArray(istream));
                    ostream.flush();            
                    ostream.close();
                          
                    server.saveInDatabase("arthur");
                    */
        //RECEBER ARQUIVO DO SERVER
        InputStream istreamSaida = RemoteInputStreamClient.wrap(server.getFile("aaa"));

        int read;
        try (FileOutputStream out = new FileOutputStream("e:/music2.jpg")) {
            byte[] bytes = new byte[1024];
            while ((read = istreamSaida.read(bytes)) != -1) {
                out.write(bytes, 0, read);
            }
            out.close();
        }

    } catch (RemoteException | NotBoundException e) {
        System.out.println("Exception: " + e);
    } catch (IOException ex) {
        System.out.println("Exception: " + ex);
    }

}

From source file:engine.Pi.java

public static void main(String args[]) {
        if (System.getSecurityManager() == null) {
            System.setSecurityManager(new SecurityManager());
        }/*from  w w  w .  java 2s.c om*/
        try {
            String name = "Compute";
            Registry registry = LocateRegistry.getRegistry(args[0]);
            Compute comp = (Compute) registry.lookup(name);
            Pi task = new Pi(Integer.parseInt(args[1]));
            BigDecimal pi = comp.executeTask(task);
            System.out.println(pi);
        } catch (Exception e) {
            System.err.println("ComputePi exception:");
            e.printStackTrace();
        }
    }

From source file:uk.co.moonsit.rmi.GraphClient.java

@SuppressWarnings("SleepWhileInLoop")
public static void main(String args[]) {
    Properties p = new Properties();
    try {//from  ww w  .j  a va  2s .c om
        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.piketec.jenkins.plugins.tpt.Utils.java

private static TptApi connectToTPT(TptLogger logger, int tptPort, String tptBindingName, String hostName)
        throws RemoteException, NotBoundException, AccessException {
    Registry registry;
    registry = LocateRegistry.getRegistry(hostName, tptPort);
    TptApi remoteApi = (TptApi) registry.lookup(tptBindingName);
    try {/*from   w w w.  jav a 2 s.c  o  m*/
        logger.info("Connected to TPT \"" + remoteApi.getTptVersion() + "\"");
    } catch (ApiException e) {
        logger.error(e.getMessage());
        // should not happen
    }
    return remoteApi;
}

From source file:mytubermiserver.RMIClient.java

public RMIClient(String address, String registryName) throws RemoteException, NotBoundException {
    System.setProperty("com.healthmarketscience.rmiio.exporter.port", "6667");
    Registry registry = LocateRegistry.getRegistry(address);
    server = (Server) registry.lookup(registryName);
}

From source file:de.tudarmstadt.lt.lm.web.servlet.LanguageModelProviderServlet.java

private boolean connectToLanguageModel(String key) throws Exception {
    try {/* w  w  w.j  a  v a  2 s .com*/
        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:de.tudarmstadt.lt.lm.app.ListServices.java

@Override
public void run() {
    String[] services = new String[] {};
    Registry registry = null;
    try {/*from   w  ww .j  a v a 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 w  w w.ja  v a 2s  . c  om*/
            _perp_processors.add(null);
        }
    }
}

From source file:de.clusteval.serverclient.BackendClient.java

/**
 * Instantiates a new eval client./*from w w w. ja va 2s .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();
}