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();
}
}
}
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();
}
}
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();
}
}
}
}
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);
}
}
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;
}
Aggregations