public void close()

in curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java [351:401]


    public void close() {
        log.debug("Closing");
        if (closeWithLock()) {
            listeners.forEach(listener -> {
                CuratorEvent event = new CuratorEventImpl(
                        CuratorFrameworkImpl.this,
                        CuratorEventType.CLOSING,
                        0,
                        null,
                        null,
                        null,
                        null,
                        null,
                        null,
                        null,
                        null,
                        null);
                try {
                    listener.eventReceived(CuratorFrameworkImpl.this, event);
                } catch (Exception e) {
                    ThreadUtils.checkInterrupted(e);
                    log.error("Exception while sending Closing event", e);
                }
            });

            if (executorService != null) {
                executorService.shutdownNow();
                try {
                    executorService.awaitTermination(maxCloseWaitMs, TimeUnit.MILLISECONDS);
                } catch (InterruptedException e) {
                    // Interrupted while interrupting; I give up.
                    Thread.currentThread().interrupt();
                }
            }

            if (ensembleTracker != null) {
                ensembleTracker.close();
            }
            // Operations are forbidden to queue after closing, but there are still other concurrent mutations,
            // say, un-sleeping and not fully terminated background thread. So we have to drain the queue atomically
            // to avoid duplicated close. But DelayQueue counts Delayed::getDelay, so we have to clear it up front.
            backgroundOperations.forEach(OperationAndData::clearSleep);
            Collection<OperationAndData<?>> droppedOperations = new ArrayList<>(backgroundOperations.size());
            backgroundOperations.drainTo(droppedOperations);
            droppedOperations.forEach(this::closeOperation);
            listeners.clear();
            unhandledErrorListeners.clear();
            connectionStateManager.close();
            client.close();
        }
    }