Search in sources :

Example 1 with OverloadException

use of com.yahoo.jdisc.handler.OverloadException in project vespa by vespa-engine.

the class ThreadedRequestHandler method handleRequest.

/**
 * Handles a request by assigning a worker thread to it.
 *
 * @throws OverloadException if thread pool has no available thread
 */
@Override
public final ContentChannel handleRequest(Request request, ResponseHandler responseHandler) {
    metric.add("handled.requests", 1, contextFor(request.getBindingMatch()));
    if (request.getTimeout(TimeUnit.SECONDS) == null) {
        Duration timeout = getTimeout();
        if (timeout != null) {
            request.setTimeout(timeout.getSeconds(), TimeUnit.SECONDS);
        }
    }
    BufferedContentChannel content = new BufferedContentChannel();
    final RequestTask command = new RequestTask(request, content, responseHandler);
    try {
        executor.execute(command);
    } catch (RejectedExecutionException e) {
        command.failOnOverload();
        throw new OverloadException("No available threads for " + getClass().getSimpleName(), e);
    } finally {
        logRejectedRequests();
    }
    return content;
}
Also used : OverloadException(com.yahoo.jdisc.handler.OverloadException) Duration(java.time.Duration) BufferedContentChannel(com.yahoo.jdisc.handler.BufferedContentChannel) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 2 with OverloadException

use of com.yahoo.jdisc.handler.OverloadException in project vespa by vespa-engine.

the class JDiscHttpServlet method dispatchHttpRequest.

private void dispatchHttpRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
    AccessLogEntry accessLogEntry = new AccessLogEntry();
    AccessLogRequestLog.populateAccessLogEntryFromHttpServletRequest(request, accessLogEntry);
    request.setAttribute(ATTRIBUTE_NAME_ACCESS_LOG_ENTRY, accessLogEntry);
    try {
        switch(request.getDispatcherType()) {
            case REQUEST:
                new HttpRequestDispatch(context, accessLogEntry, getMetricContext(request), request, response).dispatch();
                break;
            default:
                if (log.isLoggable(Level.INFO)) {
                    log.info("Unexpected " + request.getDispatcherType() + "; " + formatAttributes(request));
                }
                break;
        }
    } catch (OverloadException e) {
    // nop
    } catch (RuntimeException e) {
        throw new ExceptionWrapper(e);
    }
}
Also used : OverloadException(com.yahoo.jdisc.handler.OverloadException) AccessLogEntry(com.yahoo.container.logging.AccessLogEntry)

Aggregations

OverloadException (com.yahoo.jdisc.handler.OverloadException)2 AccessLogEntry (com.yahoo.container.logging.AccessLogEntry)1 BufferedContentChannel (com.yahoo.jdisc.handler.BufferedContentChannel)1 Duration (java.time.Duration)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1