}
}
System.out.println("gtw = " + mGateway.toString());
String dispelFile = args[0]; //Util.getFileContentAsString(args[0]);
System.out.println(dispelFile);
GatewayProcess mGatewayProcess = mGateway.submit(dispelFile);
// now can either wait for results (blocking) or sign up for
// notifications (non-blocking)
// 0 - blocking wait; 1 - wait with timeout; 2 - non-blocking
int example = 0;
switch (example) {
// *****************************************************
// waiting for results
// *****************************************************
case 0:
try {
mGatewayProcess.waitForResults();
return mGatewayProcess.getResults();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
// then destroy the process itself
mGatewayProcess.destroy();
}
break;
// *****************************************************
// waiting for results with timeout
// *****************************************************
case 1:
long timeout = 100 * 1000;
try {
mGatewayProcess.waitForResults(timeout);
if (hasErrors(mGatewayProcess.getErrors()))
{
return null;
}
for (Result r : mGatewayProcess.getResults().values()) {
return mGatewayProcess.getResults();
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (TimeoutException e) {
System.out.println("Ooops! Timed out!");
} finally {
// then destroy the process itself
mGatewayProcess.destroy();
}
break;
// *****************************************************
// subscribing for results
// *****************************************************
// when subscribing also need to implement ResultObserver interface
// resultsReady method, example below
case 2:
mGatewayProcess.subscribeForResults(this);
System.out.println("Hurray! Got my prompt back!!");
break;
}
return null;