Class ActivityExecutor
- java.lang.Object
-
- io.engineblock.core.ActivityExecutor
-
- All Implemented Interfaces:
io.engineblock.activityapi.core.ActivityController,io.engineblock.activityapi.core.ProgressMeter,io.engineblock.activityimpl.ParameterMap.Listener
public class ActivityExecutor extends java.lang.Object implements io.engineblock.activityapi.core.ActivityController, io.engineblock.activityimpl.ParameterMap.Listener, io.engineblock.activityapi.core.ProgressMeterAn ActivityExecutor is a named instance of an execution harness for a single activity instance. It is responsible for managing threads and activity settings which may be changed while the activity is running.
An ActivityExecutor may be represent an activity that is defined and active in the running scenario, but which is inactive. This can occur when an activity is paused by controlling logic, or when the threads are set to zero.
Invariants:
- Motors may not receive parameter updates before their owning activities are initialized.
-
-
Constructor Summary
Constructors Constructor Description ActivityExecutor(io.engineblock.activityapi.core.Activity activity)
-
Method Summary
Modifier and Type Method Description booleanawaitCompletion(int waitTime)booleanawaitFinish(int timeout)voidforceStopExecutor(int initialMillisToWait)Shutdown the activity executor, with a grace period for the motor threads.io.engineblock.activityapi.core.ActivitygetActivity()io.engineblock.activityimpl.ActivityDefgetActivityDef()doublegetProgress()java.lang.StringgetProgressDetails()java.lang.StringgetProgressName()io.engineblock.activityapi.core.RunStategetProgressState()voidhandleParameterMapUpdate(io.engineblock.activityimpl.ParameterMap parameterMap)Listens for changes to parameter maps, maps them to the activity instance, and notifies all eligible listeners of changes.booleanisRunning()voidnotifyException(java.lang.Thread t, java.lang.Throwable e)booleanrequestStopExecutor(int secondsToWait)voidstartActivity()True-up the number of motor instances known to the executor.voidstopActivity()Simply stop the motorsvoidstopActivityWithErrorAsync(java.lang.Throwable throwable)voidstopActivityWithReasonAsync(java.lang.String reason)java.lang.StringtoString()
-
-
-
Method Detail
-
startActivity
public void startActivity()
True-up the number of motor instances known to the executor. Start all non-running motors. The protocol between the motors and the executor should be safe as long as each state change is owned by either the motor logic or the activity executor but not both, and strictly serialized as well. This is enforced by forcing start(...) to be serialized as well as using CAS on the motor states.
The startActivity method may be called to true-up the number of active motors in an activity executor after changes to threads.
-
stopActivity
public void stopActivity()
Simply stop the motors
-
forceStopExecutor
public void forceStopExecutor(int initialMillisToWait)
Shutdown the activity executor, with a grace period for the motor threads.- Parameters:
initialMillisToWait- milliseconds to wait after graceful shutdownActivity request, before forcing everything to stop
-
requestStopExecutor
public boolean requestStopExecutor(int secondsToWait)
-
handleParameterMapUpdate
public void handleParameterMapUpdate(io.engineblock.activityimpl.ParameterMap parameterMap)
Listens for changes to parameter maps, maps them to the activity instance, and notifies all eligible listeners of changes.- Specified by:
handleParameterMapUpdatein interfaceio.engineblock.activityimpl.ParameterMap.Listener
-
getActivityDef
public io.engineblock.activityimpl.ActivityDef getActivityDef()
-
awaitCompletion
public boolean awaitCompletion(int waitTime)
-
awaitFinish
public boolean awaitFinish(int timeout)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isRunning
public boolean isRunning()
-
getActivity
public io.engineblock.activityapi.core.Activity getActivity()
-
getProgress
public double getProgress()
- Specified by:
getProgressin interfaceio.engineblock.activityapi.core.ProgressMeter
-
getProgressDetails
public java.lang.String getProgressDetails()
- Specified by:
getProgressDetailsin interfaceio.engineblock.activityapi.core.ProgressMeter
-
getProgressName
public java.lang.String getProgressName()
- Specified by:
getProgressNamein interfaceio.engineblock.activityapi.core.ProgressMeter
-
getProgressState
public io.engineblock.activityapi.core.RunState getProgressState()
- Specified by:
getProgressStatein interfaceio.engineblock.activityapi.core.ProgressMeter
-
notifyException
public void notifyException(java.lang.Thread t, java.lang.Throwable e)
-
stopActivityWithReasonAsync
public void stopActivityWithReasonAsync(java.lang.String reason)
- Specified by:
stopActivityWithReasonAsyncin interfaceio.engineblock.activityapi.core.ActivityController
-
stopActivityWithErrorAsync
public void stopActivityWithErrorAsync(java.lang.Throwable throwable)
- Specified by:
stopActivityWithErrorAsyncin interfaceio.engineblock.activityapi.core.ActivityController
-
-