/** * Create <code>SSLProcessorTask</code> objects and configure it to be ready * to proceed request. */ @Override protected ProcessorTask newProcessorTask(boolean initialize){ SSLProcessorTask task = null; if (!asyncExecution) { task = new SSLProcessorTask(initialize, isBufferResponse()); } else { task = new SSLAsyncProcessorTask(initialize, isBufferResponse()); } return configureProcessorTask(task); }
/** * Flush the buffer by looping until the <code>ByteBuffer</code> is empty * using <code>SSLOutputBuffer</code> * @param bb the ByteBuffer to write. */ @Override public void flushChannel(ByteBuffer bb) throws IOException{ SSLOutputWriter.flushChannel(socketChannel, bb, outputBB, sslEngine); }
/** * Initialize this <code>SelectorThread</code> */ @Override public void initEndpoint() throws IOException, InstantiationException { setName("SSLSelectorReaderThread-" + getPort()); initAlgorithm(); }
/** * 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; }
/** * 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); } }
/** * Return the <code>ProcessorTask</code> to the pool. */ @Override public void detachProcessor(){ if ( processorTask != null ){ ((SSLProcessorTask)processorTask).setSSLSupport(null); ((SSLProcessorTask)processorTask).setSslReadTask(null); final SecureOuputBuffer secureOutputBuffer = ((SSLProcessorTask) processorTask).getSecureOutputBuffer(); secureOutputBuffer.setSSLEngine(null); secureOutputBuffer.setOutputBB(null); } super.detachProcessor(); }
/** * Complete the transaction. */ @Override public void terminate(boolean keepAlive){ if (processorTask != null && processorTask.isKeepAlive()){ detachProcessor(); registerKey(); returnTask(); } else { super.terminate(keepAlive); } }
/** * Create new <code>SSLWorkerThread</code> */ @Override protected void increaseWorkerThread(int increment, boolean startThread){ SSLWorkerThread workerThread; int currentCount = threadCount; int increaseCount = threadCount + increment; for (int i=currentCount; i < increaseCount; i++){ workerThread = new SSLWorkerThread(this, name + "SSLWorkerThread-" + port + "-" + i); workerThread.setPriority(priority); if (startThread) workerThread.start(); workerThreads[i] = workerThread; threadCount++; } } }
/** * Encrypt the response and flush it using <code>OutputWriter</code> */ public static void flushChannel(SocketChannel socketChannel, ByteBuffer bb) throws IOException{ SSLWorkerThread workerThread = (SSLWorkerThread)Thread.currentThread(); SSLEngine sslEngine = workerThread.getSSLEngine(); ByteBuffer outputBB = workerThread.getOutputBB(); flushChannel(socketChannel,bb,outputBB,sslEngine); }
/** * Initialize this object. */ @Override public void initialize(StreamAlgorithm algorithm, boolean useDirectByteBuffer, boolean useByteBufferView){ type = READ_TASK; this.algorithm = algorithm; inputStream = new SSLAsyncStream(); this.useDirectByteBuffer = useDirectByteBuffer; this.useByteBufferView = useByteBufferView; }
/** * Initialize this object. */ @Override public void initialize(StreamAlgorithm algorithm, boolean useDirectByteBuffer, boolean useByteBufferView){ type = READ_TASK; this.algorithm = algorithm; inputStream = new SSLByteBufferInputStream(); this.useDirectByteBuffer = useDirectByteBuffer; this.useByteBufferView = useByteBufferView; }
/** * Perform an SSL handshake using the SSLEngine. * @param key the <code>SelectionKey</code> * @param byteBuffer The application <code>ByteBuffer</code> * @param inputBB The encrypted input <code>ByteBuffer</code> * @param outputBB The encrypted output <code>ByteBuffer</code> * @param sslEngine The SSLEngine used. * @param handshakeStatus The current handshake status * @param timeout The time the Selector will block waiting for bytes * @return byteBuffer the new ByteBuffer * @throw IOException if the handshake fail. */ public static ByteBuffer doHandshake(SelectionKey key, ByteBuffer byteBuffer, ByteBuffer inputBB, ByteBuffer outputBB, SSLEngine sslEngine, HandshakeStatus handshakeStatus) throws IOException { return doHandshake(key,byteBuffer,inputBB,outputBB,sslEngine, handshakeStatus,readTimeout); }
public SSLSelectorThread(){ super(); setPipelineClassName(com.sun.enterprise.web.connector.grizzly.ssl. SSLPipeline.class.getName()); }
/** * Return an instance of this Factory. */ public static FileCacheFactory getFactory(int currentPort){ FileCacheFactory fileCacheFactory = cache.get(currentPort); if ( fileCacheFactory == null ){ fileCacheFactory = newInstance(currentPort); } return fileCacheFactory; }
/** * Log an exception. */ private void log(Throwable ex){ Logger logger = SSLSelectorThread.logger(); if ( logger.isLoggable(Level.WARNING) ){ logger.log(Level.WARNING,"Redirector",ex); } } }
public ReadTask getReadTask(SelectionKey key) throws IOException{ ReadTask readTask = SSLSelectorThread.this.getReadTask(key); readTask.setSelectorThread(this); return readTask; } };
/** * Provides the count of request threads that are currently * being processed by the container * * @return Count of requests */ @Override public int getCurrentBusyProcessorThreads() { return (getProcessorPipeline().getCurrentThreadsBusy()); }
/** * Disable gathering of monitoring datas. */ @Override public void disableMonitoring(){ disablePipelineStats(); if (readThreads != null) { for (int i = 0; i < readThreads.length; i++) { ((SSLSelectorReadThread)readThreads[i]).isMonitoringEnabled = false; } } fileCacheFactory.setIsMonitoringEnabled(isMonitoringEnabled); }
/** * Flush the buffer by looping until the <code>ByteBuffer</code> is empty * using <code>SSLOutputBuffer</code> * @param bb the ByteBuffer to write. */ @Override public void flushChannel(ByteBuffer bb) throws IOException{ SSLOutputWriter.flushChannel(socketChannel, bb, outputBB, sslEngine); }
@Override protected void sendCache(SocketChannel socketChannel, FileCacheEntry entry, boolean keepAlive) throws IOException{ SSLOutputWriter.flushChannel(socketChannel, entry.headerBuffer.slice()); ByteBuffer keepAliveBuf = keepAlive ? connectionKaBB.slice(): connectionCloseBB.slice(); SSLOutputWriter.flushChannel(socketChannel, keepAliveBuf); SSLOutputWriter.flushChannel(socketChannel, entry.bb.slice()); } };