Modifier and type | Property and description |
---|---|
ConcurrentSet<T> | activeTasks Replies the names of the active tasks. |
Modifier and type | Action and description |
---|---|
abstract AgentTask | at([AgentTask],long,Procedure1<Param>) Schedule a given task to be executed at the given time. |
abstract AgentTask | atFixedDelay([AgentTask],long,Procedure1<Param>) Schedule a single-execution task. |
abstract boolean | cancel(AgentTask,[boolean]) Attempts to cancel execution of this task. |
abstract AgentTask | every([AgentTask],long,Procedure1<Param>) Schedule a periodic execution of the given task. |
abstract AgentTask | execute([AgentTask],Procedure1<Param>) Schedule a single-execution task. |
abstract ConcurrentSet<T> | getActiveTasks Replies the names of the active tasks. |
abstract AgentTask | in([AgentTask],long,Procedure1<Param>) Schedule a given task to be executed after the specified delay. |
abstract boolean | isCanceled(AgentTask) Replies if the given task was canceled. |
abstract void | setName(AgentTask,String) Change the name of the given task. |
abstract AgentTask | task(String) Create a named task that can be retrieved and schedule later. |
val activeTasks : ConcurrentSet<T>
This property is an alias for the action: getActiveTasks
def at([AgentTask],long,Procedure1<Param>) : AgentTask
it
by default.
The given time is expressed in milliseconds according to the time scale of the SRE. It means that the given number of milliseconds may be not real milliseconds, depending on the definition of the builtin capacity Time.
If this function is invoked from a Behavior
and there is no provided task, the created task will be associated to the behavior instance. It means that the task will be automatically canceled when the behavior instance is unregistered from the the owning agent.
This function does nothing if one of the following conditions evaluates to true:
def atFixedDelay([AgentTask],long,Procedure1<Param>) : AgentTask
every()
function. For example, consider the following code:
br atFixedDelay(500) [ sleep(2000) ]br
At a given time, 3 instances (A, B, C) of the task are run in sequence, and each run is separated by 500 milliseconds:
br t=0 0500 1000 1500 2000 2500 3000 3500 4000 4500 5000br | | | | | | | | | | |br [-A-----------------------]br [-B-------------------------]br [-C-------------------------]br
For executing a task with a fixed rate, and not with a fixed delay between the task runs, you should use the every()
function.
The given procedure takes one parameter: the agent associated to the task. It is name it
by default.
The given delay is expressed in milliseconds according to the time scale of the SRE. It means that the given number of milliseconds may be not real milliseconds, depending on the definition of the builtin capacity Time.
It is recommended that the SARL run-time environment, which is providing the implementation of this function to provide an efficient implementation in the case the argument delay
is equal to zero. Indeed, if the delay
is equal to zero, the task should be run in an infinite loop until it is canceled, or the owning agent is killed.
This function does nothing if one of the following conditions evaluates to true:
def cancel(AgentTask,[boolean]) : boolean
cancel
is called, this task should never run. If the task has already started, then the mayInterruptIfRunning
parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.
def every([AgentTask],long,Procedure1<Param>) : AgentTask
atFixedDelay()
function. For example, consider the following code:
br every(500) [ sleep(2000) ]br
At a given time, 4 instances (A, B, C, D) of the task may be run in parallel:
br t=0 0500 1000 1500 2000 2500 3000 3500 4000 4500br | | | | | | | | | |br [-A-----------------------]br [-B-------------------------]br [-C-------------------------]br [-D-------------------------]br [-E-------------------------]br [-F-------------------------]br
For executing a task with a fixed delay between the runs, and not at a fixed rate, you should use the atFixedDelay()
function.
The given procedure takes one parameter: the agent associated to the task. It is name it
by default.
The given period is expressed in milliseconds according to the time scale of the SRE. It means that the given number of milliseconds may be not real milliseconds, depending on the definition of the builtin capacity Time.
If this function is invoked from a Behavior
and there is no provided task, the created task will be associated to the behavior instance. It means that the task will be automatically canceled when the behavior instance is unregistered from the the owning agent.
This function does nothing if one of the following conditions evaluates to true:
def execute([AgentTask],Procedure1<Param>) : AgentTask
in(0) [statements]
.
The given procedure takes one parameter: the agent associated to the task. It is name it
by default.
This function is supposed to execute the given procedure, even if the agent is not alive.
def getActiveTasks : ConcurrentSet<T>
def in([AgentTask],long,Procedure1<Param>) : AgentTask
it
by default.
The given delay is expressed in milliseconds according to the time scale of the SRE. It means that the given number of milliseconds may be not real milliseconds, depending on the definition of the builtin capacity Time.
If this function is invoked from a Behavior
and there is no provided task, the created task will be associated to the behavior instance. It means that the task will be automatically canceled when the behavior instance is unregistered from the the owning agent.
This function does nothing if one of the following conditions evaluates to true:
def isCanceled(AgentTask) : boolean
def setName(AgentTask,String)
def task(String) : AgentTask
Behavior
, the created task will be associated to the behavior instance. It means that the task will be automatically canceled when the behavior instance is unregistered from the the owning agent.
This function does nothing if one of the following conditions evaluates to true: