Package trclib.robotcore
Class TrcPeriodicThread.TaskState
java.lang.Object
trclib.robotcore.TrcPeriodicThread.TaskState
- Enclosing class:
- TrcPeriodicThread<T>
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetData()
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
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
start()
This method is called after TaskState is created to start the task thread.void
This method is called to terminate the periodic task.
-
Field Details
-
periodicThread
-
taskEnabled
private boolean taskEnabled -
data
-
-
Constructor Details
-
TaskState
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
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
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.
-