Closes the given LedgerHandle.

@param handle The LedgerHandle to close.
@throws DurableDataLogException If an exception occurred. The causing exception is wrapped inside it.
335097
static void close(LedgerHandle handle) throws DurableDataLogException {
        try {
            Exceptions.handleInterrupted(handle::close);
        } catch (BKException bkEx) {
            throw new DurableDataLogException(String.format("Unable to close ledger %d.", handle.getId()), bkEx);
        }
    }
76814
@Override
	public void close() {
		AppEngineTransaction tx = transaction.get();
		
		if (tx != null) {
			tx.rollback();
		}
	}
142247
void closeHandle(HelloWorldConnection handle)
   {
      connections.remove((HelloWorldConnectionImpl)handle);

      ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
      event.setConnectionHandle(handle);

      for (ConnectionEventListener cel : listeners)
      {
         cel.connectionClosed(event);
      }
   }
1295589
private void closeConnection(Object connectionHandle)
   {
      try
      {
         Throwable exception = null;

         synchronized (connectionStackTraces)
         {
            exception = connectionStackTraces.remove(connectionHandle);
         }

         Method m = SecurityActions.getMethod(connectionHandle.getClass(), "close", new Class[]{});

         try
         {
            if (exception != null)
            {
               log.closingConnection(connectionHandle, exception);
            }
            else
            {
               log.closingConnection(connectionHandle);
            }

            m.invoke(connectionHandle, new Object[]{});
         }
         catch (Throwable t)
         {
            log.closingConnectionThrowable(t);
         }
      }
      catch (NoSuchMethodException nsme)
      {
         log.closingConnectionNoClose(connectionHandle.getClass().getName());
      }
   }
104386
public void close(final OperationResult<Void, Exception> onGraceFullClose) {

        this.onGraceFullClose = onGraceFullClose;
        this.sendLink.close();
        this.receiveLink.close();
    }
417470
public void initialize() throws DurableDataLogException {
        this.cacheManager.startAsync().awaitRunning();
        getSingleton(this.dataLogFactory, this.dataLogFactoryCreator).initialize();
        getSingleton(this.containerManager, this.segmentContainerManagerCreator).initialize();
    }
733831
@Override
	public final void unlock(int handle) throws DataStoreException 
    {
        if (SAFE_MODE) checkHandle(handle);
        if (locks.flip(handle))
        {
            locks.flip(handle); // Restore state
            throw new DataStoreException("Handle was not locked : "+handle);
        }
    }
848305
private void doClose() {
    super.close(); // We must call this or handlers don't get unregistered and we get a leak
    if (heartbeatID != -1) {
      vertx.cancelTimer(heartbeatID);
    }
    if (timeoutTimerID != -1) {
      vertx.cancelTimer(timeoutTimerID);
    }
    if (id != null) {
      // Can be null if websocket session
      sessions.remove(id);
    }

    if (!closed) {
      closed = true;
      if (endHandler != null) {
        endHandler.handle(null);
      }
    }
  }
554301
@Override
    public void close(IAsyncResultHandler<Void> result) {
        vertx.executeBlocking(blocking -> {
            super.close(result);
        }, res -> {
            if (res.failed())
                result.handle(AsyncResultImpl.create(res.cause()));
        });
    }
770510
public boolean unregisterChaincodeEventListener(String handle) throws InvalidArgumentException {
        boolean ret;

        if (shutdown) {
            throw new InvalidArgumentException(format("Channel %s has been shutdown.", name));
        }

        checkHandle(CHAINCODE_EVENTS_TAG, handle);

        synchronized (chainCodeListeners) {
            ret = null != chainCodeListeners.remove(handle);

        }

        synchronized (this) {
            if (null != blh && chainCodeListeners.isEmpty()) {

                unregisterBlockListener(blh);
                blh = null;
            }
        }

        return ret;

    }
650681
@Override
    public void close() throws Exception {         

        if(webConnection_closeComplete){
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "WebConnection close previously completed ...return ");
            }
            return;
        }
        else{
            // this is for the case to avoid infinite loop if handler destroy end up calling webconnection close.  
            if(upgradeHandler_DestroyStarted){
                return;
            }
            synchronized(this) {
                //check it again 
                if(webConnection_closeComplete || webConnection_closeOngoing){
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "WebConnection close previously completed .....return ");
                    }
                    return;
                }
                webConnection_closeOngoing = true;


                //      Call UpgradeHandler destroy() API.      
                //upgradeHandler_DestroyComplete  is needed if close is called again from complete , we do not call destroy again
                if (!upgradeHandler_DestroyComplete && _upgradeHandler != null) { 
                    /// call application handler class destroy

                    try{ 
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                            Tr.debug(tc, "call Handler destroy "+ this._upgradeHandler);                      
                        } 
                        upgradeHandler_DestroyStarted= true;
                        _upgradeHandler.destroy();
                    }
                    finally{
                        upgradeHandler_DestroyComplete = true;
                        upgradeHandler_DestroyStarted= false;
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                            Tr.debug(tc, "Handler destroy successful"+ this._upgradeHandler);                      
                        }
                    }
                }          

                if(_in != null && (_in.getInputBufferHelper().get_tcpChannelCallback() != null)){
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, " input callback");
                    }
                    inputCallback = true;
                }

                //close the streams , make sure even if one fails we close rest. 
                try{
                    if(_in!= null)
                        _in.close();
                }catch(IOException ioe){
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, " closing of inputStream failed ..");
                    }
                    closeUpgradeException = ioe;
                }

                // now close output
                // close connection
                closeOutputandConnection();
            }
        }
    }
442469
public void deleteToken(String token, DeleteTokenHandler handler) {
        HMSAgentLog.i("deleteToken:token:" + StrUtils.objDesc(token) + " handler=" + StrUtils.objDesc(handler));
        this.token = token;
        this.handler = handler;
        connect();
    }
1298694
@Override
	public int delete(int handle) throws DataStoreException
    {
        if (SAFE_MODE) checkHandle(handle);
        
        int previousHandle = previousEntry[handle];
        int nextHandle = nextEntry[handle];
        
        // Reconnect list
        if (previousHandle != -1)
            nextEntry[previousHandle] = nextHandle;
        if (nextHandle != -1)
            previousEntry[nextHandle] = previousHandle;
 
        // Clear data
        previousEntry[handle] = -1;
        nextEntry[handle] = -1;
        data[handle] = null;
        locks.clear(handle);
        
        if (firstEntry == handle)
            firstEntry = nextHandle;
        
        size--;
        
        return previousHandle;
    }
878583
@Override
  public void close() throws IOException {
    try {
      if (consumer != null && consumer instanceof Closeable) {
        // Call close in a new transaction.
        // TODO (terence): Actually need to coordinates with other flowlets to drain the queue.
        TransactionContext txContext = dataFabricFacade.createTransactionManager();
        txContext.start();
        try {
          ((Closeable) consumer).close();
          txContext.finish();
        } catch (TransactionFailureException e) {
          LOG.warn("Fail to commit transaction when closing consumer.");
          txContext.abort();
        }
      }
    } catch (Exception e) {
      LOG.warn("Fail to close queue consumer.", e);
    }
    consumer = null;
  }
81103
public Wrapper remove(SipActivityHandle handle) {
		final Wrapper activity = handle.getActivity();
		handle.setActivity(null);
		return activity;
	}
1164356
@Override
  public void close(ChannelHandlerContext ctx, ChannelPromise future) throws Exception {
    Status status = Status.UNAVAILABLE.withDescription(
        "Connection closing while performing protocol negotiation for " + ctx.pipeline().names());
    failWrites(status.asRuntimeException());
    super.close(ctx, future);
  }
1260829
protected void closeSurrogate() throws Throwable {

        if (this.surrogateClosed) {
            return;
        }

        if (this.resultSets != null) {
            Iterator it = this.resultSets.iterator();

            // Changed to set of ResultSet invocation handlers so
            // that handler resources can be cleaned up too.
            while (it.hasNext()) {
                WrapperInvocationHandler handler =
                    (WrapperInvocationHandler) it.next();

                try {
                    ((ResultSet) handler.delegate).close();
                } catch (Exception ex) {}

                try {
                    handler.closeSurrogate();
                } catch (Exception e) {}
            }
        }

        if (this.statements != null) {
            Iterator it = this.statements.iterator();

            while (it.hasNext()) {
                WrapperInvocationHandler handler =
                    (WrapperInvocationHandler) it.next();

                try {
                    handler.closeSurrogate();
                } catch (Exception e) {}
            }
        }

        if (this.dbmdHandler != null) {
            try {
                this.dbmdHandler.closeSurrogate();
            } catch (Throwable ex) {}
        }

        Object delegate = this.delegate;

        try {
            if (delegate instanceof Connection) {
                closeConnectionSurrogate();
            } else if (delegate instanceof Statement) {
                closeStatementSurrogate();
            }
        } finally {
            this.delegate        = null;
            this.surrogate       = null;
            this.dbmdHandler     = null;
            this.parentHandler   = null;
            this.statementKey    = null;
            this.statementPool   = null;
            this.connectionPool  = null;
            this.surrogateClosed = true;
        }
    }