protected static void flushAsyncWriteQueueAndClose( final SelectorHandler selectorHandler, final SelectionKey key) { try { selectorHandler.getAsyncQueueWriter().write(key, NULL_BUFFER, new AsyncWriteCallbackHandler() { public void onWriteCompleted(SelectionKey key, AsyncQueueWriteUnit writtenRecord) { close(); } public void onException(Exception exception, SelectionKey key, ByteBuffer buffer, Queue<AsyncQueueWriteUnit> remainingQueue) { close(); } private void close() { selectorHandler.addPendingKeyCancel(key); } }); } catch (Exception e) { selectorHandler.addPendingKeyCancel(key); } }
/* package */ public void configureContext(Context ctx,SelectorHandler selectorHandler){ ctx.setSelectorHandler(selectorHandler); ctx.setPipeline(selectorHandler.pipeline()); ctx.setAsyncQueueReader(selectorHandler.getAsyncQueueReader()); ctx.setAsyncQueueWriter(selectorHandler.getAsyncQueueWriter()); }
/** * Pre process the request by decoding the request line and the header. * @param input the InputStream to read bytes * @param output the OutputStream to write bytes */ public void preProcess(InputStream input, OutputStream output) throws Exception { // Make sure this object has been initialized. if ( !started ){ initialize(); } // Setting up the I/O inputBuffer.setInputStream(input); inputBuffer.setMaxSwallowingInputBytes(selectorThread.getMaxSwallowingInputBytes()); if (key != null) { inputStream = input; outputBuffer.setAsyncHttpWriteEnabled( isAsyncHttpWriteEnabled); outputBuffer.setAsyncQueueWriter( selectorHandler.getAsyncQueueWriter()); outputBuffer.setSelectionKey(key); response.setSelectionKey(key); } configPreProcess(); }