public State get ( ) { InternalState internalState = currentInternalState . get ( ) ; while ( ! internalState . isRead ) { // Slow path, the state is first time read. Change the state only if no other changes // happened between the moment initialState is read and this moment. This ensures that this // method only changes the isRead part of the internal state. currentInternalState . compareAndSet ( internalState , internalState . state == State . ENABLED ? InternalState . ENABLED_READ : InternalState . DISABLED_READ ) ; internalState = currentInternalState . get ( ) ; } return internalState . state ; }
Returns the current state and updates the status as being read .