private synchronized boolean compareAndSetState(State expected, State update) {
    if (state == expected) {
      setState(update);
      return true;
    } else {
      return false;
    }
  }
Atomically sets the state to <code>update</code> if and only if the state is currently
<code>expected</code>.
@param expected the expected state.
@param update   the new state.
@return true if the update succeeds, or false if the current state does not equal
        <code>expected</code>.
hbase-common/src/main/java/org/apache/hadoop/hbase/io/FileChangeWatcher.java