The suspend/complete style is used when an asynchronous handler is used to generate the response:
Filter/Servlet: // when we want to enter asynchronous mode Continuation continuation = ContinuationSupport.getContinuation(request); continuation.suspend(response); // response may be wrapped myAsyncHandler.register(continuation); return; // or continuation.undispatch(); Wrapping Filter: // any filter that had wrapped the response should be implemented like: try { chain.doFilter(request,wrappedResponse); } finally { if (!continuation.isResponseWrapped()) wrappedResponse.finish() else continuation.addContinuationListener(myCompleteListener) } async wait ... Async Handler: // when the async event happens continuation.getServletResponse().getOutputStream().write(process(event)); continuation.complete()
If a continuation is suspended, but neither {@link #complete()} or {@link #resume()} iscalled during the period set by {@link #setTimeout(long)}, then the continuation will expire and {@link #isExpired()} will return true.
When a continuation expires, the {@link ContinuationListener#onTimeout(Continuation)}method is called on any {@link ContinuationListener} that has been registered via the{@link #addContinuationListener(ContinuationListener)} method. The onTimeout handlers may write a response and call {@link #complete()}. If {@link #complete()} is not called, then the container will redispatch the request as if {@link #resume()} had been called,except that {@link #isExpired()} will be true and {@link #isResumed()} will be false.
@see ContinuationSupport @see ContinuationListener
|
|