public void addStateChangeListener(StateChangeListener<T> stateChangeListener) {
    requireNonNull(stateChangeListener, "stateChangeListener is null");

    T currentState;
    synchronized (lock) {
      currentState = state;
      if (!isTerminalState(currentState)) {
        stateChangeListeners.add(stateChangeListener);
      }
    }

    // Fire state change listener with the current state
    // always fire listener callbacks from a different thread
    safeExecute(() -> stateChangeListener.stateChanged(currentState));
  }
Adds a listener to be notified when the state instance changes according to {@code .equals()}.
Listener is always notified asynchronously using a dedicated notification thread pool so, care
should be taken to avoid leaking {@code this} when adding a listener in a constructor.
Additionally, it is possible notifications are observed out of order due to the asynchronous
execution. The listener is notified immediately of the current state.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/StateMachine.java