Terminate all the connections associated with the chain

@throws Exception
970105
private void terminateConnectionsAssociatedWithChain() throws Exception {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
            Tr.event(this, tc, "terminateConnectionsAssociatedWithChain");
        }

        ChannelFramework cfw = CommsClientServiceFacade.getChannelFramewrok();
        OutboundConnectionTracker oct = ClientConnectionManager.getRef().getOutboundConnectionTracker();
        if (oct != null) {
            oct.terminateConnectionsAssociatedWithChain(_chainName);
        } else {// if we dont have any oct that means there were no connections established

            if (cfw.getChain(_chainName) != null) {// see if chain exist only then destroy
                // we have to destroy using vcf because cfw does not allow to destroy outbound 
                // chains directly using cfw.destroyChain(chainname)
                // as it is valid only for inbound chains as of now
                cfw.getOutboundVCFactory(_chainName).destroy();
            }
        }
        ChainData cd = cfw.getChain(_chainName);
        if (cd != null) {
            cfw.removeChain(cd);
        }
        removeChannel(_tcpChannelName);
        if (_isSSLChain)
            removeChannel(_sslChannelName);
        removeChannel(_jfapChannelName);

    }
182105
private synchronized void destroyConnLinks() {

        // inUse queue is still open to modification
        // during this time. Returned iterator is a "weakly consistent"
        // I don't believe this has (yet) caused any issues.
        for (Queue<TCPConnLink> queue : this.inUse) {
            try {
                TCPConnLink tcl = queue.poll();
                while (tcl != null) {
                    tcl.close(tcl.getVirtualConnection(), null);
                    tcl = queue.poll();
                }
            } catch (Throwable t) {
                FFDCFilter.processException(t, getClass().getName(), "destroyConnLinks", new Object[] { this });
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Error closing connection: " + t + " " + queue);
                }
            }

        }
    }
1205798
def Terminate(self):
		
		
		self.lock.acquire()
		try:
			for bucket in self.connections.values():
				try:
					for conn in bucket:
						conn.lock()
						try:
							conn.Close()
						except Exception:
							#We may throw exceptions due to already closed connections
							pass
						conn.release()
				except Exception:
					pass
			self.connections = {}
		finally:
			self.lock.release()
358293
@Override
    public void stop() throws Exception {
        if (!this.started) {
            logger.warn(String.format("management=%s is already stopped", this.name));
            return;
        }

        // this.nettyClientOpsThread.setStarted(false);

        for (ManagementEventListener lstr : managementEventListeners) {
            try {
                lstr.onServiceStopped();
            } catch (Throwable ee) {
                logger.error("Exception while invoking onServiceStopped", ee);
            }
        }

        // We store the original state first
        this.store();

        // Stop all associations
        FastMap<String, Association> associationsTemp = this.associations;
        for (FastMap.Entry<String, Association> n = associationsTemp.head(), end = associationsTemp.tail(); (n = n.getNext()) != end;) {
            Association associationTemp = n.getValue();
            if (associationTemp.isStarted()) {
                ((NettyAssociationImpl) associationTemp).stop();
            }
        }

        FastList<Server> tempServers = servers;
        for (FastList.Node<Server> n = tempServers.head(), end = tempServers.tail(); (n = n.getNext()) != end;) {
            Server serverTemp = n.getValue();
            if (serverTemp.isStarted()) {
                try {
                    ((NettyServerImpl) serverTemp).stop();
                } catch (Exception e) {
                    logger.error(String.format("Exception while stopping the Server=%s", serverTemp.getName()), e);
                }
            }
        }

        // waiting till stopping associations
        for (int i1 = 0; i1 < 20; i1++) {
            boolean assConnected = false;
            for (FastMap.Entry<String, Association> n = this.associations.head(), end = this.associations.tail(); (n = n
                    .getNext()) != end;) {
                Association associationTemp = n.getValue();
                if (associationTemp.isConnected()) {
                    assConnected = true;
                    break;
                }
            }
            if (!assConnected)
                break;
            Thread.sleep(100);
        }

        // TODO - make a general shutdown and waiting for it instead of "waiting till stopping associations" 
        this.bossGroup.shutdownGracefully();
        this.workerGroup.shutdownGracefully();
        this.clientExecutor.shutdown();
       

        // TODO Should servers be also checked for shutdown?

        this.started = false;

    }
660482
@Override
  public void close() throws Exception {
    if (closed.compareAndSet(false, true)) {
      interrupted.set(true);
      thread.interrupt();
    }
  }
116582
public void stop() throws Exception {
		if (server != null) {
			server.setStopTimeout(100);
			server.stop();
			server = null;
		}
	}
526768
@Override
  public void stop() throws Exception {
    mStopped = true;
    if (mServerSocket != null) {
      try {
        mServerSocket.close();
      } catch (IOException e) {
        LOG.warn("Exception in closing server socket: {}", e);
      }
    }
    mThreadPool.shutdownNow();
    // Close all client sockets so that their serving threads can stop. We shut down the threadpool
    // before closing the sockets so that no new socket threads will be created after we try to
    // close them all.
    synchronized (mClientSockets) {
      for (Socket socket : mClientSockets) {
        try {
          socket.close();
        } catch (IOException e) {
          LOG.warn("Exception in closing client socket: {}", e);
        }
      }
    }
    boolean ret = mThreadPool.awaitTermination(THREAD_KEEP_ALIVE_TIME_MS, TimeUnit.MILLISECONDS);
    if (ret) {
      LOG.info("All worker threads have terminated.");
    } else {
      LOG.warn("Log server has timed out waiting for worker threads to terminate.");
    }
  }
4546
void stopAll() {

		try {
			this.dmClient.closeConnection();
			stop();

		} catch( Throwable t ) {
			this.logger.warning( "An error occurred while closing the connection of the DM client." );
			Utils.logException( this.logger, new RuntimeException( t ));
		}
	}
1008511
def close_connection(self, connection, force=False):
        """"""
        if force:
            try:
                connection.close()
            except self.operational_exceptions:
                self.config.logger.error('ConnectionFactory - failed closing')
            for name, conn in self.pool.iteritems():
                if conn is connection:
                    break
            del self.pool[name]
        else:
            pass
696367
public function close()
    {
        if (! (@ldap_unbind($this->connection))) {
            $code = @ldap_errno($this->connection);
            throw new ConnectionException(
                sprintf(
                    'Could not close the connection: Ldap Error Code=%s - %s',
                    $code,
                    ldap_err2str($code)
                )
            );
        }

        $this->connection = null;
    }
1129885
public void stop() throws Exception {

		if( this.nazgulAgentFactory != null ) {
			for( ComponentInstance nazgul : this.nazgulAgentFactory.getInstances())
				deleteIPojoInstance( nazgul );
		}

		if( this.standardAgentFactory != null ) {
			for( ComponentInstance agent : this.standardAgentFactory.getInstances())
				deleteIPojoInstance( agent );
		}
	}
1207789
public void stop() throws Exception {
        DruidIndices.getInstance().remove(String.valueOf(port));
        server.stop();
    }
381544
public function destroy()
    {
        foreach (self::$connectionList as $dbDriver) {
            if (self::$transaction) {
                $dbDriver->commitTransaction();
            }
        }
        self::$transaction = false;
        self::$connectionList = [];
    }
317227
def terminate(self):
        

        self.close()

        for conn in list(self._used):
            conn.close()
            self._terminated.add(conn)

        self._used.clear()
1159504
@Override
    public void destroy(Exception e) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "destroy, vc=" + getVCHash());
        }

        // Clean up the read and write interfaces as well as the SSL engine.
        this.connected = false;
        cleanup();
        getVirtualConnection().getStateMap().remove(LINKCONFIG);
        if (this.syncConnectFailure) {
            // sync connect failure needs cleanup below us but not above
            // us on the connlink chain
            super.destroy();
        } else {
            // otherwise use the destroy that goes up the chain
            super.destroy(e);
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "destroy");
        }
    }
780785
final public void close() {
		List<C> connsToClose;
		synchronized(poolLock) {
			// Prevent any new connections
			isClosed = true;
			// Find any connections that are available and open
			connsToClose = new ArrayList<>(availableConnections.size());
			for(PooledConnection<C> availableConnection : availableConnections) {
				synchronized(availableConnection) {
					C conn = availableConnection.connection;
					if(conn!=null) {
						availableConnection.connection = null;
						connsToClose.add(conn);
					}
				}
			}
			poolLock.notifyAll();
		}
		// Close all of the connections
		for(C conn : connsToClose) {
			try {
				close(conn);
			} catch(Exception err) {
				logger.log(Level.WARNING, null, err);
			}
		}
	}
907373
@Override
  public void close() throws IOException {
    try {
      try {
        if (this.failed && this.conn != null) {
          this.conn.rollback();
        }
      } finally {
        if (this.conn != null) {
          this.conn.close();
        }
      }
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }