NIO2 endpoint.
| 54 | * NIO2 endpoint. |
| 55 | */ |
| 56 | public class Nio2Endpoint extends AbstractNetworkChannelEndpoint<Nio2Channel,AsynchronousSocketChannel> { |
| 57 | |
| 58 | |
| 59 | // -------------------------------------------------------------- Constants |
| 60 | |
| 61 | |
| 62 | private static final Log log = LogFactory.getLog(Nio2Endpoint.class); |
| 63 | private static final Log logCertificate = LogFactory.getLog(Nio2Endpoint.class.getName() + ".certificate"); |
| 64 | private static final Log logHandshake = LogFactory.getLog(Nio2Endpoint.class.getName() + ".handshake"); |
| 65 | |
| 66 | |
| 67 | // ----------------------------------------------------------------- Fields |
| 68 | |
| 69 | /** |
| 70 | * Server socket "pointer". |
| 71 | */ |
| 72 | private volatile AsynchronousServerSocketChannel serverSock = null; |
| 73 | |
| 74 | /** |
| 75 | * Allows detecting if a completion handler completes inline. |
| 76 | */ |
| 77 | private static final ThreadLocal<Boolean> inlineCompletion = new ThreadLocal<>(); |
| 78 | |
| 79 | /** |
| 80 | * Thread group associated with the server socket. |
| 81 | */ |
| 82 | private AsynchronousChannelGroup threadGroup = null; |
| 83 | |
| 84 | private volatile boolean allClosed; |
| 85 | |
| 86 | /** |
| 87 | * Bytebuffer cache, each channel holds a set of buffers (two, except for SSL holds four) |
| 88 | */ |
| 89 | private SynchronizedStack<Nio2Channel> nioChannels; |
| 90 | |
| 91 | private SocketAddress previousAcceptedSocketRemoteAddress = null; |
| 92 | private long previousAcceptedSocketNanoTime = 0; |
| 93 | |
| 94 | |
| 95 | // --------------------------------------------------------- Public Methods |
| 96 | |
| 97 | /** |
| 98 | * Number of keep-alive sockets. |
| 99 | * |
| 100 | * @return Always returns -1. |
| 101 | */ |
| 102 | public int getKeepAliveCount() { |
| 103 | // For this connector, only the overall connection count is relevant |
| 104 | return -1; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | // ----------------------------------------------- Public Lifecycle Methods |
| 109 | |
| 110 | |
| 111 | /** |
| 112 | * Initialize the endpoint. |
| 113 | */ |