Search in sources :

Example 1 with Replies

use of org.directwebremoting.extend.Replies 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)

Example 2 with Replies

use of org.directwebremoting.extend.Replies in project ma-core-public by infiniteautomation.

the class DefaultRemoter method execute.

/* (non-Javadoc)
     * @see org.directwebremoting.Remoter#execute(org.directwebremoting.Calls)
     */
public Replies execute(Calls calls) {
    Replies replies = new Replies(calls.getBatchId());
    int callCount = calls.getCallCount();
    if (callCount > maxCallCount) {
        log.error("Call count for batch exceeds maxCallCount. Add an init-param of maxCallCount to increase this limit");
        throw new SecurityException("Call count for batch is too high");
    }
    for (int callNum = 0; callNum < callCount; callNum++) {
        Call call = calls.getCall(callNum);
        Reply reply = execute(call);
        replies.addReply(reply);
    }
    return replies;
}
Also used : Call(org.directwebremoting.extend.Call) Reply(org.directwebremoting.extend.Reply) Replies(org.directwebremoting.extend.Replies)

Example 3 with Replies

use of org.directwebremoting.extend.Replies in project ma-core-public by infiniteautomation.

the class HtmlCallHandler method handle.

/* (non-Javadoc)
     * @see org.directwebremoting.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Calls calls = null;
    try {
        calls = htmlCallMarshaller.marshallInbound(request, response);
    } catch (Exception ex) {
        htmlCallMarshaller.marshallException(request, response, ex);
        return;
    }
    Replies replies = remoter.execute(calls);
    htmlCallMarshaller.marshallOutbound(replies, request, response);
}
Also used : Calls(org.directwebremoting.extend.Calls) Replies(org.directwebremoting.extend.Replies) IOException(java.io.IOException)

Example 4 with Replies

use of org.directwebremoting.extend.Replies in project ma-core-public by infiniteautomation.

the class PlainCallHandler method handle.

/* (non-Javadoc)
     * @see org.directwebremoting.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Calls calls = null;
    try {
        calls = plainCallMarshaller.marshallInbound(request, response);
    } catch (Exception ex) {
        plainCallMarshaller.marshallException(request, response, ex);
        return;
    }
    Replies replies = remoter.execute(calls);
    plainCallMarshaller.marshallOutbound(replies, request, response);
}
Also used : Calls(org.directwebremoting.extend.Calls) Replies(org.directwebremoting.extend.Replies) IOException(java.io.IOException)

Aggregations

Replies (org.directwebremoting.extend.Replies)4 IOException (java.io.IOException)2 Call (org.directwebremoting.extend.Call)2 Calls (org.directwebremoting.extend.Calls)2 Reply (org.directwebremoting.extend.Reply)2 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