Called by pika once the connection to RabbitMQ has
        been established. It passes the handle to the connection object in
        case we need it, but in this case, we'll just mark it unused.

        :type unused_connection: pika.SelectConnection
342277
def on_connection_open(self, unused_connection):
        
        self._logger.info('Connection opened')
        self.add_on_connection_close_callback()
        self.open_channel()
1009857
def connections(self, wait):
        
        while wait:
            try:
                params = pika.ConnectionParameters(host=self.rmq_host,
                                                   port=self.rmq_port)
                connection = pika.BlockingConnection(params)
                self.channel = connection.channel()
                self.channel.exchange_declare(exchange='topic_recs',
                                              exchange_type='topic')

                result = self.channel.queue_declare()
                self.queue_name = result.method.queue
                self.es_conn = Elasticsearch([{'host': self.es_host,
                                               'port': self.es_port}])
                wait = False
                print('connected to rabbitmq and elasticsearch...')
            except Exception as e:  # pragma: no cover
                print(str(e))
                print('waiting for connection to rabbitmq...' + str(e))
                time.sleep(2)
                wait = True
1348277
protected void postConnection(ConnectionHandle handle, long statsObtainTime){

		handle.renewConnection(); // mark it as being logically "open"

		// Give an application a chance to do something with it.
		if (handle.getConnectionHook() != null){
			handle.getConnectionHook().onCheckOut(handle);
		}

		if (this.pool.closeConnectionWatch){ // a debugging tool
			this.pool.watchConnection(handle);
		}

		if (this.pool.statisticsEnabled){
			this.pool.statistics.addCumulativeConnectionWaitTime(System.nanoTime()-statsObtainTime);
		}
	}
1095776
def connection_made(self, transport):
        

        # Save the underlying transport
        self._transport = transport

        # Call connection_made() on the client protocol, passing
        # ourself as the transport
        self._client.connection_made(self)
723169
def remove(self, connection):
        
        cid = id(connection)
        if cid not in self.connections:
            raise ConnectionNotFoundError(self.id, cid)
        self.connection_handle(connection).close()
        with self._lock:
            del self.connections[cid]
        LOGGER.debug('Pool %s removed connection %s', self.id, cid)
908192
private void removeIdleTimeoutConnection() {

    //descending iterator since first from queue are the first to be used
    Iterator<MariaDbPooledConnection> iterator = idleConnections.descendingIterator();

    MariaDbPooledConnection item;

    while (iterator.hasNext()) {
      item = iterator.next();

      long idleTime = System.nanoTime() - item.getLastUsed().get();
      boolean timedOut = idleTime > TimeUnit.SECONDS.toNanos(maxIdleTime);

      boolean shouldBeReleased = false;

      if (globalInfo != null) {

        // idle time is reaching server @@wait_timeout
        if (idleTime > TimeUnit.SECONDS.toNanos(globalInfo.getWaitTimeout() - 45)) {
          shouldBeReleased = true;
        }

        //  idle has reach option maxIdleTime value and pool has more connections than minPoolSiz
        if (timedOut && totalConnection.get() > options.minPoolSize) {
          shouldBeReleased = true;
        }

      } else if (timedOut) {
        shouldBeReleased = true;
      }

      if (shouldBeReleased && idleConnections.remove(item)) {

        totalConnection.decrementAndGet();
        silentCloseConnection(item);
        addConnectionRequest();
        if (logger.isDebugEnabled()) {
          logger.debug(
              "pool {} connection removed due to inactivity (total:{}, active:{}, pending:{})",
              poolTag, totalConnection.get(), getActiveConnections(), pendingRequestNumber.get());
        }

      }
    }

  }
1349028
def disconnectAll(self):
        '''
        
        '''
        if not self.connections:
            return defer.succeed(None)
        result = self._notifier.wait('idle')
        for connection in self.connections:
            connection.transport.loseConnection()
        return result
395676
function handleConnection(client) {
        // set ghostmode callbacks
        if (bs.options.get("ghostMode")) {
            addGhostMode(client);
        }

        client.emit("connection", bs.options.toJS()); //todo - trim the amount of options sent to clients

        emitter.emit("client:connected", {
            ua: client.handshake.headers["user-agent"]
        });
    }
637623
def on_connection_unblocked(self, method_frame):
        
        LOGGER.debug('Connection unblocked: %r', method_frame)
        self.state = self.STATE_READY
        if self.on_ready:
            self.on_ready(self)
487294
def connection_made(self, transport):
        
        self.transport = transport
        self.transport.write(self.method.message.encode())
        self.time_out_handle = self.loop.call_later(
            TIME_OUT_LIMIT, self.time_out)
1084812
def _clear(reason, idle_pool, using_pool, channel_pool, conn_id):
        
        with _lock():
            try:
                idle_pool.pop(conn_id)
                logger.info('a connection lost when not using')
            except KeyError:
                if using_pool.pop(conn_id, None):
                    logger.warn('connection lost when using, should be handled later')
                    return reason
            finally:
                channel_pool.pop(conn_id, None)
754632
def deregister(cls, name: str) -> None:
        
        if name not in cls.available:
            raise ConnectionPluginNotRegistered(
                f"Connection {name!r} is not registered"
            )
        cls.available.pop(name)
1138364
def _get_and_set_reconnection_handler(self, new_handler):
        
        with self._reconnection_lock:
            old = self._reconnection_handler
            self._reconnection_handler = new_handler
            return old
1220990
void replaceConnection(ConnectionWrapper connWrap) {
		synchronized (allConnections) {
			try {
				if (usedConnections.remove(connWrap)) {
					nrofReset++;

					//the object was indeed locked
					allConnections.remove(connWrap);
					//IMPORTANT does this result in an SQL error which breaks off the connection?
					connWrap.getConnection().close();
					System.out.println(new LogEntry(Level.CRITICAL, "Connection reset" + (connWrap.getLastStatement() != null ? " while executing '" + connWrap.getLastStatement() + '\'' : "")));
					//lets create a fresh successor
					ConnectionWrapper newConnWrap = createConnectionWrapper(dbUrl, dbUsername, dbUserpassword);
					availableConnections.add(newConnWrap);
					allConnections.add(newConnWrap);
				} else {
					nrofErrors++;
					System.out.println(new LogEntry(Level.CRITICAL, "error in connection pool: attempt to close a Connection that does not exist in pool"));
				}
			} catch (SQLException sqle) {
				//happens if db unreachable
				//connection will be lost for the time being
				nrofErrors++;
				System.out.println(new LogEntry(Level.CRITICAL, "can not create new connection to " + dbUrl + " unreachable or useless connection settings", sqle));
			}
			try {
				if (!connWrap.isClosed()) {
					connWrap.getConnection().close();
				}
			} catch (SQLException sqle) {
				nrofErrors++;
				System.out.println(new LogEntry(Level.CRITICAL, "", sqle));
			}
		}
	}
913731
def on_rabbitmq_conn_open(self, connection):
        
        global pending_rabbitmq_connection, rabbitmq_connection
        LOGGER.info('RabbitMQ has connected')
        rabbitmq_connection = connection
        rabbitmq_connection.add_on_close_callback(self.on_rabbitmq_close)
        rabbitmq_connection.channel(self.on_rabbitmq_channel_open)
        pending_rabbitmq_connection = None
591143
private void reclaimConnections() {

        if (tc.isEntryEnabled()) {
            Tr.entry(this, tc, "reclaimConnections");
        }
        if (totalConnectionCount.get() == 0) {
            /*
             * If there are no connection, we have nothing to reclaim
             */
            if (tc.isEntryEnabled()) {
                Tr.exit(this, tc, "reclaimConnections", "Total connection count is zero");
            }
            return;
        }

        // This is only used for debug information
        int totalNumberOfConnectionRemoved = 0;

        /*
         * Look through the free pools for expired Aged and UnusedTimeout values
         */
        for (int j = 0; j < maxFreePoolHashSize; ++j) {
            synchronized (freePool[j].freeConnectionLockObject) {
                boolean removemcw = false;
                int mcwlSize = freePool[j].mcWrapperList.size();
                for (int k = 0; k < mcwlSize; ++k) {
                    MCWrapper mcw = (MCWrapper) freePool[j].mcWrapperList.get(k);
                    if (!removemcw && agedTimeout != -1) {
                        if (mcw.hasAgedTimedOut(agedTimeoutMillis)) {
                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                Tr.debug(this, tc, "Aged timeout reclaim connection " + mcw);
                            }
                            removemcw = true;
                        }
                    }
                    if (!removemcw && unusedTimeout != -1) {
                        if (mcw.hasIdleTimedOut(unusedTimeout * 1000)
                            && (this.totalConnectionCount.get() > minConnections)) {
                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                Tr.debug(this, tc, "Unused timeout reclaim connection " + mcw);
                            }
                            removemcw = true;
                        }
                    }

                    if (removemcw) {
                        mcWrappersToDestroy.add(mcw);
                        this.totalConnectionCount.decrementAndGet();
                        removemcw = false;
                    }
                } // end of for k loop
                for (int k = 0; k < mcWrappersToDestroy.size(); ++k) {
                    freePool[j].removeMCWrapperFromList(
                                                        mcWrappersToDestroy.get(k),
                                                        mcWrapperDoesExistInFreePool,
                                                        synchronizedAllReady,
                                                        dontNotifyWaiter, // Notifies will be done after cleanupAndDestroyMCWrapper
                                                        // processing
                                                        dontDecrementTotalCounter);
                }

            } // end of synchronized
            if (localConnection_ != null && needToReclaimTLSConnections()) {
                boolean reapTLS = false;
                /*
                 * We can reap connections in the connection pool if we are not in thread sensitive code.
                 */
                updateToTLSPoolInProgress.set(true); // set to true for pausing pool.
                synchronized (updateToTLSPoolInProgressLockObject) {
                    try {
                        sleep(20);
                    } catch (InterruptedException e) {
                    }
                    if (activeTLSRequest.get() > 0) {
                        try {
                            sleep(100);
                        } catch (InterruptedException e) {
                        }
                        if (activeTLSRequest.get() > 0) {
                            // We can not purge tls
                            if (tc.isDebugEnabled()) {
                                Tr.debug(this, tc, "To many active requests to search tls, active request value is " + activeRequest.get());
                            }
                        } else {
                            reapTLS = true;
                        }
                    } else {
                        reapTLS = true;
                    }
                    if (reapTLS) {
                        if (tc.isDebugEnabled()) {
                            Tr.debug(this, tc, "Searching tls for a connections to reap.");
                        }

                        Iterator<Entry<MCWrapper, ArrayList<MCWrapper>>> it = tlsArrayLists.entrySet().iterator();
                        while (it.hasNext()) {
                            Entry<MCWrapper, ArrayList<MCWrapper>> e = it.next();
                            MCWrapper mcw = e.getKey();
                            if (mcw.getPoolState() == MCWrapper.ConnectionState_freeTLSPool) {
                                ArrayList<MCWrapper> mh = e.getValue();
                                if (agedTimeout != -1) {
                                    if (mcw.hasAgedTimedOut(agedTimeoutMillis)) {
                                        mh.remove(mcw);
                                        tlsArrayLists.remove(mcw);
                                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                            ((com.ibm.ejs.j2c.MCWrapper) mcw).setThreadID(((com.ibm.ejs.j2c.MCWrapper) mcw).getThreadID() + "-reclaim-removed");
                                            Tr.debug(this, tc, "removed mcWrapper from thread local " + mcw);
                                        }
                                        mcw.setPoolState(MCWrapper.ConnectionState_noPool);
                                        mcWrappersToDestroy.add(mcw);
                                        this.totalConnectionCount.decrementAndGet();
                                        continue;
                                    }
                                }
                                if (unusedTimeout != -1) {
                                    if (mcw.hasIdleTimedOut(unusedTimeout * 1000)
                                        && (this.totalConnectionCount.get() > minConnections)) {
                                        mh.remove(mcw);
                                        tlsArrayLists.remove(mcw);
                                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                            ((com.ibm.ejs.j2c.MCWrapper) mcw).setThreadID(((com.ibm.ejs.j2c.MCWrapper) mcw).getThreadID() + "-reclaim-removed");
                                            Tr.debug(this, tc, "removed mcWrapper from thread local " + mcw);
                                        }
                                        mcw.setPoolState(MCWrapper.ConnectionState_noPool);
                                        mcWrappersToDestroy.add(mcw);
                                        this.totalConnectionCount.decrementAndGet();
                                    }
                                }
                            }
                        }
                    }
                    updateToTLSPoolInProgress.set(false); // set to false for releasing pool.
                    updateToTLSPoolInProgressLockObject.notifyAll();
                }
            }

            MCWrapper mcw;
            int destroyListSize = mcWrappersToDestroy.size();
            totalNumberOfConnectionRemoved = totalNumberOfConnectionRemoved + destroyListSize;
            for (int k = destroyListSize; k > 0; --k) {
                mcw = mcWrappersToDestroy.remove(k - 1);
                mcw.setInSharedPool(false); // : This mcwrapper is not in shared pool.
                freePool[j].cleanupAndDestroyMCWrapper(mcw);
            }
            for (int k = 0; k < destroyListSize; ++k) { // free one connection at
                //  at a time.
                synchronized (waiterFreePoolLock) {

                    if (waiterCount > 0) {
                        // there are requests waiting, so notify one of them
                        waiterFreePoolLock.notify();
                    }
                } // end sync
            }
        } // end for (int j
        if (tc.isEntryEnabled()) {
            if (tc.isDebugEnabled()) {
                // This information should only be printed if tc.isEntryEnabled()
                // and tc.isDebugEnabled()
                if (totalNumberOfConnectionRemoved > 0) {
                    Tr.debug(
                             tc,
                             "Total number of connections removed are " + totalNumberOfConnectionRemoved);
                } else {
                    Tr.debug(this, tc, "No connection were removed");
                }
                Tr.debug(this, tc, "Current state of pool:");
                Tr.debug(this, tc, this.toString());
            }
            Tr.exit(this, tc, "reclaimConnections");
        }
    }
676802
def purge(self, connection):
        """"""
        self._checkpid()
        if connection.pid == self.pid:
            idx = connection._pattern_idx
            if connection in self._in_use_connections[idx]:
                self._in_use_connections[idx].remove(connection)
            else:
                self._available_connections[idx].remove(connection)
            connection.disconnect()