Connection registerChannel ( final SocketChannel channel , final InputHandler handler , final int interestOps , final ReverseDNSPolicy dns , final CipherExecutor cipherService , final SSLEngine sslEngine ) throws IOException { synchronized ( channel . blockingLock ( ) ) { channel . configureBlocking ( false ) ; channel . socket ( ) . setKeepAlive ( true ) ; } Callable < Connection > registerTask = new Callable < Connection > ( ) { @ Override public Connection call ( ) throws Exception { final VoltPort port = VoltPortFactory . createVoltPort ( channel , VoltNetwork . this , handler , ( InetSocketAddress ) channel . socket ( ) . getRemoteSocketAddress ( ) , m_pool , cipherService , sslEngine ) ; port . registering ( ) ; /* * This means we are used by a client. No need to wait then, trigger * the reverse DNS lookup now. */ if ( dns != ReverseDNSPolicy . NONE ) { port . resolveHostname ( dns == ReverseDNSPolicy . SYNCHRONOUS ) ; } try { SelectionKey key = channel . register ( m_selector , interestOps , null ) ; port . setKey ( key ) ; port . registered ( ) ; //Fix a bug witnessed on the mini where the registration lock and the selector wakeup contained //within was not enough to prevent the selector from returning the port after it was registered, //but before setKey was called. Suspect a bug in the selector.wakeup() or register() implementation //on the mac. //The null check in invokeCallbacks will catch the null attachment, continue, and do the work //next time through the selection loop key . attach ( port ) ; return port ; } finally { m_ports . add ( port ) ; m_numPorts . incrementAndGet ( ) ; } } } ; FutureTask < Connection > ft = new FutureTask < Connection > ( registerTask ) ; m_tasks . offer ( ft ) ; m_selector . wakeup ( ) ; try { return ft . get ( ) ; } catch ( Exception e ) { throw new IOException ( e ) ; } }
Register a channel with the selector and create a Connection that will pass incoming events to the provided handler .