@SuppressWarnings("squid:S1181")
  private void fireStateChanged(
      T newState,
      FutureStateChange<T> futureStateChange,
      List<StateChangeListener<T>> stateChangeListeners) {
    checkState(!Thread.holdsLock(lock), "Cannot fire state change event while holding the lock");
    requireNonNull(newState, STATE_IS_NULL);

    // always fire listener callbacks from a different thread
    safeExecute(
        () -> {
          checkState(!Thread.holdsLock(lock), "Cannot notify while holding the lock");
          try {
            futureStateChange.complete(newState);
          } catch (Throwable e) {
            LOGGER.error("Error setting future state for {}", name, e);
          }
          for (StateChangeListener<T> stateChangeListener : stateChangeListeners) {
            fireStateChangedListener(newState, stateChangeListener);
          }
        });
  }
Sets the state if the current state {@code .equals()} the specified expected state. If the new
state does not {@code .equals()} the current state, listeners and waiters will be notified.

@return true if the state is set
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/StateMachine.java