Wrap a connection along its {@link Origin} reference.

@param connection
@param pool
@param <T>
@return
11664
@SuppressWarnings({ "unchecked", "rawtypes" })
    static <T> T wrapConnection(T connection, Origin<T> pool) {

        ReturnObjectOnCloseInvocationHandler<T> handler = new ReturnObjectOnCloseInvocationHandler<T>(connection, pool);

        Class<?>[] implementedInterfaces = connection.getClass().getInterfaces();
        Class[] interfaces = new Class[implementedInterfaces.length + 1];
        interfaces[0] = HasTargetConnection.class;
        System.arraycopy(implementedInterfaces, 0, interfaces, 1, implementedInterfaces.length);

        T proxiedConnection = (T) Proxy.newProxyInstance(connection.getClass().getClassLoader(), interfaces, handler);
        handler.setProxiedConnection(proxiedConnection);

        return proxiedConnection;
    }
309463
@Override
    public Connection makeObject(ObjectPoolWithThreadAffinity<Connection> pool) throws Exception
    {
        Connection conn = connectionFactory.createConnection();
        return new PooledConnection(conn, pool, this.statementsToPool);
    }
1255656
public void copy(ConnectionContext source) {
        this.connection = source.connection;
        this.session = source.session;
        this.destination = source.destination;
    }
565870
protected B connection(Http2Connection connection) {
        enforceConstraint("connection", "maxReservedStreams", maxReservedStreams);
        enforceConstraint("connection", "server", isServer);
        enforceConstraint("connection", "codec", decoder);
        enforceConstraint("connection", "codec", encoder);

        this.connection = checkNotNull(connection, "connection");

        return self();
    }
1081768
public ConnectionPool getPool(String poolName)
            throws ConnectionPoolNotFoundException {
        ConnectionPool connectionPool = null;

        try {
            if (h_ConnectionPools.containsKey(poolName)) {
                connectionPool = h_ConnectionPools.get(poolName);
            } else {
                // Error: pool was never initialized or name could not be found
                throw new ConnectionPoolNotFoundException("Connection pool "
                        + "not found: " + poolName);
            }
        } catch (Throwable th) {
            throw new ConnectionPoolNotFoundException("The specified connection "
                    + "pool \""
                    + poolName
                    + "\" could not be found. The underlying "
                    + "error was a "
                    + th.getClass().getName()
                    + "The message was \""
                    + th.getMessage() + "\".");
        }

        return connectionPool;
    }
982927
public void connectionDidLeave(final RespokeConnection connection) {
        members.remove(connection);

        new Handler(Looper.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                Listener listener = listenerReference.get();
                if (null != listener) {
                    listener.onLeave(connection, RespokeGroup.this);
                }
            }
        });
    }
905675
ConnectionWrapper obtainConnection() {
		synchronized (allConnections) {
			//fails if connection pool not started
			if (!availableConnections.isEmpty()) {
				//retrieve and remove first connection from list
				//  since released connections are added to the back, connections will rotate
				ConnectionWrapper connWrap = (ConnectionWrapper) availableConnections.remove(0);
				usedConnections.add(connWrap);
				if (usedConnections.size() > maxNrOfConcurrentConnectionsCounted) {
					maxNrOfConcurrentConnectionsCounted = usedConnections.size();
				}
				return connWrap;
			} else {
				//create one if max not reached
				//this also restores lost connections
				if ((allConnections.size() < initialNrofConnections) || (allConnections.size() < maxNrofConnections)) {
					try {
						ConnectionWrapper connWrap = createConnectionWrapper(dbUrl, dbUsername, dbUserpassword);

						allConnections.add(connWrap);
						usedConnections.add(connWrap);

						System.out.println(new LogEntry("Creating new Connection, now " + allConnections.size() + " in use"));

						return connWrap;
					} catch (SQLException sqle) {
						//happens if db unreachable
						//connection will be lost for the time being
						nrofErrors++;
						System.out.println(new LogEntry("Cannot create new connection to " + dbUrl + " unreachable or useless connection settings", sqle));
						throw new ResourceException("Cannot create new connection to " + dbUrl + " unreachable or useless connection settings", sqle);
					}
				} else {
					System.out.println(new LogEntry("maximum nr of connections (" + maxNrofConnections + ") reached while Application demands another"));
				}
				return null;
			}
		}
	}
302163
def migrate(pool, from_connection, to_connection):
    
    f = connect_database(from_connection)
    t = connect_database(to_connection)

    if isinstance(f, ProjectDB):
        for each in f.get_all():
            each = unicode_obj(each)
            logging.info("projectdb: %s", each['name'])
            t.drop(each['name'])
            t.insert(each['name'], each)
    elif isinstance(f, TaskDB):
        pool = Pool(pool)
        pool.map(
            lambda x, f=from_connection, t=to_connection: taskdb_migrating(x, f, t),
            f.projects)
    elif isinstance(f, ResultDB):
        pool = Pool(pool)
        pool.map(
            lambda x, f=from_connection, t=to_connection: resultdb_migrating(x, f, t),
            f.projects)
1324997
public static synchronized void unknownCCMConnection(String poolName, Object mcp, Object cl,
                                                        Object connection, String key)
   {
      log.tracef("%s", new TraceEvent(poolName,
                                      Integer.toHexString(System.identityHashCode(mcp)),
                                      TraceEvent.UNKNOWN_CCM_CONNECTION,
                                      Integer.toHexString(System.identityHashCode(cl)),
                                      Integer.toHexString(System.identityHashCode(connection)),
                                      key));
   }
353280
public void addConnection (Connection connection) {
		if (connection == null) throw new IllegalArgumentException("connection cannot be null.");

		synchronized (connectionsLock) {
			Connection[] newConnections = new Connection[connections.length + 1];
			newConnections[0] = connection;
			System.arraycopy(connections, 0, newConnections, 1, connections.length);
			connections = newConnections;
		}

		connection.addListener(invokeListener);

		if (TRACE) trace("kryonet", "Added connection to ObjectSpace: " + connection);
	}
651105
def create_connector_c_pool(name, server=None, **kwargs):
    '''
    
    '''
    defaults = {
        'connectionDefinitionName': 'javax.jms.ConnectionFactory',
        'resourceAdapterName': 'jmsra',
        'associateWithThread': False,
        'connectionCreationRetryAttempts': 0,
        'connectionCreationRetryIntervalInSeconds': 0,
        'connectionLeakReclaim': False,
        'connectionLeakTimeoutInSeconds': 0,
        'description': '',
        'failAllConnections': False,
        'id': name,
        'idleTimeoutInSeconds': 300,
        'isConnectionValidationRequired': False,
        'lazyConnectionAssociation': False,
        'lazyConnectionEnlistment': False,
        'matchConnections': True,
        'maxConnectionUsageCount': 0,
        'maxPoolSize': 32,
        'maxWaitTimeInMillis': 60000,
        'ping': False,
        'poolResizeQuantity': 2,
        'pooling': True,
        'steadyPoolSize': 8,
        'target': 'server',
        'transactionSupport': '',
        'validateAtmostOncePeriodInSeconds': 0
    }

    # Data = defaults + merge kwargs + remove salt
    data = defaults
    data.update(kwargs)

    # Check TransactionSupport against acceptable values
    if data['transactionSupport'] and data['transactionSupport'] not in (
               'XATransaction',
               'LocalTransaction',
               'NoTransaction'
       ):
        raise CommandExecutionError('Invalid transaction support')

    return _create_element(name, 'resources/connector-connection-pool', data, server)
73441
public <T> T execute(final String query, Object connection) {
        try {
            org.apache.cassandra.thrift.Cassandra.Client conn =
                (org.apache.cassandra.thrift.Cassandra.Client) connection;
            conn.set_cql_version(CassandraConstants.CQL_VERSION_3_0);
            KunderaCoreUtils.printQuery(query, showQuery);
            return (T) conn.execute_cql3_query(ByteBuffer.wrap(query.getBytes(Constants.CHARSET_UTF8)),
                Compression.NONE, getConsistencyLevel());
        } catch (Exception e) {
            log.error("Error while executing query {}", query);
            throw new KunderaException(e);
        }
    }
393307
public static ConnectionException ToConnectionPoolException(Throwable e) {
        if (e instanceof ConnectionException) {
            return (ConnectionException) e;
        }
        LOGGER.debug(e.getMessage());
        if (e instanceof InvalidRequestException) {
            return new com.netflix.astyanax.connectionpool.exceptions.BadRequestException(e);
        }
        else if (e instanceof TProtocolException) {
            return new com.netflix.astyanax.connectionpool.exceptions.BadRequestException(e);
        }
        else if (e instanceof UnavailableException) {
            return new TokenRangeOfflineException(e);
        }
        else if (e instanceof SocketTimeoutException) {
            return new TimeoutException(e);
        }
        else if (e instanceof TimedOutException) {
            return new OperationTimeoutException(e);
        }
        else if (e instanceof NotFoundException) {
            return new com.netflix.astyanax.connectionpool.exceptions.NotFoundException(e);
        }
        else if (e instanceof TApplicationException) {
            return new ThriftStateException(e);
        }
        else if (e instanceof AuthenticationException || e instanceof AuthorizationException) {
            return new com.netflix.astyanax.connectionpool.exceptions.AuthenticationException(e);
        }
        else if (e instanceof SchemaDisagreementException) {
            return new com.netflix.astyanax.connectionpool.exceptions.SchemaDisagreementException(e);
        }
        else if (e instanceof TTransportException) {
            if (e.getCause() != null) {
                if (e.getCause() instanceof SocketTimeoutException) {
                    return new TimeoutException(e);
                }
                if (e.getCause().getMessage() != null) {
                    if (e.getCause().getMessage().toLowerCase().contains("connection abort")
                            || e.getCause().getMessage().toLowerCase().contains("connection reset")) {
                        return new ConnectionAbortedException(e);
                    }
                }
            }
            return new TransportException(e);
        }
        else {
            // e.getCause().printStackTrace();
            return new UnknownException(e);
        }
    }
316369
void connectionCloses(final Session connection) {
        synchronized (connections) {
            final ExecutorService executorService = connectionThreads.get(connection);
            if (executorService != null) {
                executorService.shutdownNow();
            }
            connectionThreads.remove(connection);
            connections.remove(connection);
        }
    }
525473
protected void closeConnection(ThriftConnectionHandle<T> connection) {
		if (connection != null) {
			try {
				connection.internalClose();
			} catch (Throwable t) {
				logger.error("Destroy connection exception", t);
			} finally {
				this.thriftConnectionPool.postDestroyConnection(connection);
			}
		}
	}
108569
public static <T> List<T> wrap(final T source) {
        val list = new ArrayList<T>();
        if (source != null) {
            if (source instanceof Collection) {
                val it = ((Collection) source).iterator();
                while (it.hasNext()) {
                    list.add((T) it.next());
                }
            } else if (source.getClass().isArray()) {
                if (source.getClass().isAssignableFrom(byte[].class)) {
                    list.add(source);
                } else {
                    val elements = Arrays.stream((Object[]) source).collect(Collectors.toList());
                    list.addAll((List) elements);
                }
            } else {
                list.add(source);
            }
        }
        return list;
    }
976480
void connectionCloses(final SynchronizeFXTomcatConnection connection) {
        LOG.info("Client connection closed.");
        synchronized (connections) {
            final ExecutorService executorService = connectionThreads.get(connection);
            if (executorService != null) {
                executorService.shutdown();
            }
            connectionThreads.remove(connection);
            connections.remove(connection);
        }
    }