}
private NextAction flush(final FilterChainContext ctx) {
final HttpContext httpContext = HttpContext.get(ctx);
assert httpContext != null;
final OutputSink output = httpContext.getOutputSink();
if (output.canWrite()) { // if connection write queue is not overloaded
return ctx.getStopAction();
} else { // if connection write queue is overloaded
// prepare context for suspend
final NextAction suspendAction = ctx.getSuspendAction();
ctx.suspend();
// notify when connection becomes writable, so we can resume it
output.notifyCanWrite(new WriteHandler() {
@Override
public void onWritePossible() throws Exception {
finish();
}