Class TrcPeriodicThread.TaskState

java.lang.Object
trclib.robotcore.TrcPeriodicThread.TaskState
Enclosing class:
TrcPeriodicThread<T>

private class TrcPeriodicThread.TaskState extends Object
This class keeps track of the state of the periodic task. It also provides thread synchronization control to make sure the integrity of the task state.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private T
     
    private final Thread
     
    private boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    TaskState(String instanceName, Runnable runnable, int taskPriority)
    Constructor: Create an instance of the object.
  • Method Summary

    Modifier and Type
    Method
    Description
    This method returns the last data object associated with the task.
    boolean
    This method checks if the periodic task is enabled.
    boolean
    This method checks if the periodic task has been terminated.
    void
    setData(T data)
    This method is called to set new data after new data have been acquired/processed.
    void
    setTaskEnabled(boolean enabled)
    This method enables/disables the periodic task.
    void
    This method is called after TaskState is created to start the task thread.
    void
    This method is called to terminate the periodic task.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • periodicThread

      private final Thread periodicThread
    • taskEnabled

      private boolean taskEnabled
    • data

      private T data
  • Constructor Details

    • TaskState

      public TaskState(String instanceName, Runnable runnable, int taskPriority)
      Constructor: Create an instance of the object.
  • Method Details

    • start

      public void start()
      This method is called after TaskState is created to start the task thread.
    • isTaskTerminated

      public boolean isTaskTerminated()
      This method checks if the periodic task has been terminated.
      Returns:
      true if task has been terminated, false otherwise.
    • terminateTask

      public void terminateTask()
      This method is called to terminate the periodic task.
    • isTaskEnabled

      public boolean isTaskEnabled()
      This method checks if the periodic task is enabled.
      Returns:
      true if task is enabled, false otherwise.
    • setTaskEnabled

      public void setTaskEnabled(boolean enabled)
      This method enables/disables the periodic task. If this is called to disable the task, the task will be set to a paused state. The operation will be resumed when this is called to enable it again.
      Parameters:
      enabled - specifies true to enable periodic task, false to disable.
    • getData

      public T getData()
      This method returns the last data object associated with the task. If there is no new data since the last call, it will return null. This method, along with setData(), provides a thread-safe way to access the data produced or processed by the thread.
      Returns:
      newly acquired data if any, null if none.
    • setData

      public void setData(T data)
      This method is called to set new data after new data have been acquired/processed. This method, along with getData(), provides a thread-safe way to access the data produced or processed by the thread.
      Parameters:
      data - specifies newly acquired/processed data.