类org.eclipse.jetty.server.HttpChannelState源码实例Demo

下面列出了怎么用org.eclipse.jetty.server.HttpChannelState的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: micrometer   文件: TimedHandler.java
void onAsyncComplete(AsyncEvent event) {
    HttpChannelState state = ((AsyncContextEvent) event).getHttpChannelState();

    Request request = state.getBaseRequest();
    Timer.Sample sample = (Timer.Sample) request.getAttribute(SAMPLE_REQUEST_TIMER_ATTRIBUTE);
    LongTaskTimer.Sample lttSample = (LongTaskTimer.Sample) request.getAttribute(SAMPLE_REQUEST_LONG_TASK_TIMER_ATTRIBUTE);

    if (sample != null) {
        sample.stop(Timer.builder("jetty.server.requests")
                .description("HTTP requests to the Jetty server")
                .tags(tagsProvider.getTags(request, request.getResponse()))
                .tags(tags)
                .register(registry));

        lttSample.stop();
    }

    asyncWaits.decrementAndGet();

    // If we have no more dispatches, should we signal shutdown?
    FutureCallback shutdownCallback = shutdown.get();
    if (shutdownCallback != null && openRequests.activeTasks() == 0) {
        shutdownCallback.succeeded();
    }
}
 
源代码2 项目: vespa   文件: HttpResponseStatisticsCollector.java
@Override
public void handle(String path, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    inFlight.incrementAndGet();

    /* The control flow logic here is mostly a copy from org.eclipse.jetty.server.handler.StatisticsHandler.handle(..) */
    try {
        Handler handler = getHandler();
        if (handler != null && shutdown.get() == null && isStarted()) {
            handler.handle(path, baseRequest, request, response);
        } else if (!baseRequest.isHandled()) {
            baseRequest.setHandled(true);
            response.sendError(HttpStatus.SERVICE_UNAVAILABLE_503);
        }
    } finally {
        HttpChannelState state = baseRequest.getHttpChannelState();

        if (state.isSuspended()) {
            if (state.isInitial()) {
                state.addListener(completionWatcher);
            }
        } else if (state.isInitial()) {
            observeEndOfRequest(baseRequest, response);
        }
    }
}
 
源代码3 项目: micrometer   文件: TimedHandler.java
void onAsyncTimeout(AsyncEvent event) {
    asyncExpires.increment();

    HttpChannelState state = ((AsyncContextEvent) event).getHttpChannelState();
    Request request = state.getBaseRequest();

    LongTaskTimer.Sample lttSample = (LongTaskTimer.Sample) request.getAttribute(SAMPLE_REQUEST_LONG_TASK_TIMER_ATTRIBUTE);
    lttSample.stop();
}
 
源代码4 项目: micrometer   文件: TimedHandler.java
@Override
public void handle(String path, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    Timer.Sample sample = Timer.start(registry);
    LongTaskTimer.Sample requestSample;

    HttpChannelState state = baseRequest.getHttpChannelState();
    if (state.isInitial()) {
        requestSample = openRequests.start();
        request.setAttribute(SAMPLE_REQUEST_TIMER_ATTRIBUTE, sample);
        request.setAttribute(SAMPLE_REQUEST_LONG_TASK_TIMER_ATTRIBUTE, requestSample);
    } else {
        asyncDispatches.increment();
        request.setAttribute(SAMPLE_REQUEST_TIMER_ATTRIBUTE, sample);
        requestSample = (LongTaskTimer.Sample) request.getAttribute(SAMPLE_REQUEST_LONG_TASK_TIMER_ATTRIBUTE);
    }

    try {
        Handler handler = getHandler();
        if (handler != null && !shutdown.isShutdown() && isStarted()) {
            handler.handle(path, baseRequest, request, response);
        } else {
            if (!baseRequest.isHandled()) {
                baseRequest.setHandled(true);
            }
            if (!baseRequest.getResponse().isCommitted()) {
                response.sendError(HttpStatus.SERVICE_UNAVAILABLE_503);
            }
        }
    } finally {
        if (state.isSuspended()) {
            if (state.isInitial()) {
                state.addListener(onCompletion);
                asyncWaits.incrementAndGet();
            }
        } else if (state.isInitial()) {
            sample.stop(Timer.builder("jetty.server.requests")
                    .description("HTTP requests to the Jetty server")
                    .tags(tagsProvider.getTags(request, response))
                    .tags(tags)
                    .register(registry));

            requestSample.stop();

            // If we have no more dispatches, should we signal shutdown?
            FutureCallback shutdownCallback = shutdown.get();
            if (shutdownCallback != null) {
                response.flushBuffer();
                if (openRequests.activeTasks() == 0) {
                    shutdownCallback.succeeded();
                }
            }
        }
        // else onCompletion will handle it.
    }
}
 
源代码5 项目: Web-API   文件: InternalHttpRequest.java
@Override
public HttpChannelState getHttpChannelState() {
    return this.state;
}
 
源代码6 项目: chassis   文件: InstrumentedHandler.java
@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.
    }
}
 
 类所在包
 类方法
 同包方法