use of java.rmi.RemoteException 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.RemoteException 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.RemoteException in project jdk8u_jdk by JetBrains.
the class FilterUSRTest method UnicastServerRef.
/*
* Test exporting an object with a serialFilter using UnicastServerRef.exportObject().
* Send some objects and check the number of calls to the serialFilter.
*/
@Test(dataProvider = "bindData")
public void UnicastServerRef(String name, Object obj, int expectedFilterCount) throws RemoteException {
try {
RemoteImpl impl = RemoteImpl.create();
UnicastServerRef ref = new UnicastServerRef(new LiveRef(0), impl.checker);
Echo client = (Echo) ref.exportObject(impl, null, false);
int count = client.filterCount(obj);
System.out.printf("count: %d, obj: %s%n", count, obj);
Assert.assertEquals(count, expectedFilterCount, "wrong number of filter calls");
} catch (RemoteException rex) {
if (expectedFilterCount == -1 && UnmarshalException.class.equals(rex.getCause().getClass()) && InvalidClassException.class.equals(rex.getCause().getCause().getClass())) {
// normal expected exception
return;
}
rex.printStackTrace();
Assert.fail("unexpected remote exception", rex);
} catch (Exception ex) {
Assert.fail("unexpected exception", ex);
}
}
use of java.rmi.RemoteException 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.RemoteException in project jdk8u_jdk by JetBrains.
the class RuntimeThreadInheritanceLeak method main.
public static void main(String[] args) {
System.err.println("\nRegression test for bug 4404702\n");
/*
* HACK: Work around the fact that java.util.logging.LogManager's
* (singleton) construction also has this bug-- it will register a
* "shutdown hook", i.e. a thread, which will inherit and pin the
* current thread's context class loader for the lifetime of the VM--
* by causing the LogManager to be initialized now, instead of by
* RMI when our special context class loader is set.
*/
java.util.logging.LogManager.getLogManager();
/*
* HACK: Work around the fact that the non-native, thread-based
* SecureRandom seed generator (ThreadedSeedGenerator) seems to
* have this bug too (which had been causing this test to fail
* when run with jtreg on Windows XP-- see 4910382).
*/
(new java.security.SecureRandom()).nextInt();
RuntimeThreadInheritanceLeak obj = new RuntimeThreadInheritanceLeak();
try {
ClassLoader loader = URLClassLoader.newInstance(new URL[0]);
ReferenceQueue refQueue = new ReferenceQueue();
Reference loaderRef = new WeakReference(loader, refQueue);
System.err.println("created loader: " + loader);
Thread.currentThread().setContextClassLoader(loader);
UnicastRemoteObject.exportObject(obj);
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
System.err.println("exported remote object with loader as context class loader");
loader = null;
System.err.println("nulled strong reference to loader");
UnicastRemoteObject.unexportObject(obj, true);
System.err.println("unexported remote object");
/*
* HACK: Work around the fact that the sun.misc.GC daemon thread
* also has this bug-- it will have inherited our loader as its
* context class loader-- by giving it a chance to pass away.
*/
Thread.sleep(2000);
System.gc();
System.err.println("waiting to be notified of loader being weakly reachable...");
Reference dequeued = refQueue.remove(TIMEOUT);
if (dequeued == null) {
System.err.println("TEST FAILED: loader not deteced weakly reachable");
dumpThreads();
throw new RuntimeException("TEST FAILED: loader not detected weakly reachable");
}
System.err.println("TEST PASSED: loader detected weakly reachable");
dumpThreads();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException("TEST FAILED: unexpected exception", e);
} finally {
try {
UnicastRemoteObject.unexportObject(obj, true);
} catch (RemoteException e) {
}
}
}
Aggregations