Capacity.ContextAwareCapacityWrapper<C extends Capacity>| Modifier and Type | Method and Description |
|---|---|
AgentTask |
at([task : AgentTask],
time : long,
procedure : (Agent)=>void)
Schedule a given task to be executed at the given time.
|
AgentTask |
atFixedDelay([task : AgentTask],
delay : long,
procedure : (Agent)=>void)
Schedule a single-execution task.
|
boolean |
cancel(task : AgentTask,
[mayInterruptIfRunning : boolean])
Attempts to cancel execution of this task.
|
AgentTask |
every([task : AgentTask],
period : long,
procedure : (Agent)=>void)
Schedule a periodic execution of the given task.
|
AgentTask |
execute([task : AgentTask],
procedure : (Agent)=>void)
Schedule a single-execution task.
|
ConcurrentSet<String> |
getActiveTasks()
Replies the names of the active tasks.
|
AgentTask |
in([task : AgentTask],
delay : long,
procedure : (Agent)=>void)
Schedule a given task to be executed after the specified delay.
|
boolean |
isCanceled(task : AgentTask)
Replies if the given task was canceled.
|
void |
setName(task : AgentTask,
name : String)
Change the name of the given task.
|
AgentTask |
task(name : String)
Create a named task that can be retrieved and schedule later.
|
@Pure
def getActiveTasks() : ConcurrentSet<String>
Schedulesdef in([task : AgentTask],
delay : long,
procedure : (Agent)=>void) : AgentTask
SchedulesThe 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.
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:
task - the task that will run the given closure. If null, a new task is created.delay - time in milliseconds to delay the procedure execution.procedure - the closure to execute.def task(name : String) : AgentTask
SchedulesIf this function is invoked from a 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:
name - the name of the task. If null or empty, a random name will be given to the task.null if one of the conditions in the function's comment
evaluates to true.def setName(task : AgentTask,
name : String) : void
SchedulesThis function should not be directly invoked from a regular SARL code. It is provided for enabling a SRE to change the name of a task.
task - the task to change.name - the new name of the task.def cancel(task : AgentTask,
[mayInterruptIfRunning : boolean]) : boolean
Schedulescancel 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.task - the task to cancel.mayInterruptIfRunning - true if the thread executing this
task should be interrupted; otherwise, in-progress tasks are allowed
to completefalse if the task could not be canceled,
typically because it has already completed normally;
true otherwise@Pure
def isCanceled(task : AgentTask) : boolean
Schedulestask - the task.true if the task was canceled with Schedules.cancel(AgentTask,boolean)
or Schedules.cancel(AgentTask); false otherwise.def every([task : AgentTask],
period : long,
procedure : (Agent)=>void) : AgentTask
SchedulesIf the duration of the task is greater to the given period length, then
multiple task's instances will be run in parallel, in opposite to the
atFixedDelay() function.
For example, consider the following code:
every(500) [ sleep(2000) ]
At a given time, 4 instances (A, B, C, D) of the task may be run in parallel:
t=0 0500 1000 1500 2000 2500 3000 3500 4000 4500
| | | | | | | | | |
[-A-----------------------]
[-B-------------------------]
[-C-------------------------]
[-D-------------------------]
[-E-------------------------]
[-F-------------------------]
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:
task - the task to associate to the procedure. If null a new task is created.period - the number of milliseconds between two launches of the given procedure.procedure - the procedure to launch. The parameter of the procedure is the agent.def atFixedDelay([task : AgentTask],
delay : long,
procedure : (Agent)=>void) : AgentTask
SchedulesIf the duration of the task is greater to the given delay length, then
no multiple task's instance are run in parallel, in opposite to the
every() function.
For example, consider the following code:
atFixedDelay(500) [ sleep(2000) ]
At a given time, 3 instances (A, B, C) of the task are run in sequence, and
each run is separated by 500 milliseconds:
t=0 0500 1000 1500 2000 2500 3000 3500 4000 4500 5000
| | | | | | | | | | |
[-A-----------------------]
[-B-------------------------]
[-C-------------------------]
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:
task - the task to associate to the procedure. If null a new task is created.delay - the delay in milliseconds.procedure - the procedure to launch. The parameter of the procedure is the agent.def execute([task : AgentTask],
procedure : (Agent)=>void) : AgentTask
SchedulesThis function is the easy to use version and efficient implementation of the code
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.
task - the task to associate to the procedure. If null a new task is created.procedure - the procedure to launch. The parameter of the procedure is the agent.def at([task : AgentTask],
time : long,
procedure : (Agent)=>void) : AgentTask
SchedulesIf the given time is passed, according to Time then the task is not executed.
The given procedure takes one parameter: the agent associated to the task. It is name 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:
task - the task that will run the given closure. If null, a new task is created.time - the time in milliseconds at which to start the procedure execution.procedure - the closure to execute.null if the procedure is not scheduled.Copyright © 2021 the original authors or authors.