Search in sources :

Example 1 with EmptyCompletionHandler

use of org.glassfish.grizzly.EmptyCompletionHandler in project Payara by payara.

the class XProtocolFilter method handleRead.

@Override
public NextAction handleRead(final FilterChainContext ctx) throws IOException {
    final Connection connection = ctx.getConnection();
    final MemoryManager memoryManager = connection.getTransport().getMemoryManager();
    ctx.write(Buffers.wrap(memoryManager, "X-Protocol-Response", CHARSET));
    ctx.flush(new EmptyCompletionHandler() {

        @Override
        public void completed(Object result) {
            connection.closeSilently();
        }
    });
    return ctx.getStopAction();
}
Also used : Connection(org.glassfish.grizzly.Connection) EmptyCompletionHandler(org.glassfish.grizzly.EmptyCompletionHandler) MemoryManager(org.glassfish.grizzly.memory.MemoryManager)

Example 2 with EmptyCompletionHandler

use of org.glassfish.grizzly.EmptyCompletionHandler in project Payara by payara.

the class Request method startAsync.

/**
 * Starts async processing on this request.
 *
 * @param servletRequest the ServletRequest with which to initialize
 * the AsyncContext
 * @param servletResponse the ServletResponse with which to initialize
 * the AsyncContext
 * @param isStartAsyncWithZeroArg true if the zero-arg version of
 * startAsync was called, false otherwise
 */
private AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse, boolean isStartAsyncWithZeroArg) throws IllegalStateException {
    if (servletRequest == null || servletResponse == null) {
        throw new IllegalArgumentException("Null request or response");
    }
    if (!isAsyncSupported()) {
        throw new IllegalStateException(rb.getString(LogFacade.REQUEST_WITHIN_SCOPE_OF_FILTER_OR_SERVLET_EXCEPTION));
    }
    final AsyncContextImpl asyncContextLocal = asyncContext;
    if (asyncContextLocal != null) {
        if (isAsyncStarted()) {
            throw new IllegalStateException(rb.getString(LogFacade.START_ASYNC_CALLED_AGAIN_EXCEPTION));
        }
        if (asyncContextLocal.isAsyncComplete()) {
            throw new IllegalStateException(rb.getString(LogFacade.ASYNC_ALREADY_COMPLETE_EXCEPTION));
        }
        if (!asyncContextLocal.isStartAsyncInScope()) {
            throw new IllegalStateException(rb.getString(LogFacade.START_ASYNC_CALLED_OUTSIDE_SCOPE_EXCEPTION));
        }
        // Reinitialize existing AsyncContext
        asyncContextLocal.reinitialize(servletRequest, servletResponse, isStartAsyncWithZeroArg);
    } else {
        final AsyncContextImpl asyncContextFinal = new AsyncContextImpl(this, servletRequest, (Response) getResponse(), servletResponse, isStartAsyncWithZeroArg);
        asyncContext = asyncContextFinal;
        final CompletionHandler<org.glassfish.grizzly.http.server.Response> requestCompletionHandler = new EmptyCompletionHandler<org.glassfish.grizzly.http.server.Response>() {

            @Override
            public void completed(org.glassfish.grizzly.http.server.Response response) {
                asyncContextFinal.notifyAsyncListeners(AsyncContextImpl.AsyncEventType.COMPLETE, null);
            }
        };
        final TimeoutHandler timeoutHandler = new TimeoutHandler() {

            @Override
            public boolean onTimeout(final org.glassfish.grizzly.http.server.Response response) {
                return processTimeout();
            }
        };
        coyoteRequest.getResponse().suspend(-1, TimeUnit.MILLISECONDS, requestCompletionHandler, timeoutHandler);
        asyncStartedThread = Thread.currentThread();
    }
    asyncStarted.set(true);
    return asyncContext;
}
Also used : HttpResponse(org.apache.catalina.HttpResponse) ServletResponse(javax.servlet.ServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) TimeoutHandler(org.glassfish.grizzly.http.server.TimeoutHandler) EmptyCompletionHandler(org.glassfish.grizzly.EmptyCompletionHandler)

Aggregations

EmptyCompletionHandler (org.glassfish.grizzly.EmptyCompletionHandler)2 ServletResponse (javax.servlet.ServletResponse)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpResponse (org.apache.catalina.HttpResponse)1 Connection (org.glassfish.grizzly.Connection)1 TimeoutHandler (org.glassfish.grizzly.http.server.TimeoutHandler)1 MemoryManager (org.glassfish.grizzly.memory.MemoryManager)1