test/java/rmi/reliability/juicer/ApplicationServer.java
Print this page
*** 19,28 ****
--- 19,29 ----
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
+ import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.util.logging.Logger;
import java.util.logging.Level;
*** 58,88 ****
/*
* On initialization, export remote objects and register
* them with server.
*/
public void run() {
try {
int i = 0;
/*
! * Locate apple user object in registry. The lookup will
! * occur until it is successful or fails LOOKUP_ATTEMPTS times.
* These repeated attempts allow the ApplicationServer
* to be started before the AppleUserImpl.
*/
Exception exc = null;
! for (i = 0; i < LOOKUP_ATTEMPTS; i++) {
try {
Registry registry = LocateRegistry.getRegistry(
registryHost, registryPort);
user = (AppleUser) registry.lookup("AppleUser");
user.startTest();
break; //successfully obtained AppleUser
! } catch (Exception e) {
exc = e;
! Thread.sleep(10000); //sleep 10 seconds and try again
}
}
if (user == null) {
logger.log(Level.SEVERE, "Failed to lookup AppleUser:", exc);
return;
--- 59,91 ----
/*
* On initialization, export remote objects and register
* them with server.
*/
+ @Override
public void run() {
try {
int i = 0;
/*
! * Locate apple user object in registry. The lookup will occur
! * every 5 seconds until it is successful or timeout 50 seconds.
* These repeated attempts allow the ApplicationServer
* to be started before the AppleUserImpl.
*/
Exception exc = null;
! long stopTime = System.currentTimeMillis() + LOOKUP_ATTEMPTS * 10000;
! while (System.currentTimeMillis() < stopTime) {
try {
Registry registry = LocateRegistry.getRegistry(
registryHost, registryPort);
user = (AppleUser) registry.lookup("AppleUser");
user.startTest();
break; //successfully obtained AppleUser
! } catch (RemoteException | NotBoundException e) {
exc = e;
! Thread.sleep(5000); //sleep 5 seconds and try again
}
}
if (user == null) {
logger.log(Level.SEVERE, "Failed to lookup AppleUser:", exc);
return;
*** 111,123 ****
}
} catch (RemoteException e) {
logger.log(Level.SEVERE,
"Failed to register callbacks for " + apples[i] + ":", e);
user.reportException(e);
- return;
}
! } catch (Exception e) {
logger.log(Level.SEVERE, "Unexpected exception:", e);
}
}
private static void usage() {
--- 114,125 ----
}
} catch (RemoteException e) {
logger.log(Level.SEVERE,
"Failed to register callbacks for " + apples[i] + ":", e);
user.reportException(e);
}
! } catch (InterruptedException | RemoteException e) {
logger.log(Level.SEVERE, "Unexpected exception:", e);
}
}
private static void usage() {
*** 141,161 ****
// parse command line args
try {
for (int i = 0; i < args.length ; i++ ) {
String arg = args[i];
! if (arg.equals("-numApples")) {
i++;
num = Integer.parseInt(args[i]);
! } else if (arg.equals("-registryHost")) {
i++;
host = args[i];
! } else if (arg.equals("-registryPort")) {
i++;
port = Integer.parseInt(args[i]);
! } else {
usage();
}
}
if (port == -1) {
usage();
--- 143,168 ----
// parse command line args
try {
for (int i = 0; i < args.length ; i++ ) {
String arg = args[i];
! switch (arg) {
! case "-numApples":
i++;
num = Integer.parseInt(args[i]);
! break;
! case "-registryHost":
i++;
host = args[i];
! break;
! case "-registryPort":
i++;
port = Integer.parseInt(args[i]);
! break;
! default:
usage();
+ break;
}
}
if (port == -1) {
usage();