Use a VirtualConnection rather than a InboundVirtualConnection for discrimination
1440
public int discriminate(VirtualConnection vc, Object discrimData, ConnectionLink prevChannelLink) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "discriminate: " + vc);
        }
        ConnectionLink nextChannelLink = nextChannel.getConnectionLink(vc);
        prevChannelLink.setApplicationCallback(nextChannelLink);
        nextChannelLink.setDeviceLink(prevChannelLink);
        return DiscriminationProcess.SUCCESS;
    }
980310
def is_connection_to_a_vcenter(service_instance):
    '''
    
    '''
    try:
        api_type = service_instance.content.about.apiType
    except vim.fault.NoPermission as exc:
        log.exception(exc)
        raise salt.exceptions.VMwareApiError(
            'Not enough permissions. Required privilege: '
            '{}'.format(exc.privilegeId))
    except vim.fault.VimFault as exc:
        log.exception(exc)
        raise salt.exceptions.VMwareApiError(exc.msg)
    except vmodl.RuntimeFault as exc:
        log.exception(exc)
        raise salt.exceptions.VMwareRuntimeError(exc.msg)
    log.trace('api_type = %s', api_type)
    if api_type == 'VirtualCenter':
        return True
    elif api_type == 'HostAgent':
        return False
    else:
        raise salt.exceptions.VMwareApiError(
            'Unexpected api type \'{0}\' . Supported types: '
            '\'VirtualCenter/HostAgent\''.format(api_type))
770712
@Override
    public VirtualConnection write(long numBytes, TCPWriteCompletedCallback userCallback, boolean forceQueue, int timeout) {
        return write(numBytes, userCallback, forceQueue, timeout, false);
    }
1207733
@Override
    public ConnectionLink getConnectionLink(VirtualConnection vc) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "getConnectionLink");
        }

        // add this new connection link to the next in-use list based on
        // the atomic index, the extra add/mod handles the negative values
        int index = ((this.inUseIndex.getAndIncrement() % SIZE_IN_USE) + SIZE_IN_USE) % SIZE_IN_USE;

        TCPConnLink connLink = new TCPConnLink(vc, this, this.config, index);
        this.inUse[index].add(connLink);

        // assign default ConnectionType and unique ConnectionHandle to new inbound
        // connection
        // ConnectionType may seem redundant, but is used on some platforms to
        // identify
        // more than just inbound/outbound flow.
        ConnectionType.setDefaultVCConnectionType(vc);
        ConnectionHandle.getConnectionHandle(vc);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "getConnectionLink: " + connLink);
        }
        return connLink;
    }
710476
@Override
    public ConnectionLink getConnectionLink(VirtualConnection vc) {
        HttpDispatcherLink link = (HttpDispatcherLink) vc.getStateMap().get(HttpDispatcherLink.LINK_ID);
        if (null == link) {
            link = new HttpDispatcherLink();
            link.init(vc, this);
        }
        return link;
    }
1070976
def vcenter_connect(self):
        
        try:
            si = SmartConnect(
                host=self.host,
                user=self.user,
                pwd=self.password,
                port=self.port)
            # disconnect vc
            atexit.register(Disconnect, si)
        except vim.fault.InvalidLogin as e:
            print "Unable to connect to vcenter because of: {}".format(e.msg)
            sys.exit(5)
        return si
916524
def get_connection(self, provider_name='default'):
        """"""
        try:
            return self._providers[provider_name].get_connection()
        except KeyError:
            raise AssertionError(f'No Provider registered with name {provider_name}')
887781
protected void setConnectionType(VirtualConnection vc) {

        if (this.myType == 0 || vc == null) {
            ConnectionType newType = ConnectionType.getVCConnectionType(vc);
            this.myType = (newType == null) ? 0 : newType.export();
        }
    }
467444
def get_conn():
    '''
    
    '''
    if __active_provider_name__ in __context__:
        return __context__[__active_provider_name__]
    vm_ = get_configured_provider()
    profile = vm_.pop('profile', None)
    if profile is not None:
        vm_ = __utils__['dictupdate.update'](os_client_config.vendors.get_profile(profile), vm_)
    conn = shade.openstackcloud.OpenStackCloud(cloud_config=None, **vm_)
    if __active_provider_name__ is not None:
        __context__[__active_provider_name__] = conn
    return conn
1234701
def _chooseConnection(ctype, name, results):
    
    # At this point we have a list of result tuples containing (url, token, PlexServer, runtime)
    # or (url, token, None, runtime) in the case a connection could not be established.
    for url, token, result, runtime in results:
        okerr = 'OK' if result else 'ERR'
        log.info('%s connection %s (%ss): %s?X-Plex-Token=%s', ctype, okerr, runtime, url, token)
    results = [r[2] for r in results if r and r[2] is not None]
    if results:
        log.info('Connecting to %s: %s?X-Plex-Token=%s', ctype, results[0]._baseurl, results[0]._token)
        return results[0]
    raise NotFound('Unable to connect to %s: %s' % (ctype.lower(), name))
9934
public void error(VirtualConnection vc, Throwable t) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "error() called: " + vc);
        }
        // can't do anything with a null VC
        if (null == vc) {
            return;
        }
        Object o = vc.getStateMap().get(CallbackIDs.CALLBACK_HTTPICL);
        if (null == o) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "ERROR: null ICL in error()");
            }
            return;
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Error occurring while purging body: " + t);
        }
        // close the connection
        ((HttpInboundLink) o).close(vc, (Exception) t);
    }
147675
function normalizeConnectArgs(args) {
		var options = {};

		if (args[0] !== null && _typeof(args[0]) === 'object') {
			// connect(options, [cb])
			options = args[0];
		} else {
			// connect(port, [host], [cb])
			options.port = args[0];
			if (typeof args[1] === 'string') {
				options.host = args[1];
			} else {
				options.host = 'localhost';
			}
		}

		var cb = args[args.length - 1];
		return typeof cb === 'function' ? [options, cb] : [options];
	}
1079731
public ConnectionLink getConnectionLink(VirtualConnection vc) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(this, tc, "getConnectionLink");
        }

        UDPConnLink connLink = new UDPConnLink(workQueueManager, vc, this, getConfig());

        // add connection to inUse LinkedList
        synchronized (inUse) {
            inUse.add(connLink);
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(this, tc, "getConnectionLink: " + connLink);
        }
        return connLink;
    }
74874
def native_conn(self):
        """"""
        if self.__native is None:
            self.__native = self._get_connection()

        return self.__native
1127873
public void forceConnect(SIBUuid8 meUuid) 
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "forceConnect", meUuid);
    
    if(_routingManager!=null)
      _routingManager.connectToME(meUuid);
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "forceConnect");
  }
946275
public static ConnectionHandle getConnectionHandle(VirtualConnection vc) {
        if (vc == null) {
            return null;
        }

        ConnectionHandle connHandle = (ConnectionHandle) vc.getStateMap().get(CONNECTION_HANDLE_VC_KEY);

        // We can be here for two reasons:
        // a) We have one, just needed to find it in VC state map
        if (connHandle != null)
            return connHandle;

        // b) We want a new one
        connHandle = factory.createConnectionHandle();

        // For some connections (outbound, most notably), the connection type
        // will be set on the VC before connect... in which case, read it
        // and set it on the connection handle at the earliest point
        // possible.
        if (connHandle != null) {
            connHandle.setConnectionType(vc);
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "getConnectionHandle - created new connection handle: " + connHandle);
        }

        setConnectionHandle(vc, connHandle);
        return connHandle;
    }
778183
protected VirtualConnection write(long _numBytes, TCPWriteCompletedCallback userCallback,
                                      boolean forceQueue, int timeout, boolean fromQueue) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "writeAsync, numBytes=" + _numBytes + ", timeout=" + timeout
                         + ", fromQueue=" + fromQueue + ", vc=" + getVCHash());
        }
        VirtualConnection vc = null;
        try {
            long numBytes = _numBytes;

            // Handle timing out of former read request.
            if (timeout == IMMED_TIMEOUT || timeout == ABORT_TIMEOUT) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Requested to timeout former request.  Calling device side.");
                }
                getConnLink().getDeviceWriteInterface().write(numBytes, this, forceQueue, timeout);
                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
                    Tr.exit(tc, "writeAsync: " + getVC());
                }
                return getVC();
            }

            // Look for errors in the request.
            IOException exceptionInRequest = checkForErrors(numBytes, true);
            if (exceptionInRequest != null) {
                // Found an error.
                boolean fireHere = true;
                if (forceQueue) {
                    // Error must be returned on a separate thread.
                    queuedWork.setErrorParameters(getConnLink().getVirtualConnection(),
                                                this, userCallback, exceptionInRequest);

                    EventEngine events = SSLChannelProvider.getEventService();
                    if (null == events) {
                        Exception e = new Exception("missing event admin");
                        FFDCFilter.processException(e, getClass().getName(), "172", this);
                        // fall-thru below and use callback here regardless
                    } else {
                        // fire an event to continue this queued work
                        Event event = events.createEvent(SSLEventHandler.TOPIC_QUEUED_WORK);
                        event.setProperty(SSLEventHandler.KEY_RUNNABLE, this.queuedWork);
                        events.postEvent(event);
                        fireHere = false;
                    }
                }
                if (fireHere) {
                    // Call the callback on this thread.
                    userCallback.error(getConnLink().getVirtualConnection(), this, exceptionInRequest);
                }
                // Return null indicating that the callback will handle the response.
                return null;
            }

            // Get the work on another thread if queuing is being forced.
            if (forceQueue) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Forcing write request to another thread, vc=" + getVCHash());
                }
                queuedWork.setWriteParameters(numBytes, userCallback, timeout);

                EventEngine events = SSLChannelProvider.getEventService();
                if (null == events) {
                    IOException e = new IOException("missing event admin");
                    FFDCFilter.processException(e, getClass().getName(), "471", this);
                    userCallback.error(getConnLink().getVirtualConnection(), this, e);
                } else {
                    // fire an event to continue this queued work
                    Event event = events.createEvent(SSLEventHandler.TOPIC_QUEUED_WORK);
                    event.setProperty(SSLEventHandler.KEY_RUNNABLE, this.queuedWork);
                    events.postEvent(event);
                }
                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
                    Tr.exit(tc, "writeAsync: null");
                }
                return null;
            }

            callback = userCallback;

            // Adjust size of numBytes if all data is requested to be written (-1).
            if (numBytes == TCPWriteRequestContext.WRITE_ALL_DATA) {
                numBytes = WsByteBufferUtils.lengthOf(getBuffers());
            }

            SSLEngineResult sslResult = null;

            // Check if a handshake is needed.
            if (SSLUtils.isHandshaking(getConnLink().getSSLEngine())) {
                // A handshake is needed. Set the write parameters.
                handshakeCallback.setWriteParameters(numBytes, timeout);
                try {
                    sslResult = doHandshake(handshakeCallback);
                } catch (IOException e) {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "Caught exception during SSL handshake, " + e);
                    }
                    callback.error(getConnLink().getVirtualConnection(), this, e);
                    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
                        Tr.exit(tc, "writeAsynch: null");
                    }
                    return null;
                }
                // Check to see if handshake was done synchronously.
                if (sslResult != null) {
                    // Handshake was done synchronously. Verify results.
                    if (sslResult.getHandshakeStatus() != HandshakeStatus.FINISHED) {
                        IOException e = new IOException("Unable to complete SSLhandshake");
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                            Tr.debug(tc, "Unable to complete SSLhandshake, " + e);
                        }
                        callback.error(getConnLink().getVirtualConnection(), this, e);
                            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
                            Tr.exit(tc, "writeAsynch: null");
                        }
                        return null;
                    }
                } else {
                    // Handshake is being handled asynchronously.
                    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
                        Tr.exit(tc, "writeAsynch: null");
                    }
                    return null;
                }
            }

            // Code can only get here if handshake wasn't needed or was done sync with valid return code.
            // Encrypt the data and write it to the network.
            vc = encryptAndWriteAsync(numBytes, false, timeout);

            // If data is ready, but this was from a formerly queued request, call the callback.
            if (vc != null && fromQueue) {
                callback.complete(vc, this);
                vc = null;
            }
        } catch (Exception original) {
            synchronized (closeSync) {
                // if close has been called then assume this exception was due to a race condition
                // with the close logic. so no FFDC here.
                if (closeCalled) {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "Cannot write, the link was already closed; vc=" +this.getVCHash());
                    }
                    return null;
                } else {
                    IOException ioe;
                    if (original instanceof IOException) {
                        ioe = (IOException) original;
                    }
                    ioe = new IOException("writeAsynch failed with exception: " +original.getMessage());
                    boolean fireHere = true;
                    if (forceQueue) {
                        // Error must be returned on a separate thread.
                        queuedWork.setErrorParameters(getConnLink().getVirtualConnection(),
                                                    this, userCallback, ioe);
                        EventEngine events = SSLChannelProvider.getEventService();
                        if (null != events) {
                            // fire an event to continue this queued work
                            Event event = events.createEvent(SSLEventHandler.TOPIC_QUEUED_WORK);
                            event.setProperty(SSLEventHandler.KEY_RUNNABLE, this.queuedWork);
                            events.postEvent(event);
                            fireHere = false;
                        }
                    }
                    if (fireHere) {
                        // Call the callback on this thread.
                        userCallback.error(getConnLink().getVirtualConnection(), this, ioe);
                    }
                    return null;
                }
            }
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "writeAsynch: " + vc);
        }
        return vc;
    }