SocketIOChannel getConnection ( TCPConnectRequestContext connectContext , TCPConnLink tcpConnLink , SimpleSync blocking ) throws IOException { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) { Tr . entry ( tc , "getConnection for local: " + connectContext . getLocalAddress ( ) + ", remote: " + connectContext . getRemoteAddress ( ) + ", timeout: " + connectContext . getConnectTimeout ( ) ) ; } // create will throw an IOException or return a non-null value SocketIOChannel ioSocket = create ( connectContext . getLocalAddress ( ) , tcpConnLink ) ; // set ioSocket in TCPConnLink tcpConnLink . setSocketIOChannel ( ioSocket ) ; boolean isConnected = ioSocket . connect ( connectContext . getRemoteAddress ( ) ) ; // if isConnected is true, then connect happened immediately. // This could happen even for non-blocking if ( isConnected ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "obtained connection without queuing to selector" ) ; } tcpConnLink . setCallCompleteLocal ( true ) ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) { Tr . exit ( tc , "getConnection" ) ; } return ioSocket ; } // Create new work for the nonblocking connect selector - register for // finishConnect. ConnectInfo ci = new ConnectInfo ( connectContext , tcpConnLink , ioSocket ) ; ci . timeout = connectContext . getConnectTimeout ( ) ; if ( blocking != null ) { // synchronous connect, so we want to do the connect work on this thread ci . setSyncObject ( blocking ) ; } ci . setFinish ( ) ; workQueueMgr . queueConnectForSelector ( ci ) ; if ( blocking != null ) { // synchronous blocking call boolean connectDone = false ; while ( ! connectDone ) { blocking . simpleWait ( ) ; connectDone = workQueueMgr . attemptConnectWork ( ci ) ; } if ( ci . getAction ( ) == ConnectInfo . FINISH_COMPLETE ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) { Tr . exit ( tc , "getConnection" ) ; } return ioSocket ; } if ( ci . getError ( ) == null ) { // Add local and remote address information InetSocketAddress iaRemote = ci . remoteAddress ; InetSocketAddress iaLocal = ci . localAddress ; ci . setError ( new IOException ( "Connection could not be established. local=" + iaLocal + " remote=" + iaRemote ) ) ; } throw ci . getError ( ) ; } if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) { Tr . exit ( tc , "getConnection" ) ; } // Return a null to the (async) caller to indicate the connect is still in // progress. return null ; }
Get a connection .