private void close() { selectorHandler.addPendingKeyCancel(key); } });
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); } }
@Override public void onRead(IOEvent<Context> ioEvent) { // We don't expect any read, so if any data comes - we suppose it's "close" notification final Context context = ioEvent.attachment(); final SelectionKey selectionKey = context.getSelectionKey(); // close the channel context.getSelectorHandler().addPendingKeyCancel(selectionKey); }
public boolean execute(Context ctx) throws IOException { final ProtocolChain chain = ctx.getProtocolChain(); synchronized (ssl) { if (!isSslInitialized) { isSslInitialized = true; isInitilizedOk = sslConfigHolder.configureSSL(); if (!isInitilizedOk) { logger.log(Level.SEVERE, "Failed to configure SSL on protocol ''{0}'' on network-listener ''{1}''", new Object[]{protocolName, networkListenerName}); } } } if (isInitilizedOk) { doConfigureFilters(chain); } else { logger.log(Level.FINE, "Closing connection to misconfigured SSL protocol"); ctx.getSelectorHandler().addPendingKeyCancel(ctx.getSelectionKey()); } return false; }
flushAsyncWriteQueueAndClose(selectorHandler, processorSelectionKey); } else { selectorHandler.addPendingKeyCancel(processorSelectionKey);
public boolean postProcess(ProcessorTask processorTask) { final boolean keepAlive = processorTask.isKeepAlive(); final SelectorHandler selectorHandler = processorTask.getSelectorHandler(); final SelectionKey selectionKey = processorTask.getSelectionKey(); final SelectorThread selectorThread = processorTask.getSelectorThread(); if (keepAlive) { selectorHandler.register(selectionKey, SelectionKey.OP_READ); } else { if (selectorThread.isAsyncHttpWriteEnabled()) { flushAsyncWriteQueueAndClose(selectorHandler, selectionKey); } else { selectorHandler.addPendingKeyCancel(selectionKey); } } ((InputReader) processorTask.getInputStream()).recycle(); processorTask.recycle(); selectorThread.returnTask(processorTask); return true; }