/** * 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. */ public void addStateChangeListener(StateMachine.StateChangeListener<TaskStatus> stateChangeListener) { taskStatus.addStateChangeListener(stateChangeListener); }
@Override public void addStateChangeListener(StateChangeListener<BufferState> stateChangeListener) { state.addStateChangeListener(stateChangeListener); }
/** * 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. */ public void addStateChangeListener(StateChangeListener<QueryState> stateChangeListener) { queryState.addStateChangeListener(stateChangeListener); }
/** * 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. */ public void addStateChangeListener(StateChangeListener<TaskState> stateChangeListener) { taskState.addStateChangeListener(stateChangeListener); }
@Override public void addStateChangeListener(StateChangeListener<BufferState> stateChangeListener) { state.addStateChangeListener(stateChangeListener); }
@Override public void addStateChangeListener(StateChangeListener<BufferState> stateChangeListener) { state.addStateChangeListener(stateChangeListener); }
@Override public void addStateChangeListener(StateChangeListener<BufferState> stateChangeListener) { state.addStateChangeListener(stateChangeListener); }
/** * 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. */ public void addStateChangeListener(StateChangeListener<StageState> stateChangeListener) { stageState.addStateChangeListener(stateChangeListener); }
public TaskStateMachine(TaskId taskId, Executor executor) { this.taskId = requireNonNull(taskId, "taskId is null"); taskState = new StateMachine<>("task " + taskId, executor, TaskState.RUNNING, TERMINAL_TASK_STATES); taskState.addStateChangeListener(new StateChangeListener<TaskState>() { @Override public void stateChanged(TaskState newState) { log.debug("Task %s is %s", taskId, newState); } }); }
/** * Add a listener for the final query info. This notification is guaranteed to be fired only once. * 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. */ public void addQueryInfoStateChangeListener(StateChangeListener<QueryInfo> stateChangeListener) { AtomicBoolean done = new AtomicBoolean(); StateChangeListener<Optional<QueryInfo>> fireOnceStateChangeListener = finalQueryInfo -> { if (finalQueryInfo.isPresent() && done.compareAndSet(false, true)) { stateChangeListener.stateChanged(finalQueryInfo.get()); } }; finalQueryInfo.addStateChangeListener(fireOnceStateChangeListener); }
/** * Add a listener for the final stage info. This notification is guaranteed to be fired only once. * 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. */ public void addFinalStageInfoListener(StateChangeListener<StageInfo> finalStatusListener) { AtomicBoolean done = new AtomicBoolean(); StateChangeListener<Optional<StageInfo>> fireOnceStateChangeListener = finalStageInfo -> { if (finalStageInfo.isPresent() && done.compareAndSet(false, true)) { finalStatusListener.stateChanged(finalStageInfo.get()); } }; finalStageInfo.addStateChangeListener(fireOnceStateChangeListener); }
public StageStateMachine( StageId stageId, URI location, Session session, PlanFragment fragment, ExecutorService executor, SplitSchedulerStats schedulerStats) { this.stageId = requireNonNull(stageId, "stageId is null"); this.location = requireNonNull(location, "location is null"); this.session = requireNonNull(session, "session is null"); this.fragment = requireNonNull(fragment, "fragment is null"); this.scheduledStats = requireNonNull(schedulerStats, "schedulerStats is null"); stageState = new StateMachine<>("stage " + stageId, executor, PLANNED, TERMINAL_STAGE_STATES); stageState.addStateChangeListener(state -> log.debug("Stage %s is %s", stageId, state)); finalStageInfo = new StateMachine<>("final stage " + stageId, executor, Optional.empty()); }
/** * Add a listener for the final task info. This notification is guaranteed to be fired only once. * 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. */ public void addFinalTaskInfoListener(StateChangeListener<TaskInfo> stateChangeListener) { AtomicBoolean done = new AtomicBoolean(); StateChangeListener<Optional<TaskInfo>> fireOnceStateChangeListener = finalTaskInfo -> { if (finalTaskInfo.isPresent() && done.compareAndSet(false, true)) { stateChangeListener.stateChanged(finalTaskInfo.get()); } }; finalTaskInfo.addStateChangeListener(fireOnceStateChangeListener); fireOnceStateChangeListener.stateChanged(finalTaskInfo.get()); }
private static SettableFuture<State> addTestListener(StateMachine<State> stateMachine) { State initialState = stateMachine.get(); SettableFuture<Boolean> initialStateNotified = SettableFuture.create(); SettableFuture<State> stateChanged = SettableFuture.create(); Thread addingThread = Thread.currentThread(); stateMachine.addStateChangeListener(newState -> { Thread callbackThread = Thread.currentThread(); if (callbackThread == addingThread) { stateChanged.setException(new AssertionError("Listener was not called back on a different thread")); return; } if (newState == initialState) { initialStateNotified.set(true); } else { stateChanged.set(newState); } }); assertTrue(tryGetFutureValue(initialStateNotified, 10, SECONDS).isPresent(), "Initial state notification not fired"); return stateChanged; }
public void addStateChangeListener(StateChangeListener<QueryState> stateChangeListener) { queryState.addStateChangeListener(stateChangeListener); }
public void addStateChangeListener(StateChangeListener<BufferState> stateChangeListener) { state.addStateChangeListener(stateChangeListener); }
public void addStateChangeListener(StateChangeListener<TaskState> stateChangeListener) { taskState.addStateChangeListener(stateChangeListener); }
@Override public void addStateChangeListener(StateChangeListener<TaskInfo> stateChangeListener) { try (SetThreadName ignored = new SetThreadName("HttpRemoteTask-%s", taskId)) { taskInfo.addStateChangeListener(stateChangeListener); } }
public TaskStateMachine(TaskId taskId, Executor executor) { this.taskId = requireNonNull(taskId, "taskId is null"); taskState = new StateMachine<>("task " + taskId, executor, TaskState.RUNNING, TERMINAL_TASK_STATES); taskState.addStateChangeListener(new StateChangeListener<TaskState>() { @Override public void stateChanged(TaskState newState) { log.debug("Task %s is %s", TaskStateMachine.this.taskId, newState); } }); }
public StageStateMachine(StageId stageId, URI location, Session session, PlanFragment fragment, ExecutorService executor) { this.stageId = requireNonNull(stageId, "stageId is null"); this.location = requireNonNull(location, "location is null"); this.session = requireNonNull(session, "session is null"); this.fragment = requireNonNull(fragment, "fragment is null"); stageState = new StateMachine<>("stage " + stageId, executor, PLANNED, TERMINAL_STAGE_STATES); stageState.addStateChangeListener(state -> log.debug("Stage %s is %s", stageId, state)); }