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();
}
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;
}
Aggregations