Assign the default ConnectionType (INBOUND or OUTBOUND) to
the VirtualConnection.

@param vc
VirtualConnection to add ConnectionType to
762096
public static void setDefaultVCConnectionType(VirtualConnection vc) {
        if (vc == null) {
            return;
        }

        Map<Object, Object> map = vc.getStateMap();

        // Pick defaults for INBOUND/OUTBOUND
        // setVCConnectionType will only set these values in the VC if
        // a type has not been preset.
        if (map.get(CONNECTION_TYPE_VC_KEY) == null) {
            if (vc instanceof InboundVirtualConnection) {
                map.put(CONNECTION_TYPE_VC_KEY, ConnectionType.INBOUND);
            } else {
                map.put(CONNECTION_TYPE_VC_KEY, ConnectionType.OUTBOUND);
            }
        }
    }
326490
public void setVpcPeeringConnections(java.util.Collection<VpcPeeringConnection> vpcPeeringConnections) {
        if (vpcPeeringConnections == null) {
            this.vpcPeeringConnections = null;
            return;
        }

        this.vpcPeeringConnections = new java.util.ArrayList<VpcPeeringConnection>(vpcPeeringConnections);
    }
882901
public static void setVCConnectionType(VirtualConnection vc, ConnectionType connType) {
        if (vc == null || connType == null) {
            return;
        }

        Map<Object, Object> map = vc.getStateMap();

        // Internal connections are both inbound and outbound (they're connections
        // to ourselves)
        // so while we prevent setting Outbound ConnTypes for inbound connections
        // and vice versa,
        // we don't prevent internal types from being set as either.
        if (vc instanceof InboundVirtualConnection && ConnectionType.isOutbound(connType.type)) {
            throw new IllegalStateException("Cannot set outbound ConnectionType on inbound VirtualConnection");
        } else if (vc instanceof OutboundVirtualConnection && ConnectionType.isInbound(connType.type)) {
            throw new IllegalStateException("Cannot set inbound ConnectionType on outbound VirtualConnection");
        }

        map.put(CONNECTION_TYPE_VC_KEY, connType);
    }
919548
public Object openConnection(String proxyHost, int proxyPort, Proxy.Type proxyType) throws ConnectionException {
        try {
            String endpointUri = getEndpointUri();
            if (endpointUri == null)
                throw new ConnectionException("Missing endpoint URI");
            Map<String,String> params = getRequestParameters();
            if (params != null && !params.isEmpty()) {
                StringBuffer query = new StringBuffer();
                query.append(endpointUri.indexOf('?') < 0 ? '?' : '&');
                int count = 0;
                for (String name : params.keySet()) {
                    if (count > 0)
                        query.append('&');
                    String encoding = getUrlEncoding();
                    query.append(encoding == null ? name : URLEncoder.encode(name, encoding)).append("=");
                    query.append(encoding == null ? params.get(name) : URLEncoder.encode(params.get(name), encoding));
                    count++;
                }
                endpointUri += query;
            }
            logdebug("REST adapter endpoint: " + endpointUri);
            URL url = new URL(endpointUri);
            HttpConnection httpConnection;
            if ("PATCH".equals(getHttpMethod()))
                httpConnection = new HttpAltConnection(url);
            else
                httpConnection = new HttpConnection(url);

            if (proxyHost != null)
                httpConnection.setProxyHost(proxyHost);
            if (proxyPort > 0)
                httpConnection.setProxyPort(proxyPort);
            if (proxyType != null)
                httpConnection.setProxyType(proxyType);

            httpConnection.open();
            return httpConnection;
        }
        catch (Exception ex) {
            throw new ConnectionException(ConnectionException.CONNECTION_DOWN, ex.getMessage(), ex);
        }
    }
551049
public void setConnectionProperties(Map connectionProperties)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
        {
            SibTr.entry(tc, "getConnectionProperties", connectionProperties);
            SibTr.exit(tc, "getConnectionProperties");
        }
        _connectionProperties = connectionProperties;
    }
375590
public void setCooccurrenceType(String v) {
    if (Cooccurrence_Type.featOkTst && ((Cooccurrence_Type)jcasType).casFeat_cooccurrenceType == null)
      jcasType.jcas.throwFeatMissing("cooccurrenceType", "ch.epfl.bbp.uima.types.Cooccurrence");
    jcasType.ll_cas.ll_setStringValue(addr, ((Cooccurrence_Type)jcasType).casFeatCode_cooccurrenceType, v);}
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;
    }
429513
protected DatagramSocket initDatagramSocket(VirtualConnection vc) throws IOException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Create new DatagramSocket: " + vc);
        }
        UDPChannelConfiguration channelConfig = udpChannel.getConfig();
        InetSocketAddress address = null;

        if (localBindAddress != null) {
            if (localBindAddress.equals("*")) {
                localBindAddress = "0.0.0.0";
            }
            address = new InetSocketAddress(localBindAddress, localBindPort);

            if (address.isUnresolved()) {
                String displayableHostName = channelConfig.getHostname();
                if (displayableHostName == null) {
                    displayableHostName = "*";
                }
                Tr.error(tc, "CWUDP0004E", new Object[] { channelConfig.getExternalName(), displayableHostName, String.valueOf(channelConfig.getPort()) });
                throw (new IOException("local address unresolved"));
            }
        }

        datagramChannel = DatagramChannel.open();
        DatagramSocket datagramSocket = datagramChannel.socket();

        // never reuse - only one app can have the port open
        datagramSocket.setReuseAddress(false);
        datagramChannel.configureBlocking(false);

        // receieve buffer size for sockets is set on datagramSocket,
        // send buffer size is set on individual sockets

        if ((channelConfig.getReceiveBufferSize() >= UDPConfigConstants.RECEIVE_BUFFER_SIZE_MIN)
            && (channelConfig.getReceiveBufferSize() <= UDPConfigConstants.RECEIVE_BUFFER_SIZE_MAX)) {
            int size = datagramSocket.getReceiveBufferSize();
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "setting receive buffer to size " + channelConfig.getReceiveBufferSize());
            }
            try {
                datagramSocket.setReceiveBufferSize(channelConfig.getReceiveBufferSize());
                int size1 = datagramSocket.getReceiveBufferSize();
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    if (size == size1) {
                        Tr.debug(tc, "setting receive buffer had no effect, still the same size ");
                    }
                }
            } catch (SocketException e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Caught SocketException " + e.getMessage() + " while trying to setReceiveBufferSize to " + channelConfig.getReceiveBufferSize());
                }
            } catch (IllegalArgumentException e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Caught IllegalArgumentException " + e.getMessage() + " while trying to setReceiveBufferSize to " + channelConfig.getReceiveBufferSize());
                }
            }
        }
        if ((channelConfig.getSendBufferSize() >= UDPConfigConstants.SEND_BUFFER_SIZE_MIN) && (channelConfig.getSendBufferSize() <= UDPConfigConstants.SEND_BUFFER_SIZE_MAX)) {
            int size = datagramSocket.getSendBufferSize();
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "setting send buffer to size " + channelConfig.getSendBufferSize());
            }
            try {
                datagramSocket.setSendBufferSize(channelConfig.getSendBufferSize());
                int size1 = datagramSocket.getSendBufferSize();
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    if (size == size1) {
                        Tr.debug(tc, "setting send buffer had no effect, still the same size ");
                    }
                }
            } catch (SocketException e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Caught SocketException " + e.getMessage() + " while trying to setSendBufferSize to " + channelConfig.getSendBufferSize());
                }
            } catch (IllegalArgumentException e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Caught IllegalArgumentException " + e.getMessage() + " while trying to setSendBufferSize to " + channelConfig.getSendBufferSize());
                }
            }
        }
        try {
            datagramSocket.bind(address);
            selectorMonitor.setChannel(datagramChannel, this);
        } catch (IOException ioe) {
            String displayableHostName = channelConfig.getHostname();
            if (displayableHostName == null) {
                displayableHostName = "*";
            }
            Tr.error(tc, "CWUDP0005E", new Object[] { channelConfig.getExternalName(), displayableHostName, String.valueOf(channelConfig.getPort()) });
            throw new IOException(ioe.getMessage());
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "new ServerSocket successfully created");
        }

        return datagramChannel.socket();
    }
93851
public static void setConnectionHandle(VirtualConnection vc, ConnectionHandle handle) {
        if (vc == null || handle == null) {
            return;
        }
        Map<Object, Object> map = vc.getStateMap();

        // set connection handle into VC
        Object vcLock = vc.getLockObject();
        synchronized (vcLock) {
            Object tmpHandle = map.get(CONNECTION_HANDLE_VC_KEY);

            // If this connection already has a unique handle when we get here,
            // something went wrong.
            if (tmpHandle != null) {
                throw new IllegalStateException("Connection " + tmpHandle + " has already been created");
            }

            map.put(CONNECTION_HANDLE_VC_KEY, handle);
        }
    }
783406
@SuppressWarnings("unchecked")
  protected <R> void connect(final EtcdRequest<R> etcdRequest, final ConnectionState connectionState) throws IOException {
    if(eventLoopGroup.isShuttingDown() || eventLoopGroup.isShutdown() || eventLoopGroup.isTerminated()){
      etcdRequest.getPromise().getNettyPromise().cancel(true);
      logger.debug("Retry canceled because of closed etcd client");
      return;
    }

    final URI uri;

    // when we are called from a redirect, the url in the request may also
    // contain host and port!
    URI requestUri = URI.create(etcdRequest.getUrl());
    if (requestUri.getHost() != null && requestUri.getPort() > -1) {
      uri = requestUri;
    } else if (connectionState.uris.length == 0 && System.getenv(ENV_ETCD4J_ENDPOINT) != null) {
      // read uri from environment variable
      String endpoint_uri = System.getenv(ENV_ETCD4J_ENDPOINT);
      if(logger.isDebugEnabled()) {
        logger.debug("Will use environment variable {} as uri with value {}", ENV_ETCD4J_ENDPOINT, endpoint_uri);
      }
      uri = URI.create(endpoint_uri);
    } else {
      uri = connectionState.uris[connectionState.uriIndex];
    }

    // Start the connection attempt.
    final ChannelFuture connectFuture = bootstrap.connect(connectAddress(uri));
    etcdRequest.getPromise().getConnectionState().loop = connectFuture.channel().eventLoop();
    etcdRequest.getPromise().attachNettyPromise(connectFuture.channel().eventLoop().<R>newPromise());

    connectFuture.addListener(new GenericFutureListener<ChannelFuture>() {
      @Override
      public void operationComplete(final ChannelFuture f) throws Exception {
        if (!f.isSuccess()) {
          final Throwable cause = f.cause();
          if (logger.isDebugEnabled()) {
            logger.debug("Connection failed to {}, cause {}", connectionState.uris[connectionState.uriIndex], cause);
          }

          if (cause instanceof ClosedChannelException || cause instanceof IllegalStateException) {
            etcdRequest.getPromise().cancel(new CancellationException("Channel closed"));
          } else {
            etcdRequest.getPromise().handleRetry(f.cause());
          }

          return;
        }

        // Handle already cancelled promises
        if (etcdRequest.getPromise().getNettyPromise().isCancelled()) {
          f.channel().close();
          etcdRequest.getPromise().getNettyPromise().setFailure(new CancellationException());
          return;
        }

        final Promise listenedToPromise = etcdRequest.getPromise().getNettyPromise();

        // Close channel when promise is satisfied or cancelled later
        listenedToPromise.addListener(new GenericFutureListener<Future<?>>() {
          @Override
          public void operationComplete(Future<?> future) throws Exception {
            // Only close if it was not redirected to new promise
            if (etcdRequest.getPromise().getNettyPromise() == listenedToPromise) {
              f.channel().close();
            }
          }
        });

        if (logger.isDebugEnabled()) {
          logger.debug("Connected to {} ({})", f.channel().remoteAddress().toString(), connectionState.uriIndex);
        }

        lastWorkingUriIndex = connectionState.uriIndex;

        modifyPipeLine(etcdRequest, f.channel().pipeline());

        createAndSendHttpRequest(uri, etcdRequest.getUrl(), etcdRequest, f.channel())
          .addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
              if (!future.isSuccess()) {
                etcdRequest.getPromise().setException(future.cause());
                if (!f.channel().eventLoop().inEventLoop()) {
                  f.channel().eventLoop().shutdownGracefully();
                }

                f.channel().close();
              }
            }
          });

        f.channel().closeFuture().addListener(new ChannelFutureListener() {
          @Override
          public void operationComplete(ChannelFuture future) throws Exception {
            if (logger.isDebugEnabled()) {
              logger.debug("Connection closed for request {} on uri {} ",
              etcdRequest.getMethod().name(),
              etcdRequest.getUri());
            }
          }
        });
      }
    });
  }
76204
public ConnectionInput withConnectionProperties(java.util.Map<String, String> connectionProperties) {
        setConnectionProperties(connectionProperties);
        return this;
    }
383098
public void connectServer(Connection connection) {
    threadContext.checkThread();

    // Handlers for all request types are registered since requests can be proxied between servers.
    // Note we do not use method references here because the "state" variable changes over time.
    // We have to use lambdas to ensure the request handler points to the current state.
    connection.handler(RegisterRequest.class, (Function<RegisterRequest, CompletableFuture<RegisterResponse>>) request -> state.register(request));
    connection.handler(ConnectRequest.class, (Function<ConnectRequest, CompletableFuture<ConnectResponse>>) request -> state.connect(request, connection));
    connection.handler(KeepAliveRequest.class, (Function<KeepAliveRequest, CompletableFuture<KeepAliveResponse>>) request -> state.keepAlive(request));
    connection.handler(UnregisterRequest.class, (Function<UnregisterRequest, CompletableFuture<UnregisterResponse>>) request -> state.unregister(request));
    connection.handler(ResetRequest.class, (Consumer<ResetRequest>) request -> state.reset(request));
    connection.handler(ConfigureRequest.class, (Function<ConfigureRequest, CompletableFuture<ConfigureResponse>>) request -> state.configure(request));
    connection.handler(InstallRequest.class, (Function<InstallRequest, CompletableFuture<InstallResponse>>) request -> state.install(request));
    connection.handler(JoinRequest.class, (Function<JoinRequest, CompletableFuture<JoinResponse>>) request -> state.join(request));
    connection.handler(ReconfigureRequest.class, (Function<ReconfigureRequest, CompletableFuture<ReconfigureResponse>>) request -> state.reconfigure(request));
    connection.handler(LeaveRequest.class, (Function<LeaveRequest, CompletableFuture<LeaveResponse>>) request -> state.leave(request));
    connection.handler(AppendRequest.class, (Function<AppendRequest, CompletableFuture<AppendResponse>>) request -> state.append(request));
    connection.handler(PollRequest.class, (Function<PollRequest, CompletableFuture<PollResponse>>) request -> state.poll(request));
    connection.handler(VoteRequest.class, (Function<VoteRequest, CompletableFuture<VoteResponse>>) request -> state.vote(request));
    connection.handler(CommandRequest.class, (Function<CommandRequest, CompletableFuture<CommandResponse>>) request -> state.command(request));
    connection.handler(QueryRequest.class, (Function<QueryRequest, CompletableFuture<QueryResponse>>) request -> state.query(request));

    connection.onClose(stateMachine.executor().context().sessions()::unregisterConnection);
  }
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);
    }
271354
public void setOutboundConnectionInfo(Map<String, Object> connectionInfo) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "setOutboundConnectionInfo");
        this.outboundConnectionInfo = connectionInfo;
    }
160729
@Override
	public void setMaxHostConnections(int maxHostConnections) {
    	connectionManager.getParams().setDefaultMaxConnectionsPerHost(maxHostConnections);
    	connectionManager.getParams().setMaxConnectionsPerHost(hostConfiguration, maxHostConnections);
    }
1317557
func (s *UpdateIntegrationInput) SetConnectionType(v string) *UpdateIntegrationInput {
	s.ConnectionType = &v
	return s
}
682632
public void createNetworkAdapter(VirtualNetworkAdapterType type, String networkName, String macAddress, boolean wakeOnLan, boolean startConnected) throws InvalidProperty, RuntimeFault, RemoteException, InterruptedException {
        VirtualMachinePowerState powerState = vm.getRuntime().getPowerState();
        String vmVerStr = vm.getConfig().getVersion();
        int vmVer = Integer.parseInt(vmVerStr.substring(vmVerStr.length() - 2));

        if ((powerState == VirtualMachinePowerState.suspended)) {
            throw new InvalidPowerState();
        }

        HostSystem host = new HostSystem(vm.getServerConnection(), vm.getRuntime().getHost());
        ComputeResource cr = (ComputeResource) host.getParent();
        EnvironmentBrowser envBrowser = cr.getEnvironmentBrowser();
        ConfigTarget configTarget = envBrowser.queryConfigTarget(host);
        VirtualMachineConfigOption vmCfgOpt = envBrowser.queryConfigOption(null, host);

        type = validateNicType(vmCfgOpt.getGuestOSDescriptor(), vm.getConfig().getGuestId(), type);

        VirtualDeviceConfigSpec nicSpec = createNicSpec(type, networkName, macAddress, wakeOnLan, startConnected, configTarget);

        VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
        vmConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec[]{nicSpec});
        Task task = vm.reconfigVM_Task(vmConfigSpec);

        task.waitForTask(200, 100);
    }