throw new IllegalStateException("GridJob does not support final results");
}
// Create Proxy for callback
ConnectionFactory cf = ClusterManager.getInstance().getConnectionFactory();
final ResultCallback callback = JMSRemotingSupport.createProxy (cf, queueName, ResultCallback.class);
// Clean Up Hook
CleanUpSupport.removeQueueWhenFinished(jobId, queueName);
Thread t = new Thread(new Runnable(){
public void run() {
// This sync block waits until result is available.
synchronized (mutex) {
try {
// If job is not finished, wait till it finishes
while (!isJobFinished()) {
// Wait for result
mutex.wait();
}
// Job Finished
if (state==GridJobState.COMPLETE) {
callback.onResult(result);
}
else {
Exception e = null;
// If we got an exception while execution
if (exception!=null) {
e = new GridExecutionException("Execution Failed", exception);
}
else { // If failed for other reason
e = new GridExecutionException("Execution Failed (Job State : " + getState() + ")");
}
// Send Exception
callback.onResult(e);
}
} catch (InterruptedException e) {
log.error(e);
throw new RuntimeException("Interrupted while waiting for Result");
}