Search in sources :

Example 1 with HttpChannelState

use of org.eclipse.jetty.server.HttpChannelState in project jetty.project by eclipse.

the class StatisticsHandler method handle.

@Override
public void handle(String path, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    _dispatchedStats.increment();
    final long start;
    HttpChannelState state = baseRequest.getHttpChannelState();
    if (state.isInitial()) {
        // new request
        _requestStats.increment();
        start = baseRequest.getTimeStamp();
    } else {
        // resumed request
        start = System.currentTimeMillis();
        _asyncDispatches.increment();
    }
    try {
        Handler handler = getHandler();
        if (handler != null && _shutdown.get() == null && isStarted())
            handler.handle(path, baseRequest, request, response);
        else if (baseRequest.isHandled()) {
            if (_wrapWarning.compareAndSet(false, true))
                LOG.warn("Bad statistics configuration. Latencies will be incorrect in {}", this);
        } else {
            baseRequest.setHandled(true);
            response.sendError(HttpStatus.SERVICE_UNAVAILABLE_503);
        }
    } finally {
        final long now = System.currentTimeMillis();
        final long dispatched = now - start;
        _dispatchedStats.decrement();
        _dispatchedTimeStats.set(dispatched);
        if (state.isSuspended()) {
            if (state.isInitial()) {
                state.addListener(_onCompletion);
                _asyncWaitStats.increment();
            }
        } else if (state.isInitial()) {
            long d = _requestStats.decrement();
            _requestTimeStats.set(dispatched);
            updateResponse(baseRequest);
            // If we have no more dispatches, should we signal shutdown?
            FutureCallback shutdown = _shutdown.get();
            if (shutdown != null) {
                response.flushBuffer();
                if (d == 0)
                    shutdown.succeeded();
            }
        }
    // else onCompletion will handle it.
    }
}
Also used : HttpChannelState(org.eclipse.jetty.server.HttpChannelState) Handler(org.eclipse.jetty.server.Handler) FutureCallback(org.eclipse.jetty.util.FutureCallback)

Example 2 with HttpChannelState

use of org.eclipse.jetty.server.HttpChannelState in project metrics by dropwizard.

the class InstrumentedHandler method handle.

@Override
public void handle(String path, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException {
    activeDispatches.inc();
    final long start;
    final HttpChannelState state = request.getHttpChannelState();
    if (state.isInitial()) {
        // new request
        activeRequests.inc();
        start = request.getTimeStamp();
        state.addListener(listener);
    } else {
        // resumed request
        start = System.currentTimeMillis();
        activeSuspended.dec();
        if (state.getState() == HttpChannelState.State.DISPATCHED) {
            asyncDispatches.mark();
        }
    }
    try {
        super.handle(path, request, httpRequest, httpResponse);
    } finally {
        final long now = System.currentTimeMillis();
        final long dispatched = now - start;
        activeDispatches.dec();
        dispatches.update(dispatched, TimeUnit.MILLISECONDS);
        if (state.isSuspended()) {
            activeSuspended.inc();
        } else if (state.isInitial()) {
            updateResponses(httpRequest, httpResponse, start);
        }
    // else onCompletion will handle it.
    }
}
Also used : HttpChannelState(org.eclipse.jetty.server.HttpChannelState)

Example 3 with HttpChannelState

use of org.eclipse.jetty.server.HttpChannelState in project chassis by Kixeye.

the class InstrumentedHandler method handle.

@Override
public void handle(String path, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException {
    activeDispatches.inc();
    final long start;
    final HttpChannelState state = request.getHttpChannelState();
    if (state.isInitial()) {
        // new request
        activeRequests.inc();
        start = request.getTimeStamp();
    } else {
        // resumed request
        start = System.currentTimeMillis();
        activeSuspended.dec();
        if (state.getState() == State.DISPATCHED) {
            asyncDispatches.mark();
        }
    }
    try {
        super.handle(path, request, httpRequest, httpResponse);
    } finally {
        final long now = System.currentTimeMillis();
        final long dispatched = now - start;
        activeDispatches.dec();
        dispatches.update(dispatched, TimeUnit.MILLISECONDS);
        if (state.isSuspended()) {
            if (state.isInitial()) {
                state.addListener(listener);
            }
            activeSuspended.inc();
        } else if (state.isInitial()) {
            requests.update(dispatched, TimeUnit.MILLISECONDS);
            updateResponses(request);
        }
    // else onCompletion will handle it.
    }
}
Also used : HttpChannelState(org.eclipse.jetty.server.HttpChannelState)

Example 4 with HttpChannelState

use of org.eclipse.jetty.server.HttpChannelState in project jetty.project by eclipse.

the class ContextHandlerCollection method handle.

/* ------------------------------------------------------------ */
/*
     * @see org.eclipse.jetty.server.server.Handler#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
     */
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    Handler[] handlers = getHandlers();
    if (handlers == null || handlers.length == 0)
        return;
    HttpChannelState async = baseRequest.getHttpChannelState();
    if (async.isAsync()) {
        ContextHandler context = async.getContextHandler();
        if (context != null) {
            Handler branch = _contextBranches.get(context);
            if (branch == null)
                context.handle(target, baseRequest, request, response);
            else
                branch.handle(target, baseRequest, request, response);
            return;
        }
    }
    // }
    if (target.startsWith("/")) {
        int limit = target.length() - 1;
        while (limit >= 0) {
            // Get best match
            Map.Entry<String, Branch[]> branches = _pathBranches.getBest(target, 1, limit);
            if (branches == null)
                break;
            int l = branches.getKey().length();
            if (l == 1 || target.length() == l || target.charAt(l) == '/') {
                for (Branch branch : branches.getValue()) {
                    branch.getHandler().handle(target, baseRequest, request, response);
                    if (baseRequest.isHandled())
                        return;
                }
            }
            limit = l - 2;
        }
    } else {
        // This may not work in all circumstances... but then I think it should never be called
        for (int i = 0; i < handlers.length; i++) {
            handlers[i].handle(target, baseRequest, request, response);
            if (baseRequest.isHandled())
                return;
        }
    }
}
Also used : HttpChannelState(org.eclipse.jetty.server.HttpChannelState) Handler(org.eclipse.jetty.server.Handler) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Aggregations

HttpChannelState (org.eclipse.jetty.server.HttpChannelState)4 Handler (org.eclipse.jetty.server.Handler)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 FutureCallback (org.eclipse.jetty.util.FutureCallback)1