Example usage for java.rmi.registry LocateRegistry getRegistry

List of usage examples for java.rmi.registry LocateRegistry getRegistry

Introduction

In this page you can find the example usage for java.rmi.registry LocateRegistry getRegistry.

Prototype

public static Registry getRegistry(String host) throws RemoteException 

Source Link

Document

Returns a reference to the remote object Registry on the specified host on the default registry port of 1099.

Usage

From source file:mytubermiserver.MyTubeRMIClient.java

/**
 * @param args the command line arguments
 *///from w  w w.java  2s. com

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:client.ComputePi.java

public static void main(String args[]) {
    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new SecurityManager());
    }/*  w  w  w  . j av  a2s .  com*/
    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:engine.Pi.java

public static void main(String args[]) {
        if (System.getSecurityManager() == null) {
            System.setSecurityManager(new SecurityManager());
        }/* w w w .  jav a  2s .com*/
        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  w  ww.  j  av  a  2  s.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:puma.central.pdp.CentralPUMAPDP.java

public static void main(String[] args) {
    // initialize log4j
    BasicConfigurator.configure();// w ww.  j a v a2  s  .c  o  m

    CommandLineParser parser = new BasicParser();
    Options options = new Options();
    options.addOption("ph", "policy-home", true,
            "The folder where to find the policy file given with the given policy id. "
                    + "For default operation, this folder should contain the central PUMA policy (called "
                    + CENTRAL_PUMA_POLICY_FILENAME + ")");
    options.addOption("pid", "policy-id", true,
            "The id of the policy to be evaluated on decision requests. Default value: " + GLOBAL_PUMA_POLICY_ID
                    + ")");
    options.addOption("s", "log-disabled", true, "Verbose mode (true/false)");
    String policyHome = "";
    String policyId = "";

    // read command line
    try {
        CommandLine line = parser.parse(options, args);
        if (line.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Simple PDP Test", options);
            return;
        }
        if (line.hasOption("policy-home")) {
            policyHome = line.getOptionValue("policy-home");
        } else {
            logger.log(Level.WARNING, "Incorrect arguments given.");
            return;
        }
        if (line.hasOption("log-disabled") && Boolean.parseBoolean(line.getOptionValue("log-disabled"))) {
            logger.log(Level.INFO, "Now switching to silent mode");
            LogManager.getLogManager().getLogger("").setLevel(Level.WARNING);
            //LogManager.getLogManager().reset();
        }
        if (line.hasOption("policy-id")) {
            policyId = line.getOptionValue("policy-id");
        } else {
            logger.log(Level.INFO, "Using default policy id: " + GLOBAL_PUMA_POLICY_ID);
            policyId = GLOBAL_PUMA_POLICY_ID;
        }
    } catch (ParseException e) {
        logger.log(Level.WARNING, "Incorrect arguments given.", e);
        return;
    }

    //
    // STARTUP THE RMI SERVER
    //      
    // if (System.getSecurityManager() == null) {
    // System.setSecurityManager(new SecurityManager());
    // }
    final CentralPUMAPDP pdp;
    try {
        pdp = new CentralPUMAPDP(policyHome, policyId);
    } catch (IOException e) {
        logger.log(Level.SEVERE, "FAILED to set up the CentralPUMAPDP. Quitting.", e);
        return;
    }

    try {
        Registry registry;
        try {
            registry = LocateRegistry.createRegistry(RMI_REGISITRY_PORT);
            logger.info("Created new RMI registry");
        } catch (RemoteException e) {
            // MDC: I hope this means the registry already existed.
            registry = LocateRegistry.getRegistry(RMI_REGISITRY_PORT);
            logger.info("Reusing existing RMI registry");
        }
        CentralPUMAPDPRemote stub = (CentralPUMAPDPRemote) UnicastRemoteObject.exportObject(pdp, 0);
        registry.bind(CENTRAL_PUMA_PDP_RMI_NAME, stub);
        logger.info(
                "Central PUMA PDP up and running (available using RMI with name \"central-puma-pdp\" on RMI registry port "
                        + RMI_REGISITRY_PORT + ")");
        Thread.sleep(100); // MDC: vroeger eindigde de Thread om n of andere reden, dit lijkt te werken...
    } catch (Exception e) {
        logger.log(Level.SEVERE, "FAILED to set up PDP as RMI server", e);
    }

    //
    // STARTUP THE THRIFT PEP SERVER
    //
    //logger.log(Level.INFO, "Not setting up the Thrift server");

    // set up server
    //      PEPServer handler = new PEPServer(new CentralPUMAPEP(pdp));
    //      RemotePEPService.Processor<PEPServer> processor = new RemotePEPService.Processor<PEPServer>(handler);
    //      TServerTransport serverTransport;
    //      try {
    //         serverTransport = new TServerSocket(THRIFT_PEP_PORT);
    //      } catch (TTransportException e) {
    //         e.printStackTrace();
    //         return;
    //      }
    //      TServer server = new TSimpleServer(new TServer.Args(serverTransport).processor(processor));
    //      System.out.println("Setting up the Thrift PEP server on port " + THRIFT_PEP_PORT);
    //      server.serve();
    //
    // STARTUP THE THRIFT PEP SERVER
    //
    //logger.log(Level.INFO, "Not setting up the Thrift server");

    // set up server
    // do this in another thread not to block the main thread
    new Thread(new Runnable() {
        @Override
        public void run() {
            RemotePDPService.Processor<CentralPUMAPDP> pdpProcessor = new RemotePDPService.Processor<CentralPUMAPDP>(
                    pdp);
            TServerTransport pdpServerTransport;
            try {
                pdpServerTransport = new TServerSocket(THRIFT_PDP_PORT);
            } catch (TTransportException e) {
                e.printStackTrace();
                return;
            }
            TServer pdpServer = new TThreadPoolServer(
                    new TThreadPoolServer.Args(pdpServerTransport).processor(pdpProcessor));
            logger.info("Setting up the Thrift PDP server on port " + THRIFT_PDP_PORT);
            pdpServer.serve();
        }
    }).start();
}

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:org.brixcms.rmiserver.AbstractRmiExporterBean.java

public void afterPropertiesSet() throws Exception {
    try {/*from w  w  w . j  a  va 2  s .c o m*/
        registry = LocateRegistry.getRegistry(registryPort);
        registry.list();
    } catch (Exception e) {
        registry = LocateRegistry.createRegistry(registryPort);
        registry.list();
    }

    server = createServiceInstance();
    logger.info("Exporting " + server.getClass().getName() + " under: {}/{}", serviceName, registry);
    RemoteStub stub = UnicastRemoteObject.exportObject(server);
    registry.rebind(serviceName, stub);
    logger.info("Exported " + server.getClass().getName() + ": {}", stub);
}

From source file:org.brixcms.rmiserver.workspacemanager.WorkspaceManagerExporterBean.java

public void afterPropertiesSet() throws Exception {
    try {/*  www.ja  v a  2s  .c o m*/
        registry = LocateRegistry.getRegistry(registryPort);
        registry.list();
    } catch (Exception e) {
        registry = LocateRegistry.createRegistry(registryPort);
        registry.list();
    }

    logger.info("Exporting Workspace Manager under: {}/{}", serviceName, registry);
    server = new ServerWorkspaceManager(workspaceManager);
    RemoteStub stub = UnicastRemoteObject.exportObject(server);
    registry.rebind(serviceName, stub);
    logger.info("Exported Workspace Manager: {}", stub);
}

From source file:com.cisco.oss.foundation.monitoring.RegistryFinder.java

/**
 * @see org.springframework.beans.factory.FactoryBean#getObject()
 *//*from www  .  j  a v a2  s.  c  o m*/
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:org.brixcms.rmiserver.jackrabbit.RemoteRepositoryExporterBean.java

public void afterPropertiesSet() throws Exception {
    ServerAdapterFactory factory = new ServerAdapterFactory();
    remote = factory.getRemoteRepository(repository);

    registry = LocateRegistry.getRegistry(registryPort);
    try {// w ww  .  ja  v  a2  s .c  o  m
        registry.list(); // test registry
    } catch (Exception e) {
        registry = LocateRegistry.createRegistry(registryPort);
        registry.list(); // test registry
    }

    logger.info("Registring JackRabbit remote repository with name: {} and registry: {} ", serviceName,
            registry);

    registry.rebind(serviceName, remote);

    logger.info("JackRabbit remote server registered: " + remote);
}