Separate ActivityExecutor.forceStop() method out from the stop() method. Removing the "forcing" flag in the stop() method.

This commit is contained in:
yabinmeng
2023-01-11 17:34:48 -06:00
parent c172a140eb
commit 2aeeea125c
3 changed files with 34 additions and 13 deletions

View File

@@ -82,18 +82,40 @@ public class ActivityExecutor implements ActivityController, ParameterMap.Listen
/**
* Simply stop the motors
*
* @param forcing whether to force (without trying to wait) the activity to reach stopped/finished state
*/
public void stopActivity(boolean forcing) {
logger.info(() ->
(forcing ? "forcing " : "") + "stopping activity in progress: " + this.getActivityDef().getAlias());
public void stopActivity() {
logger.info(() -> "stopping activity in progress: " + this.getActivityDef().getAlias());
activity.setRunState(RunState.Stopping);
motors.forEach(Motor::requestStop);
tally.awaitNoneOther(RunState.Stopped, RunState.Finished);
shutdownExecutorService(Integer.MAX_VALUE);
tally.awaitNoneOther(RunState.Stopped,RunState.Finished);
activity.setRunState(RunState.Stopped);
logger.info(() -> "stopped: " + this.getActivityDef().getAlias() + " with " + motors.size() + " slots");
Annotators.recordAnnotation(Annotation.newBuilder()
.session(sessionId)
.interval(this.startedAt, this.stoppedAt)
.layer(Layer.Activity)
.label("alias", getActivityDef().getAlias())
.label("driver", getActivityDef().getActivityType())
.label("workload", getActivityDef().getParams().getOptionalString("workload").orElse("none"))
.detail("params", getActivityDef().toString())
.build()
);
}
/**
* Force stop the motors without trying to wait for the activity to reach stopped/finished state
*/
public void forceStopActivity() {
logger.info(() -> "force stopping activity in progress: " + this.getActivityDef().getAlias());
activity.setRunState(RunState.Stopping);
motors.forEach(Motor::requestStop);
if (!forcing) {
tally.awaitNoneOther(RunState.Stopped, RunState.Finished);
}
shutdownExecutorService(Integer.MAX_VALUE);
tally.awaitNoneOther(RunState.Stopped,RunState.Finished);

View File

@@ -84,10 +84,9 @@ public class ActivityRuntimeInfo implements ProgressCapable {
return this.activity.getRunState();
}
public void stopActivity() { this.executor.stopActivity(false); }
public void forceStopActivity() {
this.executor.stopActivity(true);
}
public void stopActivity() { this.executor.stopActivity(); }
public void forceStopActivity() { this.executor.forceStopActivity(); }
public ActivityExecutor getActivityExecutor() {
return executor;

View File

@@ -65,7 +65,7 @@ public class ActivityExecutorTest {
try {
ad.setThreads(1);
ae.startActivity();
ae.stopActivity(false);
ae.stopActivity();
ae.startActivity();
ae.startActivity();
ExecutionResult executionResult = future.get();