Search in sources :

Example 1 with TimeoutException

use of edu.emory.mathcs.backport.java.util.concurrent.TimeoutException 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;
    }
}
Also used : Call(org.directwebremoting.extend.Call) Future(edu.emory.mathcs.backport.java.util.concurrent.Future) Reply(org.directwebremoting.extend.Reply) ExecutionException(edu.emory.mathcs.backport.java.util.concurrent.ExecutionException) Replies(org.directwebremoting.extend.Replies) TimeoutException(edu.emory.mathcs.backport.java.util.concurrent.TimeoutException)

Aggregations

ExecutionException (edu.emory.mathcs.backport.java.util.concurrent.ExecutionException)1 Future (edu.emory.mathcs.backport.java.util.concurrent.Future)1 TimeoutException (edu.emory.mathcs.backport.java.util.concurrent.TimeoutException)1 Call (org.directwebremoting.extend.Call)1 Replies (org.directwebremoting.extend.Replies)1 Reply (org.directwebremoting.extend.Reply)1