Search in sources :

Example 61 with Registry

use of java.rmi.registry.Registry in project evosuite by EvoSuite.

the class OpenRegestryTest method openTest.

@Test
public void openTest() throws RemoteException, NotBoundException {
    int port = 2000;
    for (int i = 0; i < 10000; i++) {
        try {
            LocateRegistry.createRegistry(port);
            break;
        } catch (java.rmi.server.ExportException e) {
            // it could happen that the port is already in use
            port++;
        }
    }
    Registry registry = LocateRegistry.getRegistry(port);
    Assert.assertNotNull(registry);
    try {
        LocateRegistry.createRegistry(port);
        Assert.fail();
    } catch (Exception e) {
    }
    try {
        ServerSocket socket = new ServerSocket(port);
        Assert.fail();
    } catch (Exception e) {
    }
    FooImpl foo = new FooImpl();
    Ifoo stub = (Ifoo) UnicastRemoteObject.exportObject(foo, port);
    String service = "Foo";
    registry.rebind(service, stub);
    Ifoo lookedup = (Ifoo) registry.lookup(service);
    Assert.assertEquals("Hello World", lookedup.getString());
}
Also used : ServerSocket(java.net.ServerSocket) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) NotBoundException(java.rmi.NotBoundException) RemoteException(java.rmi.RemoteException) Test(org.junit.Test)

Example 62 with Registry

use of java.rmi.registry.Registry in project mdw-designer by CenturyLinkCloud.

the class DesignerDataAccess method sendRmiMessage.

// really send RMI message through rmi registry
private String sendRmiMessage(String engineUrl, String request) throws RemoteException {
    try {
        Registry registry;
        String host;
        int port;
        int k1 = engineUrl.indexOf("://");
        int k2 = engineUrl.indexOf(':', k1 + 4);
        int k3 = engineUrl.indexOf('/', k1 + 4);
        if (k2 > 0) {
            host = engineUrl.substring(k1 + 3, k2);
            if (k3 > 0)
                port = Integer.parseInt(engineUrl.substring(k2 + 1, k3));
            else
                port = Integer.parseInt(engineUrl.substring(k2 + 1));
            port += RMIListener.PORT_DIFF;
        } else {
            // well-known RMI registry port
            port = 1099;
            if (k3 > 0)
                host = engineUrl.substring(k1 + 3, k3);
            else
                host = engineUrl.substring(k1 + 3);
        }
        registry = LocateRegistry.getRegistry(host, port);
        RMIListener server = (RMIListener) registry.lookup(RMIListener.JNDI_NAME);
        return server.invoke(null, request);
    } catch (Exception e) {
        throw new RemoteException(e.getMessage(), e);
    }
}
Also used : RMIListener(com.centurylink.mdw.model.listener.RMIListener) Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry) RemoteException(java.rmi.RemoteException) JSONException(org.json.JSONException) SQLException(java.sql.SQLException) MDWException(com.centurylink.mdw.common.exception.MDWException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) MbengException(com.qwest.mbeng.MbengException) XmlException(org.apache.xmlbeans.XmlException) PropertyException(com.centurylink.mdw.common.exception.PropertyException) ActionCancelledException(com.centurylink.mdw.common.utilities.timer.ActionCancelledException) NamingException(javax.naming.NamingException) DataAccessOfflineException(com.centurylink.mdw.dataaccess.DataAccessOfflineException) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) FileNotFoundException(java.io.FileNotFoundException) RemoteException(java.rmi.RemoteException) CreateException(javax.ejb.CreateException)

Example 63 with Registry

use of java.rmi.registry.Registry in project groovy-core by groovy.

the class JmxConnectorHelper method createRmiRegistry.

public static Map createRmiRegistry(int initPort) {
    Map<String, Object> result = new HashMap<String, Object>(2);
    int counter = 0;
    int port = initPort;
    Registry reg = null;
    while (reg == null && counter <= 4) {
        try {
            reg = LocateRegistry.createRegistry(port);
            result.put("registry", reg);
            result.put("port", port);
            break;
        } catch (RemoteException ex) {
            counter++;
            port = port + 1;
            System.out.println("JmxBuilder - *** FAILED *** to create RMI Registry - Will Retry on port [" + port + "].");
            try {
                Thread.currentThread().sleep(500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) RemoteException(java.rmi.RemoteException)

Example 64 with Registry

use of java.rmi.registry.Registry in project che by eclipse.

the class RmiServer method start.

protected static void start(Remote remote) throws RemoteException {
    System.setProperty("java.rmi.server.hostname", "localhost");
    System.setProperty("java.rmi.server.disableHttp", "true");
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.eclipse.che.rmi.JNDI");
    if (RmiServer.remote != null) {
        throw new AssertionError("This server is already started!");
    }
    RmiServer.remote = remote;
    int port = -1;
    Random random = new Random();
    Registry registry = null;
    while (port == -1) {
        int tmpPort = random.nextInt(65535);
        if (tmpPort < 4000) {
            continue;
        }
        try {
            registry = LocateRegistry.createRegistry(tmpPort);
            port = tmpPort;
        } catch (ExportException ignored) {
        }
    }
    Remote exportObject = UnicastRemoteObject.exportObject(remote, port);
    String exportName = remote.getClass().getSimpleName() + Integer.toHexString(exportObject.hashCode());
    try {
        registry.bind(exportName, exportObject);
        String portName = port + "/" + exportName;
        System.out.println("Port/Name:" + portName);
        int twoMinutes = 2 * 60 * 1000;
        Object lock = new Object();
        while (true) {
            synchronized (lock) {
                lock.wait(twoMinutes);
            }
        // TODO add ping
        }
    } catch (AlreadyBoundException | InterruptedException e) {
        e.printStackTrace();
        System.exit(42);
    }
}
Also used : Random(java.util.Random) AlreadyBoundException(java.rmi.AlreadyBoundException) Remote(java.rmi.Remote) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) ExportException(java.rmi.server.ExportException)

Example 65 with Registry

use of java.rmi.registry.Registry in project tomcat by apache.

the class JmxRemoteLifecycleListener method createServer.

private JMXConnectorServer createServer(String serverName, String bindAddress, int theRmiRegistryPort, int theRmiServerPort, HashMap<String, Object> theEnv, RMIClientSocketFactory registryCsf, RMIServerSocketFactory registrySsf, RMIClientSocketFactory serverCsf, RMIServerSocketFactory serverSsf) {
    // Create the RMI registry
    Registry registry;
    try {
        registry = LocateRegistry.createRegistry(theRmiRegistryPort, registryCsf, registrySsf);
    } catch (RemoteException e) {
        log.error(sm.getString("jmxRemoteLifecycleListener.createRegistryFailed", serverName, Integer.toString(theRmiRegistryPort)), e);
        return null;
    }
    if (bindAddress == null) {
        bindAddress = "localhost";
    }
    String url = "service:jmx:rmi://" + bindAddress;
    JMXServiceURL serviceUrl;
    try {
        serviceUrl = new JMXServiceURL(url);
    } catch (MalformedURLException e) {
        log.error(sm.getString("jmxRemoteLifecycleListener.invalidURL", serverName, url), e);
        return null;
    }
    RMIConnectorServer cs = null;
    try {
        RMIJRMPServerImpl server = new RMIJRMPServerImpl(rmiServerPortPlatform, serverCsf, serverSsf, theEnv);
        cs = new RMIConnectorServer(serviceUrl, theEnv, server, ManagementFactory.getPlatformMBeanServer());
        cs.start();
        registry.bind("jmxrmi", server.toStub());
        log.info(sm.getString("jmxRemoteLifecycleListener.start", Integer.toString(theRmiRegistryPort), Integer.toString(theRmiServerPort), serverName));
    } catch (IOException | AlreadyBoundException e) {
        log.error(sm.getString("jmxRemoteLifecycleListener.createServerFailed", serverName), e);
    }
    return cs;
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) RMIJRMPServerImpl(javax.management.remote.rmi.RMIJRMPServerImpl) MalformedURLException(java.net.MalformedURLException) RMIConnectorServer(javax.management.remote.rmi.RMIConnectorServer) AlreadyBoundException(java.rmi.AlreadyBoundException) Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException)

Aggregations

Registry (java.rmi.registry.Registry)128 LocateRegistry (java.rmi.registry.LocateRegistry)119 RemoteException (java.rmi.RemoteException)43 IOException (java.io.IOException)20 Remote (java.rmi.Remote)16 NodeRegisterRMIStub (org.mobicents.tools.sip.balancer.NodeRegisterRMIStub)14 UnknownHostException (java.net.UnknownHostException)13 JMXServiceURL (javax.management.remote.JMXServiceURL)12 HashMap (java.util.HashMap)10 NotBoundException (java.rmi.NotBoundException)9 JMXConnector (javax.management.remote.JMXConnector)9 DistributedRMICounter (examples.mvc.rmi.duplex.DistributedRMICounter)8 SocketException (java.net.SocketException)8 AlreadyBoundException (java.rmi.AlreadyBoundException)8 MBeanServerConnection (javax.management.MBeanServerConnection)8 JMXConnectorServer (javax.management.remote.JMXConnectorServer)8 Test (org.junit.Test)8 MBeanServer (javax.management.MBeanServer)7 InetAddress (java.net.InetAddress)6 MalformedURLException (java.net.MalformedURLException)6