Class 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.ProgressMeter

    An 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)  
    • Constructor Detail

      • ActivityExecutor

        public ActivityExecutor​(io.engineblock.activityapi.core.Activity activity)
    • 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:
        handleParameterMapUpdate in interface io.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:
        toString in class java.lang.Object
      • isRunning

        public boolean isRunning()
      • getActivity

        public io.engineblock.activityapi.core.Activity getActivity()
      • getProgress

        public double getProgress()
        Specified by:
        getProgress in interface io.engineblock.activityapi.core.ProgressMeter
      • getProgressDetails

        public java.lang.String getProgressDetails()
        Specified by:
        getProgressDetails in interface io.engineblock.activityapi.core.ProgressMeter
      • getProgressName

        public java.lang.String getProgressName()
        Specified by:
        getProgressName in interface io.engineblock.activityapi.core.ProgressMeter
      • getProgressState

        public io.engineblock.activityapi.core.RunState getProgressState()
        Specified by:
        getProgressState in interface io.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:
        stopActivityWithReasonAsync in interface io.engineblock.activityapi.core.ActivityController
      • stopActivityWithErrorAsync

        public void stopActivityWithErrorAsync​(java.lang.Throwable throwable)
        Specified by:
        stopActivityWithErrorAsync in interface io.engineblock.activityapi.core.ActivityController