private void syncLocalStateWithRemote()

in protonj2/src/main/java/org/apache/qpid/protonj2/engine/impl/ProtonConnection.java [633:668]


    private void syncLocalStateWithRemote() {
        if (engine.isWritable()) {
            // When the engine state changes or we have read an incoming AMQP header etc we need to check
            // if we have pending work to send and do so
            if (headerSent) {
                final ConnectionState state = getState();

                // Once an incoming header arrives we can emit our open if locally opened and also send close if
                // that is what our state is already.
                if (state != ConnectionState.IDLE && remoteHeader != null) {
                    boolean resourceSyncNeeded = false;

                    if (!localOpenSent && !engine.isShutdown()) {
                        engine.fireWrite(localOpen, 0);
                        engine.configuration().recomputeEffectiveFrameSizeLimits();
                        localOpenSent = true;
                        resourceSyncNeeded = true;
                    }

                    if (isLocallyClosed() && !localCloseSent && !engine.isShutdown()) {
                        Close localClose = new Close().setError(getCondition());
                        engine.fireWrite(localClose, 0);
                        localCloseSent = true;
                        resourceSyncNeeded = false;  // Session resources can't write anything now
                    }

                    if (resourceSyncNeeded) {
                        allSessions().forEach(session -> session.trySyncLocalStateWithRemote());
                    }
                }
            } else if (remoteHeader != null || getState() == ConnectionState.ACTIVE || remoteHeaderHandler != null) {
                headerSent = true;
                engine.fireWrite(HeaderEnvelope.AMQP_HEADER_ENVELOPE);
            }
        }
    }