protected void startOutgoingConnection ( final Connection conn , InetSocketAddress addr ) { final SocketChannel sockchan = conn . getChannel ( ) ; try { // register our channel with the selector (if this fails, we abandon ship immediately) conn . selkey = sockchan . register ( _selector , SelectionKey . OP_CONNECT ) ; // start our connection process (now if we fail we need to clean things up) NetEventHandler handler ; if ( sockchan . connect ( addr ) ) { _outConnValidator . validateOutgoing ( sockchan ) ; // may throw // it is possible even for a non-blocking socket to connect immediately, in which // case we stick the connection in as its event handler immediately handler = conn ; } else { // otherwise we wire up a special event handler that will wait for our socket to // finish the connection process and then wire things up fully handler = new OutgoingConnectionHandler ( conn ) ; } _handlers . put ( conn . selkey , handler ) ; } catch ( IOException ioe ) { log . warning ( "Failed to initiate connection for " + sockchan + "." , ioe ) ; conn . connectFailure ( ioe ) ; // nothing else to clean up } }
Starts the connection process for an outgoing connection . This is called as part of the conmgr tick for any pending outgoing connections .