/** * Change to {@link ConnectionState#SUSPENDED} only if not already suspended and not lost * * @return true if connection is set to SUSPENDED */ public synchronized boolean setToSuspended() { if ( state.get() != State.STARTED ) { return false; } if ( (currentConnectionState == ConnectionState.LOST) || (currentConnectionState == ConnectionState.SUSPENDED) ) { return false; } setCurrentConnectionState(ConnectionState.SUSPENDED); postState(ConnectionState.SUSPENDED); return true; }
/** * Post a state change. If the manager is already in that state the change * is ignored. Otherwise the change is queued for listeners. * * @param newConnectionState new state * @return true if the state actually changed, false if it was already at that state */ public synchronized boolean addStateChange(ConnectionState newConnectionState) { if ( state.get() != State.STARTED ) { return false; } ConnectionState previousState = currentConnectionState; if ( previousState == newConnectionState ) { return false; } setCurrentConnectionState(newConnectionState); ConnectionState localState = newConnectionState; boolean isNegativeMessage = ((newConnectionState == ConnectionState.LOST) || (newConnectionState == ConnectionState.SUSPENDED) || (newConnectionState == ConnectionState.READ_ONLY)); if ( !isNegativeMessage && initialConnectMessageSent.compareAndSet(false, true) ) { localState = ConnectionState.CONNECTED; } postState(localState); return true; }
/** * Change to {@link ConnectionState#SUSPENDED} only if not already suspended and not lost * * @return true if connection is set to SUSPENDED */ public synchronized boolean setToSuspended() { if ( state.get() != State.STARTED ) { return false; } if ( (currentConnectionState == ConnectionState.LOST) || (currentConnectionState == ConnectionState.SUSPENDED) ) { return false; } currentConnectionState = ConnectionState.SUSPENDED; postState(ConnectionState.SUSPENDED); return true; }
/** * Post a state change. If the manager is already in that state the change * is ignored. Otherwise the change is queued for listeners. * * @param newConnectionState new state * @return true if the state actually changed, false if it was already at that state */ public synchronized boolean addStateChange(ConnectionState newConnectionState) { if ( state.get() != State.STARTED ) { return false; } ConnectionState previousState = currentConnectionState; if ( previousState == newConnectionState ) { return false; } currentConnectionState = newConnectionState; ConnectionState localState = newConnectionState; boolean isNegativeMessage = ((newConnectionState == ConnectionState.LOST) || (newConnectionState == ConnectionState.SUSPENDED) || (newConnectionState == ConnectionState.READ_ONLY)); if ( !isNegativeMessage && initialConnectMessageSent.compareAndSet(false, true) ) { localState = ConnectionState.CONNECTED; } postState(localState); return true; }