public AjpNio2Protocol() { super(new Nio2Endpoint()); }
/** * Initialize the endpoint. */ @Override public void bind() throws Exception { // Create worker collection if ( getExecutor() == null ) { createExecutor(); } if (getExecutor() instanceof ExecutorService) { threadGroup = AsynchronousChannelGroup.withThreadPool((ExecutorService) getExecutor()); } // AsynchronousChannelGroup currently needs exclusive access to its executor service if (!internalExecutor) { log.warn(sm.getString("endpoint.nio2.exclusiveExecutor")); } serverSock = AsynchronousServerSocketChannel.open(threadGroup); socketProperties.setProperties(serverSock); InetSocketAddress addr = (getAddress()!=null?new InetSocketAddress(getAddress(),getPort()):new InetSocketAddress(getPort())); serverSock.bind(addr,getAcceptCount()); // Initialize thread count defaults for acceptor, poller if (acceptorThreadCount != 1) { // NIO2 does not allow any form of IO concurrency acceptorThreadCount = 1; } // Initialize SSL if needed initialiseSsl(); }
/** * Deallocate NIO memory pools, and close server socket. */ @Override public void unbind() throws Exception { if (running) { stop(); } doCloseServerSocket(); destroySsl(); super.unbind(); // Unlike other connectors, the thread pool is tied to the server socket shutdownExecutor(); if (getHandler() != null) { getHandler().recycle(); } }
/** * Start the NIO2 endpoint, creating acceptor. */ @Override public void startInternal() throws Exception { if (!running) { allClosed = false; running = true; paused = false; processorCache = new SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE, socketProperties.getProcessorCache()); nioChannels = new SynchronizedStack<>(SynchronizedStack.DEFAULT_SIZE, socketProperties.getBufferPool()); // Create worker collection if ( getExecutor() == null ) { createExecutor(); } initializeConnectionLatch(); startAcceptorThreads(); } }
public void awaitBytes() { // NO-OP is there is already a read in progress. if (readPending.tryAcquire()) { getSocket().getBufHandler().configureReadBufferForWrite(); Nio2Endpoint.startInline(); getSocket().read(getSocket().getBufHandler().getReadBuffer(), toNio2Timeout(getReadTimeout()), TimeUnit.MILLISECONDS, this, awaitBytesHandler); Nio2Endpoint.endInline(); } }
sc.read(netInBuffer, Nio2Endpoint.toNio2Timeout(endpoint.getConnectionTimeout()), TimeUnit.MILLISECONDS, socket, handshakeReadCompletionHandler); return 1; netInBuffer.capacity() < endpoint.getSniParseLimit()) { int newLimit = Math.min(netInBuffer.capacity() * 2, endpoint.getSniParseLimit()); log.info(sm.getString("channel.nio.ssl.expandNetInBuffer", Integer.toString(newLimit))); sc.read(netInBuffer, Nio2Endpoint.toNio2Timeout(endpoint.getConnectionTimeout()), TimeUnit.MILLISECONDS, socket, handshakeReadCompletionHandler); return 1; break; case NEED_READ: sc.read(netInBuffer, Nio2Endpoint.toNio2Timeout(endpoint.getConnectionTimeout()), TimeUnit.MILLISECONDS, socket, handshakeReadCompletionHandler); return 1; log.debug(sm.getString("channel.nio.ssl.sniDefault")); hostName = endpoint.getDefaultSSLHostConfigName(); clientRequestedCiphers = Collections.emptyList(); break; sslEngine = endpoint.createSSLEngine(hostName, clientRequestedCiphers, clientRequestedApplicationProtocols);
socketProperties.getAppWriteBufSize(), socketProperties.getDirectBuffer()); if (isSSLEnabled()) { channel = new SecureNio2Channel(bufhandler, this); } else { socketWrapper.setReadTimeout(getConnectionTimeout()); socketWrapper.setWriteTimeout(getConnectionTimeout()); socketWrapper.setKeepAliveLeft(Nio2Endpoint.this.getMaxKeepAliveRequests()); socketWrapper.setSecure(isSSLEnabled()); return processSocket(socketWrapper, SocketEvent.OPEN_READ, true); } catch (Throwable t) { ExceptionUtils.handleThrowable(t);
long timeout = endpoint.getConnectionTimeout(); if (endpoint.hasNegotiableProtocols()) { if (sslEngine instanceof SSLUtil.ProtocolInfo) { socket.setNegotiatedProtocol( } else { if (async) { sc.write(netOutBuffer, Nio2Endpoint.toNio2Timeout(timeout), TimeUnit.MILLISECONDS, socket, handshakeWriteCompletionHandler); } else { sc.write(netOutBuffer, Nio2Endpoint.toNio2Timeout(timeout), TimeUnit.MILLISECONDS, socket, handshakeWriteCompletionHandler); } else { sc.read(netInBuffer, Nio2Endpoint.toNio2Timeout(timeout), TimeUnit.MILLISECONDS, socket, handshakeReadCompletionHandler); } else {
getHandler().release(socket); } catch (Throwable e) { ExceptionUtils.handleThrowable(e); if (!nio2Socket.closed) { nio2Socket.closed = true; countDownConnection();
@Override protected void closeSocket(AsynchronousSocketChannel socket) { countDownConnection(); try { socket.close(); } catch (IOException ioe) { if (log.isDebugEnabled()) { log.debug(sm.getString("endpoint.err.close"), ioe); } } }
closing = true; sslEngine.closeOutbound(); long timeout = endpoint.getConnectionTimeout();
Nio2Endpoint.startInline(); getSocket().read(to, toNio2Timeout(getReadTimeout()), TimeUnit.MILLISECONDS, this, readCompletionHandler); Nio2Endpoint.endInline(); if (readPending.availablePermits() == 1) { nRead = to.position();
private boolean flushNonBlocking(boolean hasPermit) throws IOException { checkError(); synchronized (writeCompletionHandler) { if (hasPermit || writePending.tryAcquire()) { socketBufferHandler.configureWriteBufferForRead(); if (!nonBlockingWriteBuffer.isEmpty()) { ByteBuffer[] array = nonBlockingWriteBuffer.toArray(socketBufferHandler.getWriteBuffer()); Nio2Endpoint.startInline(); getSocket().write(array, 0, array.length, toNio2Timeout(getWriteTimeout()), TimeUnit.MILLISECONDS, array, gatheringWriteCompletionHandler); Nio2Endpoint.endInline(); } else if (socketBufferHandler.getWriteBuffer().hasRemaining()) { // Regular write Nio2Endpoint.startInline(); getSocket().write(socketBufferHandler.getWriteBuffer(), toNio2Timeout(getWriteTimeout()), TimeUnit.MILLISECONDS, socketBufferHandler.getWriteBuffer(), writeCompletionHandler); Nio2Endpoint.endInline(); } else { // Nothing was written if (!hasPermit) { writePending.release(); } } } return hasDataToWrite(); } }
public Http11Nio2Protocol() { super(new Nio2Endpoint()); }
data.length -= nRead; getSocket().getBufHandler().configureWriteBufferForRead(); Nio2Endpoint.startInline(); getSocket().write(buffer, toNio2Timeout(getWriteTimeout()), TimeUnit.MILLISECONDS, data, sendfileHandler); Nio2Endpoint.endInline(); if (data.doneInline) { if (data.error) {
timeout = toNio2Timeout(getWriteTimeout()); timeout, unit, attachment, check, handler, writePending); VectoredIOCompletionHandler<A> completion = new VectoredIOCompletionHandler<>(); Nio2Endpoint.startInline(); Nio2Endpoint.endInline(); if (block == BlockingMode.BLOCK) { synchronized (state) {
timeout = toNio2Timeout(getReadTimeout()); timeout, unit, attachment, check, handler, readPending); VectoredIOCompletionHandler<A> completion = new VectoredIOCompletionHandler<>(); Nio2Endpoint.startInline(); long nBytes = 0; if (!socketBufferHandler.isReadBufferEmpty()) { getSocket().read(dsts, offset, length, timeout, unit, state, completion); Nio2Endpoint.endInline(); if (block == BlockingMode.BLOCK) { synchronized (state) {