/*
@see
com.ibm.wsspi.channelfw.base.OutboundProtocolLink#close(com.ibm.wsspi.channelfw
.VirtualConnection, java.lang.Exception)
17748
public void close(VirtualConnection inVC, Exception e) {

        // when the channel above calls close() on the outbound connection then
        // we are done... no need to purge anything off the socket like we do
        // on the inbound side (purge request body if they never read it)

        // pass the close down the chain.
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Closing this outbound link: " + this + " " + getVirtualConnection());
        }
        setAllowReconnect(false);
        if (!this.earlyReconnectDestroy) {
            super.close(inVC, e);
        } else {
            destroy(e);
        }
    }
1050643
@Override
    public void close() throws JMSRuntimeException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "close");
        try {
            messageConsumer.close();
        } catch (JMSException jmse) {
            JmsErrorUtils.getJMS2Exception(jmse, JMSRuntimeException.class);
        } finally {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.entry(this, tc, "close");
        }

    }
537040
@Override
  public void close() throws IOException {
    if (!channelIsOpen) {
      logger.atFine().log("Ignoring close: channel for '%s' is not open.", resourceIdString);
      return;
    }
    logger.atFine().log("Closing channel for '%s'", resourceIdString);
    channelIsOpen = false;
    closeContentChannel();
  }
1239524
@Override
  public void close() throws IOException {
    checkState(isInitialized, "initialize() must be invoked before use.");
    if (isOpen()) {
      try {
        pipeSinkChannel.close();
        handleResponse(waitForCompletionAndThrowIfUploadFailed());
      } finally {
        pipeSinkChannel = null;
        uploadOperation = null;
      }
    }
  }
77735
@Override
  public void close() throws IOException {
    try {
      mLock.lock();
      if (mAvailableResources.size() != mResources.size()) {
        LOG.warn("{} resources are not released when closing the resource pool.",
            mResources.size() - mAvailableResources.size());
      }
      for (ResourceInternal<T> resourceInternal : mAvailableResources) {
        closeResource(resourceInternal.mResource);
      }
      mAvailableResources.clear();
    } finally {
      mLock.unlock();
    }
    mGcFuture.cancel(true);
  }
731055
public void closeConnection(RpcClient rpcClient, ClientTransportConfig transportConfig, Url url) {
        if (rpcClient == null || transportConfig == null || url == null) {
            return;
        }
        //TODO do not close
    }
944452
@Override
    public boolean close () throws CIFSException {
        boolean inUse = false;
        
        List<SmbTransportImpl> toClose;
        synchronized ( this.connections ) {
            log.debug("Closing pool");
            toClose = new LinkedList<>(this.connections);
            toClose.addAll(this.nonPooledConnections);
            this.connections.clear();
            this.nonPooledConnections.clear();
        }
        for ( SmbTransportImpl conn : toClose ) {
            try {
                inUse |= conn.disconnect(false, false);
            }
            catch ( IOException e ) {
                log.warn("Failed to close connection", e);
            }
        }
        return inUse;
    }
1101050
@Override
    public void close() throws SQLException
    {
        try
        {
            isClosed = true;
            JDBC4ClientConnectionPool.dispose(NativeConnection);
        }
        catch(Exception x)
        {
            throw SQLError.get(x);
        }
    }
711026
public void closeConnection()
    {
        if (tc.isEntryEnabled()) Tr.entry(tc, "closeConnection");
        try
        {
            if(_XAResourceFactory != null && _XARes != null)
            {
                ((XAResourceFactory)_XAResourceFactory).destroyXAResource(_XARes);
            }
        }
        catch(Throwable t)
        {
            FFDCFilter.processException(t, "com.ibm.ws.Transaction.JTA.XARminst.closeConnection", "250", this);
            Tr.audit(tc, "WTRN0038_ERR_DESTROYING_XARESOURCE", t);
        }
        if (tc.isEntryEnabled()) Tr.exit(tc, "closeConnection");
    }
387062
@Override
    public void close(VirtualConnection inVC, Exception e) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "close(vc, e) called H2InboundLink: " + this + " " + inVC);
        }

        //At this point our side should be in the close state, as we have sent out our data
        //Should probably check if the connection is closed, if so issue the destroy up the chain
        //Then call the close on the underlying muxLink so we can close the connection if everything has been closed
        //Additionally, don't close the underlying link if this is a push stream
        if (streamID == 0 || streamID % 2 == 1) {
            // if this isn't an http/2 exception, don't pass it down, since that will cause a GOAWAY to be sent immediately
            if (e == null || e instanceof Http2Exception) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "close: closing with exception: " + e);
                }
                if (httpInboundServiceContextImpl != null) {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "close: (1)httpInboundServiceContextImpl.clear()");
                    }
                    httpInboundServiceContextImpl.clear();
                    httpInboundServiceContextImpl = null;
                }
                this.muxLink.close(inVC, e);
            } else {
                H2StreamProcessor h2sp = muxLink.getStreamProcessor(streamID);
                if (h2sp != null && !h2sp.isStreamClosed()) {
                    try {
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                            Tr.debug(tc, "close: attempting to reset stream: " + streamID);
                        }
                        int PROTOCOL_ERROR = 0x1;
                        Frame reset = new FrameRstStream(streamID, PROTOCOL_ERROR, false);
                        h2sp.processNextFrame(reset, Constants.Direction.WRITING_OUT);
                    } catch (Http2Exception h2e) {
                        // if we can't write out RST frame, throw the original exception
                        if (httpInboundServiceContextImpl != null) {
                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                Tr.debug(tc, "close: (2)httpInboundServiceContextImpl.clear()");
                            }
                            httpInboundServiceContextImpl.clear();
                            httpInboundServiceContextImpl = null;
                        }
                        this.muxLink.close(inVC, e);
                    }
                }
                if (httpInboundServiceContextImpl != null) {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "close: (3)httpInboundServiceContextImpl.clear()");
                    }
                    httpInboundServiceContextImpl.clear();
                    httpInboundServiceContextImpl = null;
                }
                this.muxLink.close(inVC, null);
            }
        } else { // try to send an RST_STREAM to let the client know the push promise has been canceled
            H2StreamProcessor h2sp = muxLink.getStreamProcessor(streamID);
            if (h2sp != null && !h2sp.isStreamClosed() && !h2sp.isHalfClosed()) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "close: attempting to reset stream: " + streamID);
                }
                int PROTOCOL_ERROR = 0x1;
                Frame reset = new FrameRstStream(streamID, PROTOCOL_ERROR, false);
                try {
                    h2sp.processNextFrame(reset, Constants.Direction.WRITING_OUT);
                } catch (Http2Exception h2e) {
                    // don't close
                }
            }
        }
    }
877881
@Override
  public void close() throws IOException
  {
    SocketChannel s = _s;
    _s = null;
    
    if (s != null) {
      s.close();
    }

    /*
    OutputStream os = _os;
    _os = null;

    InputStream is = _is;
    _is = null;

    try {
      if (os != null)
        os.close();
      
      if (is != null)
        is.close();
    } finally {
      if (s != null)
        s.close();
    }
  */
  }
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);
			}
		}
	}
319955
@Override
	public void close() throws Exception {
		try {
			if (outputStream != null) {
				outputStream.flush();
				outputStream.close();
			}

			// first regular attempt to cleanly close. Failing that will escalate
			if (client != null) {
				client.close();
			}
		}
		catch (Exception e) {
			throw new IOException("Error while closing connection that streams data back to client at "
					+ hostIp.toString() + ":" + port, e);
		}
		finally {
			// if we failed prior to closing the client, close it
			if (client != null) {
				try {
					client.close();
				}
				catch (Throwable t) {
					// best effort to close, we do not care about an exception here any more
				}
			}
		}
	}
281310
public void close()
    throws IOException
  {
    ServerSocketChannel ss = _ss;
    _ss = ss;

    if (ss != null) {
      try {
        ss.close();
      } catch (Exception e) {
      }
    }
  }
1003411
@Override
    public void close() {
        namedParamSqlCache.clear();
        namedParamIndexPropCache.clear();
        clearStatementCache();
        if (useConnection != null) {
            try {
                useConnection.close();
            } catch (SQLException e) {
                LOG.finest("Caught exception closing connection: " + e.getMessage());
            }
        }
    }
247864
@Override
    public void close(VirtualConnection inVC, Exception e) {
        final boolean bTrace = TraceComponent.isAnyTracingEnabled();
        if (bTrace && tc.isDebugEnabled()) {
            Tr.debug(tc, "close() called: " + this + " " + inVC);
        }

        boolean errorState = (null != e);
        if (errorState && bTrace && tc.isDebugEnabled()) {
            Tr.debug(tc, "close() in error state, " + e);
        }

        final HttpInboundServiceContextImpl sc = getHTTPContext();
        final HttpChannelConfig config = sc.getHttpConfig();
        // valid responses as well as error responses all go through here so
        // this is where we tell the factory that any large response is complete
        if (sc.containsLargeMessage()) {
            getChannel().getFactory().releaseLargeMessage();
        }

        // check to see if the message has been fully sent (unless we
        // are in an error state)

        if (!errorState && !sc.isMessageSent()) {
            try {
                VirtualConnection rc = sc.finishResponseMessage(null, this, false);
                // if the finish is done already, then continue with code below
                if (null == rc) {
                    if (bTrace && tc.isDebugEnabled()) {
                        Tr.debug(tc, "finishing response msg async");
                    }
                    return;
                }
            } catch (MessageSentException mse) {
                // no FFDC required, nothing to do here
                if (bTrace && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Error: message sent exception when flag doesn't agree");
                }
                // shouldn't get here so just close the socket
                getDeviceLink().close(inVC, mse);
                return;
            }
        }

        // if the incoming request body was never read, we must purge the body
        // off the socket before we can continue with the read for the next
        // request... assuming we're not in an error condition

        if (!errorState
            // 346196.2 -- if we stopped, then don't purge the body
            && getChannel().isRunning() && !sc.isIncomingMessageFullyRead()) {
            if (bTrace && tc.isDebugEnabled()) {
                Tr.debug(tc, "Incoming request body never read.");
            }
            try {
                // 346196.4 - read/release one buffer at a time to avoid
                // unnecessary memory storage for large bodies
                VirtualConnection rc = sc.getRequestBodyBuffer(HttpIgnoreBodyCallback.getRef(), false);
                boolean reachedEnd = false;
                while (null != rc) {
                    WsByteBuffer buffer = sc.getRequestBodyBuffer();
                    if (null != buffer) {
                        buffer.release();
                        rc = sc.getRequestBodyBuffer(HttpIgnoreBodyCallback.getRef(), false);
                    } else {
                        // end of body found
                        reachedEnd = true;
                        break;
                    }
                }
                if (!reachedEnd) {
                    // wait for callback
                    if (bTrace && tc.isDebugEnabled()) {
                        Tr.debug(tc, "close() waiting for body purge callback");
                    }
                    return;
                }
            } catch (Exception purgeException) {
                // no FFDC required
                if (bTrace && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Exception purging request body: " + purgeException);
                }
                errorState = true;
            }
        }

        if (this.myInterface.getLink() instanceof H2HttpInboundLinkWrap) {
            if (bTrace && tc.isDebugEnabled()) {
                Tr.debug(tc, "we're H2, calling that close");
            }
            this.myInterface.getLink().close(inVC, e);

            return;
        }

        // If servlet upgrade processing is being used, then don't close the socket here
        if (inVC != null) {
            String upgraded = (String) (inVC.getStateMap().get(TransportConstants.UPGRADED_CONNECTION));
            if (upgraded != null) {
                if (!errorState && getChannel().isRunning() && (upgraded.compareToIgnoreCase("true") == 0)) {

                    if (bTrace && tc.isDebugEnabled()) {
                        Tr.debug(tc, "Connection Not closed because Servlet Upgrade detected.");
                    }
                    return;
                }
            }
        }

        // now check to see if the connection should be kept open (unless
        // we are in an error state). Perform one last check against a channel
        // stop, close the socket if not running.

        if (!errorState && sc.isPersistent() && getChannel().isRunning()) {

            if (config.getDebugLog().isEnabled(DebugLog.Level.DEBUG)) {
                config.getDebugLog().log(DebugLog.Level.DEBUG, HttpMessages.MSG_READ_PERSISTENT, sc);
            }

            sc.resetStartTime();
            this.myTSC.getWriteInterface().setBuffers(null);

            // check the last buffer from the previous request as
            // there might be the start of another request on it (pipelining)

            if (sc.isReadDataAvailable()) {
                handlePipeLining();
                return;
            }
            // no pipelined data, clear the SC and setup for a JIT read
            if (bTrace && tc.isDebugEnabled()) {
                Tr.debug(tc, "Reading for another request...");
            }
            if (getChannel().getHttpConfig().runningOnZOS()) {
                // 342859 - add a marker indicating the first read of a subsequent
                // request is starting. This is used for WLM type management on z/OS
                // right now with request message priority handling and monitoring
                // of "in-system" times
                getVirtualConnection().getStateMap().put(HttpConstants.HTTPFirstRead, "true");
            }

            sc.clear();
            sc.setReadBuffer(null);
            sc.setupJITRead(config.getIncomingHdrBufferSize());

            // do a forced async read to free up the thread since there will
            // no doubt be a delay until the next request -- we've already
            // checked for pipelined ones
            this.myTSC.getReadInterface().read(1, HttpICLReadCallback.getRef(), true, config.getPersistTimeout());

        } else {
            if (bTrace && tc.isDebugEnabled()) {
                Tr.debug(tc, "Closing connection");
            }

            //PI11176 Begin
            if (getChannel().getHttpConfig().shouldAttemptPurgeData()) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "attemptPurgeData true, purging the data before closing the connection");
                }
                try {
                    //Setup for a JIT read. This will allocate a buffer for X bytes if a buffer hasn't already been allocated
                    //If there is nothing to read the buffer is automatically released
                    sc.setupJITRead(10);
                    //Set the buffer to null at the TCP layer before continuing. We will be doing this after anyway, so want to do it ahead of time so we are starting with out buffer.
                    this.myTSC.getReadInterface().setBuffer(null);
                    boolean processing = true;

                    while (processing) {
                        //Do the read
                        long numBytesRead = this.myTSC.getReadInterface().read(0, 1);
                        //Get the buffer associated with the read, could return null
                        WsByteBuffer indivBuffer = this.myTSC.getReadInterface().getBuffer();
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                            Tr.debug(tc, "Bytes read : " + numBytesRead);
                        }
                        //Check if the bytesRead are 0. If so then we are done. If not then we have to process the data(which in this case means throw it out
                        if (numBytesRead <= 0) {
                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                Tr.debug(tc, "No data read");
                            }
                            if (indivBuffer != null) {
                                //Means we read more than once to set the buffer to null and release it
                                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                    Tr.debug(tc, "No data read, releasing any buffer that was allocated");
                                }
                                this.myTSC.getReadInterface().setBuffer(null);
                                indivBuffer.release();
                            }
                            processing = false;
                        } else {
                            if (indivBuffer != null) {
                                //Clear the buffer because we read some data
                                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                    Tr.debug(tc, "Found a buffer after the read : " + indivBuffer);
                                }
                                indivBuffer.clear();
                                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                    Tr.debug(tc, "Cleared the buffer, going back to read again, " + indivBuffer);
                                }
                            } else {
                                //We are done since there was no buffer
                                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                    Tr.debug(tc, "No buffer found, assuming we are done");
                                }
                                processing = false;
                            }

                        }
                    }
                } catch (IOException purgeException) {
                    //Encountered an exception, if there is a buffer, just release and null out
                    WsByteBuffer indivBuffer = this.myTSC.getReadInterface().getBuffer();
                    if (indivBuffer != null) {
                        this.myTSC.getReadInterface().setBuffer(null);
                        indivBuffer.release();
                    }
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "IOException during purge : " + purgeException);
                    }
                }
            }
            //PI11176 End

            if (config.getDebugLog().isEnabled(DebugLog.Level.INFO)) {
                config.getDebugLog().log(DebugLog.Level.INFO, HttpMessages.MSG_CONN_CLOSING, sc);
            }

            if (this.myTSC != null) {
                TCPWriteRequestContext writeInterface = this.myTSC.getWriteInterface();
                if (writeInterface != null)
                    writeInterface.setBuffer(null);
                TCPReadRequestContext readInterface = this.myTSC.getReadInterface();
                if (readInterface != null)
                    readInterface.setBuffer(null);
            }
            if (this.filterExceptions) {
                getDeviceLink().close(inVC, null);
            } else {
                getDeviceLink().close(inVC, e);
            }
        }
    }
523909
public void close(ErrorCode rstStatusCode, @Nullable IOException errorException)
      throws IOException {
    if (!closeInternal(rstStatusCode, errorException)) {
      return; // Already closed.
    }
    connection.writeSynReset(id, rstStatusCode);
  }