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 ; }
Post a state change . If the manager is already in that state the change is ignored . Otherwise the change is queued for listeners .