Closes the session. If we are currently doing a receiveWithWait then
that will be interrupted and a response will be sent to the client.

@param requestNumber
550030
public void close(int requestNumber)
   {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "close", requestNumber);

      // Deregister any error callback created for this connection.
      if (asynchReader != null)
      {
              try
              {
                 mainConsumer.getConsumerSession().getConnection().removeConnectionListener(asynchReader);
              }
              catch (SIException e)
              {
            //No FFDC code needed
            //Only FFDC if we haven't received a meTerminated event.
            if(!((ConversationState)getConversation().getAttachment()).hasMETerminated())
            {
               FFDCFilter.processException(e, CLASS_NAME + ".close",
                     CommsConstants.CATSESSSYNCHCONSUMER_CLOSE_01, this);
            }

                 if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) SibTr.exception(this, tc, e);
              }

        if (asynchReader.isCurrentlyDoingReceiveWithWait()) asynchReader.sendNoMessageToClient();
      }
      super.close(requestNumber);

      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "close");
   }
914519
static void terminateClient( IMessagingClient client, String errorMessage, Logger logger ) {

		try {
			logger.fine( "The reconfigurable client is requesting its internal connection to be closed." );
			if( client != null )
				client.closeConnection();

		} catch( Exception e ) {
			logger.warning( errorMessage + " " + e.getMessage());
			Utils.logException( logger, e );

		} finally {
			// "unregisterService" was not merged with "closeConnection"
			// on purpose. What is specific to JMX is restricted to this class
			// and this bundle. Sub-classes may use "closeConnection" without
			// any side effect on the JMX part.
			if( client instanceof JmxWrapperForMessagingClient )
				((JmxWrapperForMessagingClient) client).unregisterService();
		}
	}
78747
@Override
	protected void onQueueBrowserEnumerationClose()
	{
	    try
        {
    		CloseBrowserEnumerationQuery query = new CloseBrowserEnumerationQuery();
    		query.setSessionId(session.getId());
    		query.setBrowserId(browser.getId());
    		query.setEnumId(id);
    		transportEndpoint.blockingRequest(query);
        }
	    catch (JMSException e)
        {
            ErrorTools.log(e, log);
        }
	}
1236510
@Override
    public void flush(int requestNumber) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "flush", "" + requestNumber);

        // Locate the browser session to use.
        BrowserSession browserSession = mainConsumer.getBrowserSession();
        SIBusMessage msg = null;

        // Browse the next message and send it to the client.
        try {
            msg = getNextMessage(browserSession, getConversation(), (short) requestNumber);
            if (msg != null)
                sendMessage(msg);

            // Send a response to the browse request.
            try {
                getConversation().send(poolManager.allocate(),
                                       JFapChannelConstants.SEG_FLUSH_SESS_R,
                                       requestNumber,
                                       Conversation.PRIORITY_LOWEST,
                                       true,
                                       ThrottlingPolicy.BLOCK_THREAD,
                                       null);
            } catch (SIException e) {
                FFDCFilter.processException(e, CLASS_NAME + ".flush",
                                            CommsConstants.CATBROWSECONSUMER_FLUSH_01,
                                            this);

                SibTr.error(tc, "COMMUNICATION_ERROR_SICO2012", e);

                // Nothing else we can do at this point as the comms exception suggests that the
                // conversation is dead, anyway.
            }

        } catch (OperationFailedException e) {
            // No FFDC code needed
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled())
                SibTr.exception(this, tc, e);
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "flush");
    }
162336
public void close(Handler<AsyncResult<Void>> completion) {
        if (context == null) {
            context = vertx.getOrCreateContext();
        }

        context.runOnContext(v -> {
            if (http != null) {
                http.close(event -> {
                    logger.info("The server '{}' has been stopped (bound port: {})", name, port);
                    completion.handle(Future.<Void>succeededFuture());
                });
            }
        });
    }
1030451
public void noteRequestCompletion(ServerStats stats, Object response, Throwable e, long responseTime, RetryHandler errorHandler) {
    	if (stats == null) {
    		return;
    	}
        try {
            recordStats(stats, responseTime);
            RetryHandler callErrorHandler = errorHandler == null ? getRetryHandler() : errorHandler;
            if (callErrorHandler != null && response != null) {
                stats.clearSuccessiveConnectionFailureCount();
            } else if (callErrorHandler != null && e != null) {
                if (callErrorHandler.isCircuitTrippingException(e)) {
                    stats.incrementSuccessiveConnectionFailureCount();                    
                    stats.addToFailureCount();
                } else {
                    stats.clearSuccessiveConnectionFailureCount();
                }
            }
        } catch (Exception ex) {
            logger.error("Error noting stats for client {}", clientName, ex);
        }            
    }
1172953
@SuppressWarnings("unused")
    private void close() {
        try {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Doing client selector close");
            }
            selector.close();
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Closed client selector");
            }
        } catch (IOException e) {
            LOGGER.warn("Ignoring exception during selector close", e);
        }
    }
226355
public CompletableFuture<CloseResponse> close(CloseRequest request) {
    ComposableFuture<CloseResponse> future = new ComposableFuture<>();
    threadContext.execute(() -> {
      PrimaryBackupSession session = sessions.get(request.session());
      if (session != null) {
        role.close(session).whenComplete((result, error) -> {
          if (error == null) {
            future.complete(CloseResponse.ok());
          } else {
            future.complete(CloseResponse.error());
          }
        });
      } else {
        future.complete(CloseResponse.error());
      }
    });
    return future;
  }
1040420
private static void close(CloseableHttpClient httpClient, CloseableHttpResponse response) {
        try {
            if (response != null) {
                response.close();
            }
            if (httpClient != null) {
                httpClient.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
93875
public CompletableFuture<CloseSessionResponse> closeSession(CloseSessionRequest request) {
    CompletableFuture<CloseSessionResponse> future = new CompletableFuture<>();
    if (context.isCurrentContext()) {
      sendRequest(request, protocol::closeSession, future);
    } else {
      context.execute(() -> sendRequest(request, protocol::closeSession, future));
    }
    return future;
  }
275736
private void destroyRequestQueue(Queue<AsyncResourceRequest<V>> requestQueue) {
        if(requestQueue != null) {
            AsyncResourceRequest<V> resourceRequest = requestQueue.poll();
            while(resourceRequest != null) {
                destroyRequest(resourceRequest);
                resourceRequest = requestQueue.poll();
            }
        }
    }
959808
@Override
    public void closeSession(Throwable e) throws SIConnectionLostException, SIResourceException, SIErrorException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "closeSession", e);

        if (e == null)
        {
            //try and build an appropriate exception
            if (_consumerKey.isClosedDueToDelete())
            {
                e = new SISessionDroppedException(
                                nls.getFormattedMessage(
                                                        "DESTINATION_DELETED_ERROR_CWSIP00221",
                                                        new Object[] {
                                                                      _consumerDispatcher.getDestination().getName(),
                                                                      _messageProcessor.getMessagingEngineName() },
                                                        null));
            }
            else if (_consumerKey.isClosedDueToReceiveExclusive())
            {
                e = new SISessionDroppedException(
                                nls.getFormattedMessage(
                                                        "DESTINATION_EXCLUSIVE_ERROR_CWSIP00222",
                                                        new Object[] {
                                                                      _consumerDispatcher.getDestination().getName(),
                                                                      _messageProcessor.getMessagingEngineName() },
                                                        null));
            }
        }

        //and close the session
        _consumerSession.close();

        if (e != null)
            notifyException(e);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "closeSession", e);
    }
582759
public void disconnect() throws IOException {
        if (currentSession != null && currentSession.isOpen()) {
            synchronized (currentSession) {
                this.currentSession.close(new CloseReason(
                        CloseReason.CloseCodes.NORMAL_CLOSURE,
                        RTMClient.class.getCanonicalName() + " did it"
                ));
            }
        }
    }
1099250
@Override
    public void close() {
        if (client != null) {
            try {
                client.close();
            } catch (final IOException e) {
                LOGGER.error("Unable to close HTTP client", e);
            }
        }
    }
1362956
@Override
  public void requestCloseRead()
  {
    _state = _state.toCloseRead();

    try {
      requestLoop();
    } catch (Exception e) {
      log.log(Level.WARNING, e.toString(), e);
    }
  }
1075963
@Override
    public void close() {
        if (!closed) {
            closed = true;
            try {
                response.getOutputStream().close();
                HttpServletRequest req = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
                if (req != null) {
                    req.getAsyncContext().complete();
                }
            } catch (Exception ex) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Failed to close response stream", ex);
                }
            } finally {
                ServerProviderFactory.releaseRequestState(message);
            }
            
            //TODO: remove from all broadcasters
        }

    }
907147
@JmxOperation
    public String stopAsyncOperation(int requestId) {
        try {
            stopOperation(requestId);
        } catch(VoldemortException e) {
            return e.getMessage();
        }

        return "Stopping operation " + requestId;
    }