use of edu.emory.mathcs.backport.java.util.concurrent.ExecutionException in project ma-core-public by infiniteautomation.
the class ParallelDefaultRemoter method execute.
/**
* Execute a set of remote calls in parallel and generate set of reply data
* for later conversion to whatever wire protocol we are using today.
* @param calls The set of calls to execute in parallel
* @return A set of reply data objects
*/
public Replies execute(Calls calls) {
Replies replies = new Replies(calls.getBatchId());
Future[] future = new Future[calls.getCallCount()];
if (calls.getCallCount() == 1) {
return super.execute(calls);
} else {
for (int callNum = 0; callNum < calls.getCallCount(); callNum++) {
Call call = calls.getCall(callNum);
future[callNum] = executorService.submit(new OneCall(call));
}
for (int callNum = 0; callNum < calls.getCallCount(); callNum++) {
try {
Reply reply = (Reply) future[callNum].get(this.timeout, TimeUnit.MILLISECONDS);
replies.addReply(reply);
} catch (InterruptedException ex) {
log.warn("Method execution failed: ", ex);
replies.addReply(new Reply(calls.getCall(callNum).getCallId(), null, ex));
} catch (ExecutionException ex) {
log.warn("Method execution failed: ", ex);
replies.addReply(new Reply(calls.getCall(callNum).getCallId(), null, ex));
} catch (TimeoutException ex) {
log.warn("Method execution failed: ", ex);
replies.addReply(new Reply(calls.getCall(callNum).getCallId(), null, ex));
}
}
return replies;
}
}
Aggregations