use of java.rmi.registry.Registry in project groovy by apache.
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 intellij-community by JetBrains.
the class RemoteProcessSupport method acquire.
private EntryPoint acquire(final RunningInfo port) throws Exception {
EntryPoint result = RemoteUtil.executeWithClassLoader(() -> {
Registry registry = LocateRegistry.getRegistry("localhost", port.port);
Remote remote = ObjectUtils.assertNotNull(registry.lookup(port.name));
if (Remote.class.isAssignableFrom(myValueClass)) {
EntryPoint entryPoint = narrowImpl(remote, myValueClass);
if (entryPoint == null)
return null;
return RemoteUtil.substituteClassLoader(entryPoint, myValueClass.getClassLoader());
} else {
return RemoteUtil.castToLocal(remote, myValueClass);
}
}, // should be the loader of client plugin
getClass().getClassLoader());
// init hard ref that will keep it from DGC and thus preventing from System.exit
port.entryPointHardRef = result;
return result;
}
use of java.rmi.registry.Registry in project intellij-community by JetBrains.
the class RemoteServer method start.
@SuppressWarnings("UseOfSystemOutOrSystemErr")
protected static void start(Remote remote) throws Exception {
setupRMI();
banJNDI();
setupSSL();
setupDomainAuth();
if (ourRemote != null)
throw new AssertionError("Already started");
ourRemote = remote;
Registry registry;
int port;
for (Random random = new Random(); ; ) {
port = random.nextInt(0xffff);
if (port < 4000)
continue;
try {
registry = LocateRegistry.createRegistry(port);
break;
} catch (ExportException ignored) {
}
}
try {
Remote stub = UnicastRemoteObject.exportObject(ourRemote, 0);
final String name = remote.getClass().getSimpleName() + Integer.toHexString(stub.hashCode());
registry.bind(name, stub);
String id = port + "/" + name;
System.out.println("Port/ID: " + id);
long waitTime = RemoteDeadHand.PING_TIMEOUT;
Object lock = new Object();
//noinspection InfiniteLoopStatement
while (true) {
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (lock) {
lock.wait(waitTime);
}
RemoteDeadHand deadHand = (RemoteDeadHand) registry.lookup(RemoteDeadHand.BINDING_NAME);
waitTime = deadHand.ping(id);
}
} catch (Throwable e) {
e.printStackTrace(System.err);
System.exit(1);
}
}
use of java.rmi.registry.Registry in project opennms by OpenNMS.
the class JmxRemoteAdminIT method canConnect.
@Test
public void canConnect() throws Exception {
final InetSocketAddress addr = m_testEnvironment.getServiceAddress(ContainerAlias.OPENNMS, 18980);
final String hostString = "localhost".equals(addr.getHostString()) ? "127.0.0.1" : addr.getHostString();
final int port = addr.getPort();
final RMISocketFactory socketFactory = new JMXTestClientSocketFactory();
System.setProperty("sun.rmi.transport.tcp.responseTimeout", "5000");
final Callable<Integer> getRmiConnection = new Callable<Integer>() {
@Override
public Integer call() throws Exception {
LOG.debug("getRmiConnection({}:{})", hostString, port);
try {
final Registry registry = LocateRegistry.getRegistry(hostString, port, socketFactory);
final String[] bound = registry.list();
LOG.debug("bound={}", Arrays.asList(bound));
if (bound.length > 0) {
return bound.length;
}
} catch (final Exception e) {
}
return null;
}
};
await().atMost(5, MINUTES).pollInterval(10, SECONDS).until(getRmiConnection, greaterThanOrEqualTo(1));
final Callable<Integer> getJmxConnection = new Callable<Integer>() {
@Override
public Integer call() throws Exception {
LOG.debug("getJmxConnection({}:{})", hostString, port);
try {
RMISocketFactory.setSocketFactory(socketFactory);
final Map<String, Object> env = new HashMap<>();
final String[] credentials = { "admin", "admin" };
env.put(JMXConnector.CREDENTIALS, credentials);
env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, socketFactory);
final String urlString = String.format("service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi", hostString, port);
LOG.debug("getJmxConnection(): connecting to {}", urlString);
final JMXServiceURL url = new JMXServiceURL(urlString);
final JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
final MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
LOG.debug("mbeanCount={}", mbsc.getMBeanCount());
if (mbsc.getMBeanCount() > 0) {
return mbsc.getMBeanCount();
}
} catch (final Exception e) {
}
return null;
}
};
await().atMost(5, MINUTES).pollInterval(10, SECONDS).until(getJmxConnection, greaterThanOrEqualTo(1));
}
use of java.rmi.registry.Registry in project camel by apache.
the class JmxInstrumentationWithConnectorTest method testRmiRegistryUnexported.
public void testRmiRegistryUnexported() throws Exception {
Registry registry = LocateRegistry.getRegistry(registryPort);
// before we stop the context the registry is still exported, so list() should work
Exception e;
try {
registry.list();
e = null;
} catch (NoSuchObjectException nsoe) {
e = nsoe;
}
assertNull(e);
// stop the Camel context
context.stop();
// stopping the Camel context unexported the registry, so list() should fail
Exception e2;
try {
registry.list();
e2 = null;
} catch (NoSuchObjectException nsoe) {
e2 = nsoe;
}
assertNotNull(e2);
}
Aggregations