io.sarl.sre.janus.services.executor
Interface ExecutorService
All Superinterfaces:
org.arakhne.afc.services.IService
All Known Implementing Classes:
JreExecutorService
interface ExecutorService
implements org.arakhne.afc.services.IService
This class enables the SRE kernel to be distributed other a network.
Maven Group Identifier:
io.sarl.sre.janus
Maven Artifact Identifier:
janus.kernel
Property Summary
Modifier and type Property and description
long taskCount
Replies the number of tasks that this service has to run.
Action Summary
Modifier and type Action and description
abstract void applyBlockingConsumer([Logger],Iterable<T>,Consumer<T>)
Submit a task on the collection's elements to the executor service and wait for the termination of all the tasks.
abstract java.util.concurrent.Future<V> executeAsap([Logger],Runnable)
Submit a task to the executor service.
abstract java.util.concurrent.Future<V> executeAsap([Logger],Callable<V>)
Submit a task to the executor service.
abstract java.util.concurrent.Future<V> executeAsap([Logger],T,Runnable)
Submit a task to the executor service.
abstract int executeBlockingTask([Logger],int,int,Runnable)
Submit a single task multiple times to the executor service.
abstract void executeBlockingTasks([Logger],[boolean],Collection<E>)
Submit tasks to the executor service and wait for the termination of all the tasks.
abstract void executeNotBlockingTask([Logger],int,int,Runnable)
Submit a single task multiple times to the executor service.
abstract long getTaskCount
Replies the number of tasks that this service has to run.
static void neverReturn(Runnable)
This function simulate the never return from this call.
abstract void purge
Remove any canceled/terminated tasks from the lists of tasks.
abstract boolean remove(Runnable)
Removes this task from the executor's internal queue if it is present, thus causing it not to be run if it has not already started.
abstract java.util.concurrent.ScheduledFuture<V> schedule([Logger],[long],[TimeUnit],Runnable)
Schedule the given task.
abstract java.util.concurrent.ScheduledFuture<V> schedule([Logger],[long],[TimeUnit],Callable<V>)
Schedule the given task.
abstract java.util.concurrent.ScheduledFuture<V> scheduleAtFixedRate([Logger],[long],[long],[TimeUnit],Runnable)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on.
abstract java.util.concurrent.ScheduledFuture<V> scheduleWithFixedDelay([Logger],[long],[long],[TimeUnit],Runnable)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.
abstract void toJson(JsonBuffer)
Fill the given buffer with the state of the executor service.
Property Details
taskCount
val taskCount : long
Replies the number of tasks that this service has to run. The tasks that are considered are runnable, callable and scheduled tasks. When is a task is running or scheduled for a future run, it is counted.

This property is an alias for the action: getTaskCount

Returns:
the number of tasks that are run or to be run.
Since:
0.11
Action Details
applyBlockingConsumer([Logger],Iterable<T>,Consumer<T>)
def applyBlockingConsumer([Logger],Iterable<T>,Consumer<T>)

with T

Submit a task on the collection's elements to the executor service and wait for the termination of all the tasks.

You should ensure that the given task is properly synchronized on any shared object.

According to the implementation of the service, the given task may be run in the same or separated thread than the one of the caller.

If an exception occurs into the given consume, the exception is logged and it is thrown.
Parameters:
logger - the logger to use for errors.
collection - the collection of elements to iterate on.
task - the task to submit. Be sure that the task is synchronized on the given collection.
Since:
0.6
executeAsap([Logger],Runnable)
def executeAsap([Logger],Runnable) : java.util.concurrent.Future<V>
Submit a task to the executor service.

According to the implementation of the service, the given task may be run in the same or separated thread than the one of the caller. In another words, there is no warranty that the caller's thread is blocked until the termination of the task.

If an exception occurs into the given task, the exception is logged. It is never thrown by this function.
Parameters:
logger - the logger to use for errors.
task - the task to submit.
Returns:
a Future representing the pending execution task.
executeAsap([Logger],Callable<V>)
def executeAsap([Logger],Callable<V>) : java.util.concurrent.Future<V>

with T

Submit a task to the executor service.

According to the implementation of the service, the given task may be run in the same or separated thread than the one of the caller. In another words, there is no warranty that the caller's thread is blocked until the termination of the task.

If an exception occurs into the given task, the exception is logged. It is never thrown by this function.
Parameters:
<T> - - the type of the value replied by the task.
task - the task to submit.
Returns:
a Future representing the pending execution task.
executeAsap([Logger],T,Runnable)
def executeAsap([Logger],T,Runnable) : java.util.concurrent.Future<V>

with T

Submit a task to the executor service. The Future's get method will return the given result upon successful completion.

According to the implementation of the service, the given task may be run in the same or separated thread than the one of the caller. In another words, there is no warranty that the caller's thread is blocked until the termination of the task.

If an exception occurs into the given task, the exception is logged. It is never thrown by this function.
Parameters:
<T> - - the type of the value replied by the task.
task - the task to submit.
result - result to return after the execution.
Returns:
a Future representing the pending execution task.
executeBlockingTask([Logger],int,int,Runnable)
def executeBlockingTask([Logger],int,int,Runnable) : int
Submit a single task multiple times to the executor service.

The same task instance will be submit to the executor service.

runGroupSize indicates how many number of times the task will be run on a single thread.

This function is equivalent to:
br for(i in [ 1 .. (nbExecutions/runGroupSize) ])br dobr execute({br for(j in [1..runGroupSize]) {br task.runbr }br })br donebr 

Caution: if a task is failing, the exception will be output on the logger. This function never fails.

According to the implementation of the service, the given task may be run in the same or separated thread than the one of the caller.

If an exception occurs into the given consume, the exception is logged. It is never thrown by this function.
Parameters:
logger - the logger to use for errors.
task - the task to submit.
nbExecutions - the number of times the task must be run, usually greater than 1.
runGroupSize - the number of tasks to be run by a single thread.
Returns:
the number of successful runs.
Since:
0.5
executeBlockingTasks([Logger],[boolean],Collection<E>)
def executeBlockingTasks([Logger],[boolean],Collection<E>)
Submit tasks to the executor service and wait for the termination of all the tasks. This function ensures that the caller's thread is blocked until all the given tasks have been finished.

According to the implementation of the service, the given tasks may be run in the same or separated thread than the one of the caller.

If an exception occurs into the given task, the exception is thrown if thrownExceptions evaluates to true. If it is evaluates to false, the exception is logged.
Parameters:
task - the task to submit.
thrownExceptions - indicates if the exceptions in the given tasks are thrown forward by this function.
logger - the logger to use for errors.
Since:
0.6
executeNotBlockingTask([Logger],int,int,Runnable)
def executeNotBlockingTask([Logger],int,int,Runnable)
Submit a single task multiple times to the executor service.

The same task instance will be submit to the executor service.

runGroupSize indicates how many number of times the task will be run on a single thread.

This function is equivalent to:
br for(i in [ 1 .. (nbExecutions/runGroupSize) ])br dobr execute({br for(j in [1..runGroupSize]) {br task.runbr }br })br donebr 

Caution: if a task is failing, the exception will be output on the logger. This function never fails.

According to the implementation of the service, the given task may be run in the same or separated thread than the one of the caller.

If an exception occurs into the given consume, the exception is logged. It is never thrown by this function.
Parameters:
logger - the logger to use for errors.
task - the task to submit.
nbExecutions - the number of times the task must be run, usually greater than 1.
runGroupSize - the number of tasks to be run by a single thread.
Since:
0.11
getTaskCount
def getTaskCount : long
Replies the number of tasks that this service has to run. The tasks that are considered are runnable, callable and scheduled tasks. When is a task is running or scheduled for a future run, it is counted.
Returns:
the number of tasks that are run or to be run.
Since:
0.11
neverReturn(Runnable)
def neverReturn(Runnable)
This function simulate the never return from this call. The EarlyExitException is thrown.
Parameters:
postCommand - is the command to be run when the early-exit exception is catch. This command may be used for running post actions on the same thread as the one which does an early exit.
Since:
0.6.0
purge
def purge
Remove any canceled/terminated tasks from the lists of tasks.
remove(Runnable)
def remove(Runnable) : boolean
Removes this task from the executor's internal queue if it is present, thus causing it not to be run if it has not already started.
Parameters:
task - the task to remove.
Returns:
true if the task was removed.
schedule([Logger],[long],[TimeUnit],Runnable)
def schedule([Logger],[long],[TimeUnit],Runnable) : java.util.concurrent.ScheduledFuture<V>
Schedule the given task.

According to the implementation of the service, the given task may be run in the same or separated thread than the one of the caller. In another words, there is no warranty that the caller's thread is blocked until the termination of the task.

If an exception occurs into the given task, the exception is logged. It is never thrown by this function.
Parameters:
logger - the logger to use for errors.
command - task to run
delay - delay for waiting before launching the command
unit - time unit of the delay
Returns:
a Future representing the pending execution task.
schedule([Logger],[long],[TimeUnit],Callable<V>)
def schedule([Logger],[long],[TimeUnit],Callable<V>) : java.util.concurrent.ScheduledFuture<V>

with T

Schedule the given task.

According to the implementation of the service, the given task may be run in the same or separated thread than the one of the caller. In another words, there is no warranty that the caller's thread is blocked until the termination of the task.

If an exception occurs into the given task, the exception is logged. It is never thrown by this function.
Parameters:
<T> - - the type of the value replied by the task.
logger - the logger to use for errors.
command - task to run
delay - delay for waiting before launching the command
unit - time unit of the delay
Returns:
a Future representing the pending execution task.
scheduleAtFixedRate([Logger],[long],[long],[TimeUnit],Runnable)
def scheduleAtFixedRate([Logger],[long],[long],[TimeUnit],Runnable) : java.util.concurrent.ScheduledFuture<V>
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor. If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.

According to the implementation of the service, the given task may be run in the same or separated thread than the one of the caller. In another words, there is no warranty that the caller's thread is blocked until the termination of the task.

If an exception occurs into the given task, the exception is logged. It is never thrown by this function.
Parameters:
logger - the logger to use for errors.
command - task to run
initialDelay - the time to delay first execution
period - the period between successive executions
unit - รจ the time unit of the initialDelay and period parameters
Returns:
a Future representing the pending execution task.
scheduleWithFixedDelay([Logger],[long],[long],[TimeUnit],Runnable)
def scheduleWithFixedDelay([Logger],[long],[long],[TimeUnit],Runnable) : java.util.concurrent.ScheduledFuture<V>
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor.

According to the implementation of the service, the given task may be run in the same or separated thread than the one of the caller. In another words, there is no warranty that the caller's thread is blocked until the termination of the task.

If an exception occurs into the given task, the exception is logged. It is never thrown by this function.
Parameters:
logger - the logger to use for errors.
command - the task to execute
initialDelay - the time to delay first execution
delay - the delay between the termination of one execution and the start of the next
unit - the time unit of the initialDelay and delay parameters
Returns:
a ScheduledFuture representing pending completion of the task, and whose get() method will throw an exception upon cancellation
toJson(JsonBuffer)
def toJson(JsonBuffer)
Fill the given buffer with the state of the executor service.
Parameters:
buffer - the Json buffer to fill out with the executor service's state.
Since:
0.12