/** * Complete the transaction. */ @Override public void terminate(boolean keepAlive){ if (processorTask != null && processorTask.isKeepAlive()){ detachProcessor(); registerKey(); returnTask(); } else { super.terminate(keepAlive); } }
/** * Manage the <code>SelectionKey</code> */ @Override protected void manageKeepAlive(boolean keepAlive,int count, Exception exception){ // The key is invalid when the Task has been cancelled. if (count == -1 || exception != null){ if ( exception != null){ // Make sure we have detached the processorTask detachProcessor(); if (SelectorThread.logger().isLoggable(Level.FINE)){ SelectorThread.logger().log (Level.FINE, "SocketChannel Read Exception:",exception); } } terminate(false); } }
@Override protected boolean process() throws IOException{ boolean keepAlive = false; SocketChannel socketChannel = (SocketChannel)key.channel(); Socket socket = socketChannel.socket(); algorithm.setSocketChannel(socketChannel); inputStream.setSelectionKey(key); ((SSLAsyncStream)inputStream).setSslEngine(sslEngine); ((SSLAsyncStream)inputStream).setInputBB(inputBB); // Get a processor task. If the processorTask != null, that means we // failed to load all the bytes in a single channel.read(). if (processorTask == null){ attachProcessor(selectorThread.getProcessorTask()); } // Always true with the NoParsingAlgorithm if (algorithm.parse(byteBuffer)){ return executeProcessorTask(); } else { // Never happens with the default StreamAlgorithm return true; } }
/** * Set appropriate attribute on the <code>ProcessorTask</code>. */ @Override public void configureProcessorTask(){ super.configureProcessorTask(); if ( !getTaskListeners().contains(processorTask) ){ processorTask.addTaskListener(this); addTaskListener((TaskListener)processorTask); } SSLAsyncOutputBuffer outputBuffer = ((SSLAsyncProcessorTask)processorTask).getSSLAsyncOutputBuffer(); if (outputBuffer == null) { processorTask.initialize(); outputBuffer = ((SSLAsyncProcessorTask)processorTask).getSSLAsyncOutputBuffer(); } outputBuffer.setSSLEngine(sslEngine); outputBuffer.setOutputBB(outputBB); } }
/** * Clear the current state and make this object ready for another request. */ @Override public void recycle(){ byteBuffer = algorithm.postParse(byteBuffer); byteBuffer.clear(); inputStream.recycle(); algorithm.recycle(); key = null; inputStream.setSelectionKey(null); handshake = true; inputBB.clear(); outputBB.clear(); outputBB.position(0); outputBB.limit(0); sslEngine = null; detachProcessor(); }
/** * Execute the <code>ProcessorTask</code> * @return false if the request wasn't fully read by the channel. * so we need to respin the key on the Selector. */ @Override public boolean executeProcessorTask() throws IOException{ if (SelectorThread.logger().isLoggable(Level.FINEST)) SelectorThread.logger().log(Level.FINEST,"executeProcessorTask"); if (algorithm.getHandler() != null && algorithm.getHandler() .handle(null,Handler.REQUEST_BUFFERED) == Handler.BREAK){ return true; } if (taskEvent == null){ taskContext = new TaskContext(); taskEvent = new TaskEvent<TaskContext>(taskContext); } // Call the listener and execute the task on it's own pipeline. taskEvent.setStatus(TaskEvent.START); taskContext.setInputStream(inputStream); taskEvent.attach(taskContext); fireTaskEvent(taskEvent); return false; }
/** * Return a new <code>SSLReadTask</code> instance */ @Override protected DefaultReadTask newReadTask(){ StreamAlgorithm streamAlgorithm = new NoParsingAlgorithm(); streamAlgorithm.setPort(getPort()); SSLReadTask task; if (getMaxReadWorkerThreads() > 0 || asyncExecution){ task = new SSLAsyncReadTask(); } else { task = new SSLReadTask(); } task.initialize(streamAlgorithm, isUseDirectByteBuffer(), isUseByteBufferView()); task.setPipeline(getReadPipeline()); task.setSelectorThread(this); task.setRecycle(isRecycleTasks()); task.setSSLImplementation(sslImplementation); return task; }