Search in sources :

Example 36 with Registry

use of java.rmi.registry.Registry in project load-balancer by RestComm.

the class BlackholeAppServer method sendKeepAliveToBalancers.

private void sendKeepAliveToBalancers(ArrayList<SIPNode> info) {
    if (sendHeartbeat) {
        Thread.currentThread().setContextClassLoader(NodeRegisterRMIStub.class.getClassLoader());
        try {
            Registry registry = LocateRegistry.getRegistry(lbAddress, lbRMIport);
            NodeRegisterRMIStub reg = (NodeRegisterRMIStub) registry.lookup("SIPBalancer");
            reg.handlePing(info);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) SocketException(java.net.SocketException) NodeRegisterRMIStub(org.mobicents.tools.sip.balancer.NodeRegisterRMIStub)

Example 37 with Registry

use of java.rmi.registry.Registry in project load-balancer by RestComm.

the class BlackholeAppServer method sendCleanShutdownToBalancers.

public void sendCleanShutdownToBalancers(ArrayList<SIPNode> info) {
    Thread.currentThread().setContextClassLoader(NodeRegisterRMIStub.class.getClassLoader());
    try {
        Registry registry = LocateRegistry.getRegistry(lbAddress, lbRMIport);
        NodeRegisterRMIStub reg = (NodeRegisterRMIStub) registry.lookup("SIPBalancer");
        reg.forceRemoval(info);
        stop();
        // delay the OK for a while
        Thread.sleep(2000);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) SocketException(java.net.SocketException) NodeRegisterRMIStub(org.mobicents.tools.sip.balancer.NodeRegisterRMIStub)

Example 38 with Registry

use of java.rmi.registry.Registry in project load-balancer by RestComm.

the class AppServerWithRmi method sendKeepAliveToBalancers.

private void sendKeepAliveToBalancers(ArrayList<SIPNode> info) {
    if (sendHeartbeat) {
        Thread.currentThread().setContextClassLoader(NodeRegisterRMIStub.class.getClassLoader());
        if (balancers != null) {
            for (String balancer : balancers.replaceAll(" ", "").split(",")) {
                if (balancer.length() < 2)
                    continue;
                String host;
                String port;
                int semi = balancer.indexOf(':');
                if (semi > 0) {
                    host = balancer.substring(0, semi);
                    port = balancer.substring(semi + 1);
                } else {
                    host = balancer;
                    port = "2000";
                }
                try {
                    Registry registry = LocateRegistry.getRegistry(host, Integer.parseInt(port));
                    NodeRegisterRMIStub reg = (NodeRegisterRMIStub) registry.lookup("SIPBalancer");
                    reg.handlePing(info);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else {
            try {
                Registry registry = LocateRegistry.getRegistry(lbAddress, lbRMIport);
                NodeRegisterRMIStub reg = (NodeRegisterRMIStub) registry.lookup("SIPBalancer");
                reg.handlePing(info);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : LocateRegistry(java.rmi.registry.LocateRegistry) Registry(java.rmi.registry.Registry) NodeRegisterRMIStub(org.mobicents.tools.sip.balancer.NodeRegisterRMIStub)

Example 39 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 40 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)77 LocateRegistry (java.rmi.registry.LocateRegistry)71 RemoteException (java.rmi.RemoteException)35 Remote (java.rmi.Remote)12 HashMap (java.util.HashMap)9 JMXServiceURL (javax.management.remote.JMXServiceURL)9 IOException (java.io.IOException)8 JMXConnector (javax.management.remote.JMXConnector)8 UnknownHostException (java.net.UnknownHostException)7 MBeanServer (javax.management.MBeanServer)7 MBeanServerConnection (javax.management.MBeanServerConnection)7 JMXConnectorServer (javax.management.remote.JMXConnectorServer)7 ObjectName (javax.management.ObjectName)6 JMXPluggableAuthenticator (com.sun.jmx.remote.security.JMXPluggableAuthenticator)5 InetAddress (java.net.InetAddress)5 MalformedURLException (java.net.MalformedURLException)5 AlreadyBoundException (java.rmi.AlreadyBoundException)5 Properties (java.util.Properties)5 Attribute (javax.management.Attribute)5 Notification (javax.management.Notification)5