use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.
the class LookupIPv6 method main.
public static void main(String[] args) throws Exception {
// use loopback IPv6 address to avoid lengthy socket connection delays
String[] urls = { "rmi://[0000:0000:0000:0000:0000:0000:0000:0001]/foo", "//[0:0:0:0:0:0:0:1]:88/foo", "rmi://[0::0:0:0:1]/foo:bar", "//[::1]:88" };
for (int i = 0; i < urls.length; i++) {
try {
Naming.lookup(urls[i]);
} catch (MalformedURLException ex) {
throw ex;
} catch (Exception ex) {
// URLs are bogus, lookups expected to fail
}
}
/* Attempt to use IPv6-based URL to look up object in local registry.
* Since not all platforms support IPv6, this portion of the test may
* be a no-op in some cases. On supporting platforms, the first
* element of the array returned by InetAddress.getAllByName should be
* an Inet6Address since this test is run with
* -Djava.net.preferIPv6Addresses=true.
*/
InetAddress localAddr = InetAddress.getAllByName(null)[0];
if (localAddr instanceof Inet6Address) {
System.out.println("IPv6 detected");
Registry reg;
try {
reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
} catch (Exception ex) {
reg = LocateRegistry.getRegistry();
}
reg.rebind("foo", reg);
Naming.lookup("rmi://[" + localAddr.getHostAddress() + "]/foo");
}
}
use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.
the class LookupNameWithColon method main.
public static void main(String[] args) throws Exception {
String[] names = { "fairly:simple", "somewhat:more/complicated", "multiple:colons:in:name" };
Registry reg = TestLibrary.createRegistryOnUnusedPort();
int port = TestLibrary.getRegistryPort(reg);
for (int i = 0; i < names.length; i++) {
reg.rebind(names[i], reg);
Naming.lookup("rmi://localhost:" + port + "/" + names[i]);
}
}
use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.
the class RMISocketFactoriesTest method main.
public static void main(String[] args) {
System.out.println("Test RMI factories : " + args[0]);
try {
// Create an RMI registry
//
System.out.println("Start RMI registry...");
Registry reg = null;
int port = 5800;
while (port++ < 6000) {
try {
reg = LocateRegistry.createRegistry(port);
System.out.println("RMI registry running on port " + port);
break;
} catch (RemoteException e) {
// Failed to create RMI registry...
System.out.println("Failed to create RMI registry " + "on port " + port);
}
}
if (reg == null) {
System.exit(1);
}
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Initialize environment map to be passed to the connector server
//
System.out.println("Initialize environment map");
HashMap env = new HashMap();
env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, new RMIServerFactory(args[0]));
env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, new RMIClientFactory(args[0]));
// Create an RMI connector server
//
System.out.println("Create an RMI connector server");
JMXServiceURL url = new JMXServiceURL("rmi", null, 0, "/jndi/rmi://:" + port + "/server" + port);
JMXConnectorServer rcs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
rcs.start();
// Create an RMI connector client
//
System.out.println("Create an RMI connector client");
JMXConnector jmxc = JMXConnectorFactory.connect(url, new HashMap());
// If this line is executed then the test failed
//
System.exit(1);
} catch (Exception e) {
if (e.getMessage().equals(args[0])) {
System.out.println("Expected exception caught = " + e);
System.out.println("Bye! Bye!");
} else {
System.out.println("Unexpected exception caught = " + e);
e.printStackTrace();
System.exit(1);
}
}
}
use of java.rmi.registry.Registry in project jdk8u_jdk by JetBrains.
the class AppleUserImpl method main.
/**
* Entry point for the "juicer" server process. Create and export
* an apple user implementation in an rmiregistry running on localhost.
*/
public static void main(String[] args) {
//TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
long startTime = 0;
String durationString = null;
// parse command line args
try {
for (int i = 0; i < args.length; i++) {
String arg = args[i];
if (arg.equals("-hours")) {
if (durationString != null) {
usage();
}
i++;
int hours = Integer.parseInt(args[i]);
durationString = hours + " hours";
testDuration = hours * 60 * 60 * 1000;
} else if (arg.equals("-seconds")) {
if (durationString != null) {
usage();
}
i++;
long seconds = Long.parseLong(args[i]);
durationString = seconds + " seconds";
testDuration = seconds * 1000;
} else if (arg.equals("-maxLevel")) {
i++;
maxLevel = Integer.parseInt(args[i]);
} else {
usage();
}
}
if (durationString == null) {
durationString = testDuration + " milliseconds";
}
} catch (Throwable t) {
usage();
}
AppleUserImpl user = null;
try {
user = new AppleUserImpl();
} catch (RemoteException e) {
//TestLibrary.bomb("Failed to create AppleUser", e);
}
synchronized (user) {
int port = -1;
// create new registry and bind new AppleUserImpl in registry
try {
Registry registry = TestLibrary.createRegistryOnUnusedPort();
port = TestLibrary.getRegistryPort(registry);
Naming.rebind("rmi://localhost:" + port + "/AppleUser", user);
} catch (RemoteException e) {
//TestLibrary.bomb("Failed to bind AppleUser", e);
} catch (java.net.MalformedURLException e) {
//TestLibrary.bomb("Failed to bind AppleUser", e);
}
// start the other server if available
try {
Class app = Class.forName("ApplicationServer");
java.lang.reflect.Constructor appConstructor = app.getDeclaredConstructor(new Class[] { Integer.TYPE });
server = new Thread((Runnable) appConstructor.newInstance(port));
} catch (ClassNotFoundException e) {
// assume the other server is running in a separate process
logger.log(Level.INFO, "Application server must be " + "started in separate process");
} catch (Exception ie) {
//TestLibrary.bomb("Could not instantiate server", ie);
}
// wait for other server to call startTest method
try {
logger.log(Level.INFO, "Waiting for application server " + "process to start");
user.wait();
} catch (InterruptedException ie) {
//TestLibrary.bomb("AppleUserImpl interrupted", ie);
}
}
startTime = System.currentTimeMillis();
logger.log(Level.INFO, "Test starting");
// wait for exception to be reported or first thread to complete
try {
logger.log(Level.INFO, "Waiting " + durationString + " for " + "test to complete or exception to be thrown");
synchronized (AppleUserImpl.class) {
AppleUserImpl.class.wait();
}
if (status != null) {
//TestLibrary.bomb("juicer server reported an exception", status);
} else {
logger.log(Level.INFO, "TEST PASSED");
}
} catch (Exception e) {
logger.log(Level.INFO, "TEST FAILED");
//TestLibrary.bomb("unexpected exception", e);
} finally {
logger.log(Level.INFO, "Test finished");
long actualDuration = System.currentTimeMillis() - startTime;
logger.log(Level.INFO, "Test duration was " + (actualDuration / 1000) + " seconds " + "(" + (actualDuration / 3600000) + " hours)");
}
}
use of java.rmi.registry.Registry in project jmeter by apache.
the class RemoteJMeterEngineImpl method rexit.
/*
* Called by:
* - ClientJMeterEngine.exe() which is called on remoteStop
*/
@Override
public void rexit() throws RemoteException {
log.info("Exiting");
// Bug 59400 - allow rexit() to return
Thread et = new Thread() {
@Override
public void run() {
log.info("Stopping the backing engine");
backingEngine.exit();
}
};
et.setDaemon(false);
// Tidy up any objects we created
Registry reg = LocateRegistry.getRegistry(this.rmiPort);
try {
reg.unbind(JMETER_ENGINE_RMI_NAME);
} catch (NotBoundException e) {
log.warn("{} is not bound", JMETER_ENGINE_RMI_NAME, e);
}
log.info("Unbound from registry");
// Help with garbage control
JMeterUtils.helpGC();
et.start();
}
Aggregations