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