Close all the sessions. Once this method is invoked {@link #getReadSession()} and {@link
#getReadWriteSession()} will start throwing {@code IllegalStateException}. The returned future
blocks till all the sessions created in this pool have been closed.
426369
ListenableFuture<Void> closeAsync() {
    ListenableFuture<Void> retFuture = null;
    synchronized (lock) {
      if (closureFuture != null) {
        throw new IllegalStateException("Close has already been invoked");
      }
      // Fail all pending waiters.
      Waiter waiter = readWaiters.poll();
      while (waiter != null) {
        waiter.put(newSpannerException(ErrorCode.INTERNAL, "Client has been closed"));
        waiter = readWaiters.poll();
      }
      waiter = readWriteWaiters.poll();
      while (waiter != null) {
        waiter.put(newSpannerException(ErrorCode.INTERNAL, "Client has been closed"));
        waiter = readWriteWaiters.poll();
      }
      closureFuture = SettableFuture.create();
      retFuture = closureFuture;
      pendingClosure =
          totalSessions() + numSessionsBeingCreated + 1 /* For pool maintenance thread */;

      poolMaintainer.close();
      readSessions.clear();
      writePreparedSessions.clear();
      for (final PooledSession session : ImmutableList.copyOf(allSessions)) {
        if (session.leakedException != null) {
          logger.log(Level.WARNING, "Leaked session", session.leakedException);
        }
        if (session.state != SessionState.CLOSING) {
          closeSessionAsync(session);
        }
      }
    }
    retFuture.addListener(
        new Runnable() {
          @Override
          public void run() {
            executorFactory.release(executor);
          }
        },
        MoreExecutors.directExecutor());

    return retFuture;
  }
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);
    }
1277505
public void close() throws IOException {
        if ( session != null && session.isConnected() ) {
            session.disconnect();
        }
        session = null;

        // unnecessary, but seems right to undo what we did
        for ( Tunnel tunnel : tunnels ) {
            tunnel.setAssignedLocalPort( 0 );
        }
    }
236381
public final void close() {
        if (m_stream==null) {
            return;
        }
        try {
            m_stream.close();
        }
        catch (IOException e) {
        }
        if (m_nextException==null) {
            m_nextException=new IOException("Closed.");
        }
        m_stream=null;
        resetState();
    }
414119
private void closeRemainingSessions()
    {
        if (sessions == null)
            return;
        
        List<AbstractSession> sessionsToClose = new ArrayList<>(sessions.size());
        synchronized (sessions)
        {
            sessionsToClose.addAll(sessions.values());
        }
        for (int n = 0 ; n < sessionsToClose.size() ; n++)
        {
            Session session = sessionsToClose.get(n);
            log.debug("Auto-closing unclosed session : "+session);
            try
            {
                session.close();
            }
            catch (JMSException e)
            {
                ErrorTools.log(e, log);
            }
        }
    }
929674
public CompletableFuture<Void> closeSession(SessionId sessionId, boolean delete) {
    RaftSessionState state = sessions.get(sessionId.id());
    if (state == null) {
      return Futures.exceptionalFuture(new RaftException.UnknownSession("Unknown session: " + sessionId));
    }

    log.debug("Closing session {}", sessionId);
    CloseSessionRequest request = CloseSessionRequest.builder()
        .withSession(sessionId.id())
        .withDelete(delete)
        .build();

    CompletableFuture<Void> future = new CompletableFuture<>();
    connection.closeSession(request).whenComplete((response, error) -> {
      sessions.remove(sessionId.id());
      if (error == null) {
        if (response.status() == RaftResponse.Status.OK) {
          future.complete(null);
        } else {
          future.completeExceptionally(response.error().createException());
        }
      } else {
        future.completeExceptionally(error);
      }
    });
    return future;
  }
616968
@Override
   public void close()
   {
      if (isShutdown.getAndSet(true)) {
         return;
      }

      HikariPool p = pool;
      if (p != null) {
         try {
            LOGGER.info("{} - Shutdown initiated...", getPoolName());
            p.shutdown();
            LOGGER.info("{} - Shutdown completed.", getPoolName());
         }
         catch (InterruptedException e) {
            LOGGER.warn("{} - Interrupted during closing", getPoolName(), e);
            Thread.currentThread().interrupt();
         }
      }
   }
871949
public void close() throws SFException, SnowflakeSQLException
  {
    logger.debug(" public void close()");

    // stop heartbeat for this session
    stopHeartbeatForThisSession();

    if (isClosed)
    {
      return;
    }

    SessionUtil.LoginInput loginInput = new SessionUtil.LoginInput();
    loginInput.setServerUrl(
        (String) connectionPropertiesMap.get(SFSessionProperty.SERVER_URL))
        .setSessionToken(sessionToken)
        .setLoginTimeout(loginTimeout);

    SessionUtil.closeSession(loginInput);
    closeTelemetryClient();
    clientInfo.clear();
    isClosed = true;
  }
803923
@Override
    public synchronized void close() throws BackendException {
        if (!isOpen) return;
        this.isOpen = false;
        if (readExecutor!=null) readExecutor.shutdown();
        if (sendThread!=null) sendThread.close(CLOSE_DOWN_WAIT);
        if (readExecutor!=null) {
            try {
                readExecutor.awaitTermination(1,TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                log.error("Could not terminate reader thread pool for KCVSLog "+name+" due to interruption");
            }
            if (!readExecutor.isTerminated()) {
                readExecutor.shutdownNow();
                log.error("Reader thread pool for KCVSLog "+name+" did not shut down in time - could not clean up or set read markers");
            } else {
                for (MessagePuller puller : msgPullers) {
                    puller.close();
                }
            }
        }
        writeSetting(manager.senderId, MESSAGE_COUNTER_COLUMN, numMsgCounter.get());
        store.close();
        manager.closedLog(this);
    }
1330967
@Override
  public StateConnection onCloseRead()
  {
    ConnectionProtocol request = request();
    
    if (request != null) {
      request.onCloseRead();
    }
    
    _sequenceClose.set(_sequenceRead.get());
    
    if (_sequenceFlush.get() < _sequenceClose.get()) {
      _isClosePending.set(true);
      
      if (_sequenceFlush.get() < _sequenceClose.get()) {
        return StateConnection.CLOSE_READ_S;
      }
      else {
        _isClosePending.set(false);
        
        return StateConnection.CLOSE;
      }
    }
    else {
      return StateConnection.CLOSE;
    }
  }
341826
public static void close(Session session) {
		if (session != null && session.isConnected()) {
			session.disconnect();
		}
		JschSessionPool.INSTANCE.remove(session);
	}
198663
@Override
    public synchronized void close() {
        final int count = INSTANCE.usageCount.get() - 1;
        if (count <= 0) {
            INSTANCE.usageCount.set(0);
            if (searchingAnalyzer != null) {
                searchingAnalyzer.close();
                searchingAnalyzer = null;
            }
            if (indexReader != null) {
                try {
                    indexReader.close();
                } catch (IOException ex) {
                    LOGGER.trace("", ex);
                }
                indexReader = null;
            }
            queryParser = null;
            indexSearcher = null;
            if (index != null) {
                try {
                    index.close();
                } catch (IOException ex) {
                    LOGGER.trace("", ex);
                }
                index = null;
            }
        }
    }
1343594
private void releaseSessions() throws TTException {
        if (mSessions == null) {
            return;
        }

        // Closing all transactions.
        try {
            for (IFilelistenerWriteTrx trx : mTrx.values()) {
                trx.close();
            }
        } catch (IllegalStateException ise) {
            ise.printStackTrace();
        }

        // Closing all storages aswell.
        for (ISession s : mSessions.values()) {
            s.close();
        }
    }
941715
void shutdown() throws InterruptedException {
    List<NGSession> allSessions;
    synchronized (lock) {
      done = true;
      allSessions =
          Stream.concat(workingPool.stream(), idlePool.stream()).collect(Collectors.toList());
      idlePool.clear();
      workingPool.clear();
    }
    for (NGSession session : allSessions) {
      session.shutdown();
    }

    // wait for all sessions to complete by either returning from waiting state or finishing their
    // nails
    long start = System.nanoTime();
    for (NGSession session : allSessions) {
      long timeout =
          NGConstants.SESSION_TERMINATION_TIMEOUT_MILLIS
              - TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);
      if (timeout < 1) {
        // Give all threads a chance to finish or pick up already finished threads
        timeout = 1;
      }
      session.join(timeout);
      if (session.isAlive()) {
        throw new IllegalStateException(
            "NGSession has not completed in "
                + NGConstants.SESSION_TERMINATION_TIMEOUT_MILLIS
                + " ms");
      }
    }
  }
52241
@Override
    public synchronized void close() {

        if (isClosed) {
            return;
        }

        rollback(false);

        try {
            database.logger.writeToLog(this, Tokens.T_DISCONNECT);
        } catch (HsqlException e) {}

        sessionData.closeAllNavigators();
        sessionData.persistentStoreCollection.clearAllTables();
        sessionData.closeResultCache();
        database.compiledStatementManager.removeSession(sessionId);
        database.sessionManager.removeSession(this);
        database.closeIfLast();

        database                  = null;
        user                      = null;
        rowActionList             = null;
        sessionContext.savepoints = null;
        intConnection             = null;
        sessionContext            = null;
        lastIdentity              = null;
        isClosed                  = true;
    }
378112
public function close()
    {
        $id = session_id();
        // Make sure the session is unlocked and the expiration time is updated,
        // even if the write did not occur
        if ($this->openSessionId !== $id || !$this->sessionWritten) {
            $result = $this->connection->write($this->formatId($id), '', false);
            $this->sessionWritten = (bool) $result;
        }

        return $this->sessionWritten;
    }
133986
public synchronized void closeImmediatedly() {

        close();

        Iterator iterator = this.connectionsInUse.iterator();

        while (iterator.hasNext()) {
            PooledConnection connection = (PooledConnection) iterator.next();
            SessionConnectionWrapper sessionWrapper =
                (SessionConnectionWrapper) this.sessionConnectionWrappers.get(
                    connection);

            closeSessionWrapper(
                sessionWrapper,
                "Error closing session wrapper. Connection pool was shutdown immediatedly.");
        }
    }