Merges this and {@code discoveredConnections} into a new {@link Connections} instance. This instance is marked as closed
to prevent lingering connections.

@param discoveredConnections
@return
512835
public Connections mergeWith(Connections discoveredConnections) {

        Map<RedisURI, StatefulRedisConnection<String, String>> result = new TreeMap<>(
                TopologyComparators.RedisURIComparator.INSTANCE);

        this.closed = true;
        discoveredConnections.closed = true;

        synchronized (this.connections) {
            synchronized (discoveredConnections.connections) {

                result.putAll(this.connections);
                result.putAll(discoveredConnections.connections);
            }
        }

        return new Connections(result);
    }
867478
private ClientImpl createClientAndConnect() throws UnknownHostException, IOException
    {
        // Make client connections.
        ClientImpl clientTmp = (ClientImpl) ClientFactory.createClient(this.config);
        // ENG-6231: Only fail if we can't connect to any of the provided servers.
        boolean connectedAnything = false;
        for (String server : this.servers) {
            try {
                clientTmp.createConnection(server);
                connectedAnything = true;
            }
            catch (UnknownHostException e) {
            }
            catch (IOException e) {
            }
        }

        if (!connectedAnything) {
            try {
                clientTmp.close();
            } catch (InterruptedException ie) {}
            throw new IOException("Unable to connect to VoltDB cluster with servers: " + this.servers);
        }

        this.client.set(clientTmp);
        this.users++;
        return clientTmp;
    }
182727
@Override
    public void addNewConnective() {

        String factType = getExpressionLeftSide().getPreviousGenericType();
        if ( factType == null ) {
            factType = getExpressionLeftSide().getGenericType();
        }
        String fieldName = getExpressionLeftSide().getFieldName();
        String fieldType = getExpressionLeftSide().getGenericType();

        if ( this.getConnectives() == null ) {
            this.setConnectives( new ConnectiveConstraint[]{ new ConnectiveConstraint( factType,
                                                                                       fieldName,
                                                                                       fieldType ) } );
        } else {
            final ConnectiveConstraint[] newList = new ConnectiveConstraint[ this.getConnectives().length + 1 ];
            for ( int i = 0; i < this.getConnectives().length; i++ ) {
                newList[ i ] = this.getConnectives()[ i ];
            }
            newList[ this.getConnectives().length ] = new ConnectiveConstraint( factType,
                                                                                fieldName,
                                                                                fieldType );
            this.setConnectives( newList );
        }
    }
531005
protected SICoreConnection createConnection() throws SIResourceException {
        if (TraceComponent.isAnyTracingEnabled()
            && tc.isEntryEnabled())
            SibTr.entry(tc, "createConnection");

        SICoreConnection newConn = new ConnectionImpl(this, null, null);

        // Lock the connections so that we can't be stopped midway through a
        // create
        _connectionsLockManager.lock();

        try {
            // Now we have a lock make sure we are started.
            checkStarted();

            synchronized (_connections) {
                _connections.put(newConn, newConn);
            }
        } finally {
            _connectionsLockManager.unlock();
        }

        if (TraceComponent.isAnyTracingEnabled()
            && tc.isEntryEnabled())
            SibTr.exit(tc, "createConnection", newConn);

        return newConn;
    }
893759
public static RedisConnectionException create(Throwable cause) {

        if (cause instanceof RedisConnectionException) {
            return new RedisConnectionException(cause.getMessage(), cause.getCause());
        }

        return new RedisConnectionException("Unable to connect", cause);
    }
813048
public java.util.List<ClientVpnConnection> getConnections() {
        if (connections == null) {
            connections = new com.amazonaws.internal.SdkInternalList<ClientVpnConnection>();
        }
        return connections;
    }
1168268
public java.util.List<TerminateConnectionStatus> getConnectionStatuses() {
        if (connectionStatuses == null) {
            connectionStatuses = new com.amazonaws.internal.SdkInternalList<TerminateConnectionStatus>();
        }
        return connectionStatuses;
    }
108219
public List<ConnectionListener> getConnectionListeners() {
        if (changes == null) {
            return (List<ConnectionListener>)Collections.EMPTY_LIST;
        }

        List<EventListener> listeners = changes.getListenerList(AMQP);
        if ((listeners == null) || listeners.isEmpty()) {
            return (List<ConnectionListener>)Collections.EMPTY_LIST;
        }

        ArrayList<ConnectionListener> list = new ArrayList<ConnectionListener>();
        for (EventListener listener : listeners) {
            list.add((ConnectionListener)listener);
        }

        return list;
    }
1301550
@VisibleForTesting
    @Synchronized
    public void pruneUnusedConnections() {
        for (List<Connection> connections : connectionMap.values()) {
            for (Iterator<Connection> iterator = connections.iterator(); iterator.hasNext();) {
                Connection connection = iterator.next();
                if (isUnused(connection)) {
                    connection.getFlowHandler().close();
                    iterator.remove();
                }
            }
        }
    }
435423
@Override
    public ConnectionFactory createConnectionFactory(JmsJcaConnectionFactory jcaConnectionFactory, JmsJcaManagedConnectionFactory jcaManagedConnectionFactory) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "createConnectionFactory", new Object[] { jcaConnectionFactory, jcaManagedConnectionFactory });
        ConnectionFactory cf = new JmsConnectionFactoryImpl(jcaConnectionFactory, jcaManagedConnectionFactory);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "createConnectionFactory", cf);
        return cf;
    }
598408
public void readConnections(ConfigParams connections) {
		synchronized (_lock) {
			_items.clear();
			for (Map.Entry<String, String> entry : connections.entrySet()) {
				DiscoveryItem item = new DiscoveryItem();
				item.key = entry.getKey();
				item.connection = ConnectionParams.fromString(entry.getValue());
				_items.add(item);
			}
		}
	}
879488
public JcCollection<JcRelation> relations() {
		return new JcCollection<JcRelation>(null, this,
				new FunctionInstance(FUNCTION.Path.RELATIONS, 1), JcRelation.class);
	}
1050332
public java.util.List<String> getConnectIps() {
        if (connectIps == null) {
            connectIps = new com.amazonaws.internal.SdkInternalList<String>();
        }
        return connectIps;
    }
813417
private CompletionStage<Void> initializeSentinels() {

        if (closed) {
            return closeFuture;
        }

        Duration timeout = getTimeout();

        List<ConnectionFuture<StatefulRedisPubSubConnection<String, String>>> connectionFutures = potentiallyConnectSentinels();

        if (connectionFutures.isEmpty()) {
            return CompletableFuture.completedFuture(null);
        }

        if (closed) {
            return closeAsync();
        }

        SentinelTopologyRefreshConnections collector = collectConnections(connectionFutures);

        CompletionStage<SentinelTopologyRefreshConnections> completionStage = collector.getOrTimeout(timeout, redisClient
                .getResources().eventExecutorGroup());

        return completionStage.whenComplete((aVoid, throwable) -> {

            if (throwable != null) {
                closeAsync();
            }
        }).thenApply(noop -> (Void) null);
    }
448319
void addInstance(final Class<?> discoveredType, final Object newlyConstructed)
	{
		WeakHashMap<Object, Void> map;

		synchronized (instances)
		{
			map = instances.get(discoveredType);

			if (map == null)
			{
				map = new WeakHashMap<>();
				instances.put(discoveredType, map);
			}
		}

		synchronized (map)
		{
			map.put(newlyConstructed, null);
		}
	}
558613
private CompletableFuture<Connection> connect() {
    // If the address selector has been reset then reset the connection.
    if (selector.state() == AddressSelector.State.RESET && connection != null) {
      if (connectFuture != null) {
        return connectFuture;
      }

      CompletableFuture<Connection> future = new OrderedCompletableFuture<>();
      future.whenComplete((r, e) -> this.connectFuture = null);
      this.connectFuture = future;

      Connection oldConnection = this.connection;
      this.connection = null;
      oldConnection.close();
      connect(future);
      return future;
    }

    // If a connection was already established then use that connection.
    if (connection != null) {
      return CompletableFuture.completedFuture(connection);
    }

    // If a connection is currently being established then piggyback on the connect future.
    if (connectFuture != null) {
      return connectFuture;
    }

    // Create a new connect future and connect to the first server in the cluster.
    CompletableFuture<Connection> future = new OrderedCompletableFuture<>();
    future.whenComplete((r, e) -> this.connectFuture = null);
    this.connectFuture = future;
    reset().connect(future);
    return future;
  }
446108
public Set<CassandraHost> discoverNodes() {
    Cluster cluster =  HFactory.getCluster(connectionManager.getClusterName());
    if (cluster == null) {
      return null;
    }

    Set<CassandraHost> existingHosts = connectionManager.getHosts();
    Set<CassandraHost> foundHosts = new HashSet<CassandraHost>();

    if (log.isDebugEnabled()) {
      log.debug("using existing hosts {}", existingHosts);
    }

    try {

      for (KeyspaceDefinition keyspaceDefinition : cluster.describeKeyspaces()) {
        if (!keyspaceDefinition.getName().equals(Keyspace.KEYSPACE_SYSTEM)) {
          List<TokenRange> tokenRanges = cluster.describeRing(keyspaceDefinition.getName());
          for (TokenRange tokenRange : tokenRanges) {

            for (EndpointDetails endPointDetail : tokenRange.getEndpoint_details()) {
              // Check if we are allowed to include this Data
              // Center.
              if (dataCenterValidator == null
                  || dataCenterValidator.validate(endPointDetail.getDatacenter())) {
                // Maybe add this host if it's a new host.
                CassandraHost foundHost = new CassandraHost(endPointDetail.getHost(),
                    cassandraHostConfigurator.getPort());
                if (!existingHosts.contains(foundHost)) {
                  log.info("Found a node we don't know about {} for TokenRange {}", foundHost,
                      tokenRange);
                  foundHosts.add(foundHost);
                }
              }
            }

          }
          break;
        }
      }
    } catch (Exception e) {
      log.error("Discovery Service failed attempt to connect CassandraHost", e);
    }

    return foundHosts;
  }