Package trclib.robotcore
Class TrcTaskMgr.TaskObject
java.lang.Object
trclib.robotcore.TrcTaskMgr.TaskObject
- Enclosing class:
- TrcTaskMgr
This class implements TaskObject that will be created whenever a class is registered as a cooperative
multi-tasking task. The created task objects will be entered into an array list of task objects to be
scheduled by the scheduler.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final TrcTaskMgr.Task
private final String
private final long[]
private TrcPeriodicThread<Object>
private final int[]
private final long[]
private final long[]
private final HashSet<TrcTaskMgr.TaskType>
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
TaskObject
(String taskName, TrcTaskMgr.Task task) Constructor: Creates an instance of the task object with the given name and the given task type. -
Method Summary
Modifier and TypeMethodDescriptionprivate double
getAverageTaskElapsedTime
(TrcTaskMgr.TaskType taskType) This method returns the average task elapsed time in seconds.private double
getAverageTaskInterval
(TrcTaskMgr.TaskType taskType) This method returns the average task interval time in seconds.private TrcTaskMgr.Task
getTask()
This method returns the class object that was associated with this task object.long
This method returns the task interval for TaskType.STANDALONE_TASK.private boolean
hasType
(TrcTaskMgr.TaskType type) This method checks if the given task type is registered with this task object.boolean
This method checks if this task object is registered for any task type.boolean
This method checks if the given task type is registered with this task object.private void
recordElapsedTime
(TrcTaskMgr.TaskType taskType) This method records the task elapsed time in the task performance arrays.private void
recordStartTime
(TrcTaskMgr.TaskType taskType) This method records the task start timestamp in the task performance arrays.boolean
This method adds the given task type to the task object.boolean
registerTask
(TrcTaskMgr.TaskType type, long taskInterval) This method adds the given task type to the task object.boolean
registerTask
(TrcTaskMgr.TaskType type, long taskInterval, int taskPriority) This method adds the given task type to the task object.void
setTaskData
(Object data) This method sets the task data for TaskType.STANDALONE_TASK.void
setTaskInterval
(long taskInterval) This method sets the task interval for TaskType.STANDALONE_TASK.private void
standaloneTask
(Object context) This method runs the periodic standalone task.toString()
This method returns the instance name of the task.boolean
This method unregisters the given task object from all task types.boolean
This method removes the given task type from the task object.
-
Field Details
-
taskName
-
task
-
taskTypes
-
taskStartTimes
private final long[] taskStartTimes -
taskTotalIntervals
private final long[] taskTotalIntervals -
taskTotalElapsedTimes
private final long[] taskTotalElapsedTimes -
taskTimeSlotCounts
private final int[] taskTimeSlotCounts -
taskThread
-
-
Constructor Details
-
TaskObject
Constructor: Creates an instance of the task object with the given name and the given task type.- Parameters:
taskName
- specifies the instance name of the task.task
- specifies the object that implements the TrcTaskMgr.Task interface.
-
-
Method Details
-
toString
This method returns the instance name of the task. -
registerTask
This method adds the given task type to the task object.- Parameters:
type
- specifies the task type.taskInterval
- specifies the periodic interval for STANDALONE_TASK, ignore for any other task types. If zero interval is specified, the task will be run in a tight loop.taskPriority
- specifies the priority of the associated thread. Only valid for STANDALONE_TASK, ignored for any other task types.- Returns:
- true if successful, false if the task with that task type is already registered in the task list.
-
registerTask
This method adds the given task type to the task object.- Parameters:
type
- specifies the task type.taskInterval
- specifies the periodic interval for STANDALONE_TASK, ignore for any other task types. If zero interval is specified, the task will be run in a tight loop.- Returns:
- true if successful, false if the task with that task type is already registered in the task list.
-
registerTask
This method adds the given task type to the task object.- Parameters:
type
- specifies the task type.- Returns:
- true if successful, false if the task with that task type is already registered in the task list.
-
unregisterTask
This method removes the given task type from the task object.- Parameters:
type
- specifies the task type.- Returns:
- true if successful, false if the task with that type is not found the task list.
-
unregisterTask
public boolean unregisterTask()This method unregisters the given task object from all task types.- Returns:
- true if successfully removed from any task type, false otherwise.
-
isRegistered
This method checks if the given task type is registered with this task object.- Parameters:
type
- specifies the task type to be checked against.- Returns:
- true if this task is registered with the given type, false otherwise.
-
isRegistered
public boolean isRegistered()This method checks if this task object is registered for any task type.- Returns:
- true if this task is registered with any type, false otherwise.
-
hasType
This method checks if the given task type is registered with this task object.- Parameters:
type
- specifies the task type to be checked against.- Returns:
- true if this task is registered as the given type, false otherwise.
-
getTask
This method returns the class object that was associated with this task object.- Returns:
- class object associated with the task.
-
getTaskInterval
public long getTaskInterval()This method returns the task interval for TaskType.STANDALONE_TASK.- Returns:
- task interval in msec. If there is no STANDALONE_TASK type in the task object, zero is returned.
-
setTaskInterval
public void setTaskInterval(long taskInterval) This method sets the task interval for TaskType.STANDALONE_TASK. It has no effect for any other types.- Parameters:
taskInterval
- specifies the periodic interval for STANDALONE_TASK, ignore for any other task types. If zero interval is specified, the task will be run in a tight loop.
-
setTaskData
This method sets the task data for TaskType.STANDALONE_TASK. It has no effect for any other types.- Parameters:
data
- specifies the thread data for STANDALONE_TASK, ignore for any other task types.
-
standaloneTask
This method runs the periodic standalone task.- Parameters:
context
- specifies the context (not used).
-
recordStartTime
This method records the task start timestamp in the task performance arrays. It is used to calculate task elapsed time after the execution of a task.- Parameters:
taskType
- specifies the task type to index into the task performance arrays.
-
recordElapsedTime
This method records the task elapsed time in the task performance arrays.- Parameters:
taskType
- specifies the task type to index into the task performance arrays.
-
getAverageTaskElapsedTime
This method returns the average task elapsed time in seconds.- Parameters:
taskType
- specifies the task type to index into the task performance arrays.- Returns:
- average task elapsed time in seconds.
-
getAverageTaskInterval
This method returns the average task interval time in seconds.- Parameters:
taskType
- specifies the task type to index into the task performance arrays.- Returns:
- average task interval time in seconds.
-