Class CoreMotor<D>

  • All Implemented Interfaces:
    ActivityDefObserver, Motor<D>, Stoppable, java.lang.Runnable

    public class CoreMotor<D>
    extends java.lang.Object
    implements ActivityDefObserver, Motor<D>, Stoppable
    ActivityMotor is a Runnable which runs in one of an activity's many threads. It is the iteration harness for individual cycles of an activity. Each ActivityMotor instance is responsible for taking input from a LongSupplier and applying the provided LongConsumer to it on each cycle. These two parameters are called input and action, respectively. This motor implementation splits the handling of sync and async actions with a hard fork in the middle to limit potential breakage of the prior sync implementation with new async logic.
    • Constructor Detail

      • CoreMotor

        public CoreMotor​(Activity activity,
                         long slotId,
                         Input input)
        Create an ActivityMotor.
        Parameters:
        activity - The activity that this motor will be associated with.
        slotId - The enumeration of the motor, as assigned by its executor.
        input - A LongSupplier which provides the cycle number inputs.
      • CoreMotor

        public CoreMotor​(Activity activity,
                         long slotId,
                         Input input,
                         Action action)
        Create an ActivityMotor.
        Parameters:
        activity - The activity that this motor is based on.
        slotId - The enumeration of the motor, as assigned by its executor.
        input - A LongSupplier which provides the cycle number inputs.
        action - An LongConsumer which is applied to the input for each cycle.
      • CoreMotor

        public CoreMotor​(Activity activity,
                         long slotId,
                         Input input,
                         Action action,
                         Output output)
        Create an ActivityMotor.
        Parameters:
        activity - The activity that this motor is based on.
        slotId - The enumeration of the motor, as assigned by its executor.
        input - A LongSupplier which provides the cycle number inputs.
        action - An LongConsumer which is applied to the input for each cycle.
        output - An optional opTracker.
    • Method Detail

      • setInput

        public Motor<D> setInput​(Input input)
        Set the input for this ActivityMotor.
        Specified by:
        setInput in interface Motor<D>
        Parameters:
        input - The LongSupplier that provides the cycle number.
        Returns:
        this ActivityMotor, for chaining
      • setAction

        public Motor<D> setAction​(Action action)
        Set the action for this ActivityMotor.
        Specified by:
        setAction in interface Motor<D>
        Parameters:
        action - The LongConsumer that will be applied to the next cycle number.
        Returns:
        this ActivityMotor, for chaining
      • getSlotId

        public long getSlotId()
        Description copied from interface: Motor
        get the slotId which this motor is assigned to within the activity instance.
        Specified by:
        getSlotId in interface Motor<D>
        Returns:
        long slot id
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • requestStop

        public void requestStop()
        Description copied from interface: Stoppable
        Ask this component to stop cycling. This is an asynchronous request. Once the current active cycle completes, the request will cause the component to stop cooperatively.
        Specified by:
        requestStop in interface Stoppable
      • setResultOutput

        public void setResultOutput​(Output resultOutput)