private void processEvents()

in curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java [237:275]


    private void processEvents() {
        while (state.get() == State.STARTED) {
            try {
                long useSessionTimeoutMs = getUseSessionTimeoutMs();
                long elapsedMs = startOfSuspendedEpoch == 0
                        ? useSessionTimeoutMs / 2
                        : System.currentTimeMillis() - startOfSuspendedEpoch;
                long pollMaxMs = useSessionTimeoutMs - elapsedMs;

                final ConnectionState newState = eventQueue.poll(pollMaxMs, TimeUnit.MILLISECONDS);
                if (newState != null) {
                    if (listeners.isEmpty()) {
                        log.warn("There are no ConnectionStateListeners registered.");
                    }

                    listeners.forEach(listener -> listener.stateChanged(client, newState));
                } else if (sessionExpirationPercent > 0) {
                    synchronized (this) {
                        checkSessionExpiration();
                    }
                }

                synchronized (this) {
                    if ((currentConnectionState == ConnectionState.LOST)
                            && client.getZookeeperClient().isConnected()) {
                        // CURATOR-525 - there is a race whereby LOST is sometimes set after the connection has been
                        // repaired
                        // this "hack" fixes it by forcing the state to "RECONNECTED"
                        log.warn("ConnectionState is LOST but isConnected() is true. Forcing RECONNECTED.");
                        addStateChange(ConnectionState.RECONNECTED);
                    }
                }
            } catch (InterruptedException e) {
                // swallow the interrupt as it's only possible from either a background
                // operation and, thus, doesn't apply to this loop or the instance
                // is being closed in which case the while test will get it
            }
        }
    }