@Singleton public class JreExecutorService extends AbstractSreService implements ExecutorService, PreReleasableService
com.google.common.util.concurrent.Service.Listener, com.google.common.util.concurrent.Service.State
Constructor and Description |
---|
JreExecutorService(standardService : ExecutorService,
scheduledService : ScheduledExecutorService)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
<T> void |
applyBlockingConsumer([logger : Logger],
collection : Iterable<T>,
task : Consumer<? super T>)
Submit a task on the collection's elements to the executor service and wait for the termination of all the tasks.
|
<T> Future<T> |
executeAsap([logger : Logger],
task : Callable<T>)
Submit a task to the executor service.
|
Future<?> |
executeAsap([logger : Logger],
task : Runnable)
Submit a task to the executor service.
|
<T> Future<T> |
executeAsap([logger : Logger],
result : T,
task : Runnable)
Submit a task to the executor service.
|
int |
executeBlockingTask([logger : Logger],
nbExecutions : int,
runGroupSize : int,
task : Runnable)
Submit a single task multiple times to the executor service.
|
void |
executeBlockingTasks([logger : Logger],
[thrownExceptions : boolean],
tasks : Collection<Runnable>)
Submit tasks to the executor service and wait for the termination of all the tasks.
|
void |
executeNotBlockingTask([logger : Logger],
nbExecutions : int,
runGroupSize : int,
task : Runnable)
Submit a single task multiple times to the executor service.
|
ExecutorsConfig |
getConfiguration()
Replies the configuration.
|
ExecutorService |
getExecutorService()
Replies the JRE service for scheduled tasks.
|
ScheduledExecutorService |
getScheduledExecutorService()
Replies the JRE service for scheduled tasks.
|
long |
getTaskCount()
Replies the number of tasks that this service has to run.
|
Thread.UncaughtExceptionHandler |
getUncaughtExceptionHandler()
Replies the default exception handler.
|
void |
onPreStop()
Invoked when the service should release resources prior to the shutdown process.
|
protected void |
onStart()
Do something when starting the service.
|
protected void |
onStop()
Do something when stopping the service.
|
void |
purge()
Remove any canceled/terminated tasks from the lists of tasks.
|
boolean |
remove(task : 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.
|
<T> ScheduledFuture<T> |
schedule([logger : Logger],
[delay : long],
[unit : TimeUnit],
command : Callable<T>)
Schedule the given task.
|
ScheduledFuture<?> |
schedule([logger : Logger],
[delay : long],
[unit : TimeUnit],
command : Runnable)
Schedule the given task.
|
ScheduledFuture<?> |
scheduleAtFixedRate([logger : Logger],
[initialDelay : long],
[period : long],
[unit : TimeUnit],
command : 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.
|
ScheduledFuture<?> |
scheduleWithFixedDelay([logger : Logger],
[initialDelay : long],
[delay : long],
[unit : TimeUnit],
command : 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.
|
void |
setConfiguration(config : ExecutorsConfig)
Change the configuration from the general configuration.
|
void |
setConfiguration(config : SreConfig)
Change the configuration from the general configuration.
|
void |
setUncaughtExceptionHandler(handler : Thread.UncaughtExceptionHandler)
Change the default exception handler.
|
void |
toJson(buffer : org.arakhne.afc.vmutil.json.JsonBuffer)
Fill the given buffer with the state of the executor service.
|
String |
toString()
Replies the state of this service as a string.
|
doStart, doStop
addListener, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, doCancelStart, failureCause, isRunning, notifyFailed, notifyStarted, notifyStopped, startAsync, state, stopAsync
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
neverReturn
@Inject
public new
(standardService : ExecutorService,
scheduledService : ScheduledExecutorService)
standardService
- the JRE service for executing not scheduled tasks.scheduledService
- the JRE service for executing scheduled tasks.@Pure
public def
getExecutorService() : ExecutorService
JreExecutorService
@Pure
public def
getTaskCount() : long
ExecutorService
getTaskCount
in interface ExecutorService
publicdef
applyBlockingConsumer([logger : Logger], collection : Iterable<T>, task : Consumer<? super T>) : voidwith
<T>
ExecutorService
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.
applyBlockingConsumer
in interface ExecutorService
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.@Pure
public def
getScheduledExecutorService() : ScheduledExecutorService
JreExecutorService
the
- JRE service.@Inject
public def
setUncaughtExceptionHandler(handler : Thread.UncaughtExceptionHandler) : void
JreExecutorService
handler
- the default exception handler.@Pure
public def
getUncaughtExceptionHandler() : Thread.UncaughtExceptionHandler
JreExecutorService
@Inject
public final def
setConfiguration(config : SreConfig) : void
JreExecutorService
config
- the configuration.public def
setConfiguration(config : ExecutorsConfig) : void
JreExecutorService
config
- the configuration.@Pure
public def
getConfiguration() : ExecutorsConfig
JreExecutorService
the
- configuration.protected def
onStart() : void
AbstractSreService
This function is called from AbstractSreService.doStart()
onStart
in class AbstractSreService
public def
onPreStop() : void
PreReleasableService
onPreStop
in interface PreReleasableService
protected def
onStop() : void
AbstractSreService
This function is called from AbstractSreService.doStop()
onStop
in class AbstractSreService
public def
executeBlockingTasks([logger : Logger],
[thrownExceptions : boolean],
tasks : Collection<Runnable>) : void
ExecutorService
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.
executeBlockingTasks
in interface ExecutorService
logger
- the logger to use for errors.thrownExceptions
- indicates if the exceptions in the given tasks are thrown forward by this function.tasks
- the task to submit.public def
executeBlockingTask([logger : Logger],
nbExecutions : int,
runGroupSize : int,
task : Runnable) : int
ExecutorService
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:
for(i in [ 1 .. (nbExecutions/runGroupSize) ])
do
execute({
for(j in [1..runGroupSize]) {
task.run
}
})
done
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.
executeBlockingTask
in interface ExecutorService
logger
- the logger to use for errors.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.task
- the task to submit.public def
executeNotBlockingTask([logger : Logger],
nbExecutions : int,
runGroupSize : int,
task : Runnable) : void
ExecutorService
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:
for(i in [ 1 .. (nbExecutions/runGroupSize) ])
do
execute({
for(j in [1..runGroupSize]) {
task.run
}
})
done
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.
executeNotBlockingTask
in interface ExecutorService
logger
- the logger to use for errors.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.task
- the task to submit.public def
executeAsap([logger : Logger],
task : Runnable) : Future<?>
ExecutorService
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.
executeAsap
in interface ExecutorService
logger
- the logger to use for errors.task
- the task to submit.if you don't want a future.
publicdef
executeAsap([logger : Logger], result : T, task : Runnable) : Future<T>with
<T>
ExecutorService
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.
executeAsap
in interface ExecutorService
T
- - the type of the value replied by the task.result
- result to return after the execution.task
- the task to submit.publicdef
executeAsap([logger : Logger], task : Callable<T>) : Future<T>with
<T>
ExecutorService
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.
executeAsap
in interface ExecutorService
T
- - the type of the value replied by the task.task
- the task to submit.public def
schedule([logger : Logger],
[delay : long],
[unit : TimeUnit],
command : Runnable) : ScheduledFuture<?>
ExecutorService
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.
schedule
in interface ExecutorService
logger
- the logger to use for errors.delay
- delay for waiting before launching the commandunit
- time unit of the delaycommand
- task to runpublicdef
schedule([logger : Logger], [delay : long], [unit : TimeUnit], command : Callable<T>) : ScheduledFuture<T>with
<T>
ExecutorService
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.
schedule
in interface ExecutorService
T
- - the type of the value replied by the task.logger
- the logger to use for errors.delay
- delay for waiting before launching the commandunit
- time unit of the delaycommand
- task to runpublic def
scheduleAtFixedRate([logger : Logger],
[initialDelay : long],
[period : long],
[unit : TimeUnit],
command : Runnable) : ScheduledFuture<?>
ExecutorService
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.
scheduleAtFixedRate
in interface ExecutorService
logger
- the logger to use for errors.initialDelay
- the time to delay first executionperiod
- the period between successive executionsunit
- รจ the time unit of the initialDelay and period parameterscommand
- task to runpublic def
scheduleWithFixedDelay([logger : Logger],
[initialDelay : long],
[delay : long],
[unit : TimeUnit],
command : Runnable) : ScheduledFuture<?>
ExecutorService
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.
scheduleWithFixedDelay
in interface ExecutorService
logger
- the logger to use for errors.initialDelay
- the time to delay first executiondelay
- the delay between the termination of one execution and the start of the nextunit
- the time unit of the initialDelay and delay parameterscommand
- the task to executepublic def
remove(task : Runnable) : boolean
ExecutorService
remove
in interface ExecutorService
task
- the task to remove.true
if the task was removed.public def
purge() : void
ExecutorService
purge
in interface ExecutorService
public def
toString() : String
JreExecutorService
toString
in class com.google.common.util.concurrent.AbstractService
public def
toJson(buffer : org.arakhne.afc.vmutil.json.JsonBuffer) : void
ExecutorService
toJson
in interface ExecutorService
buffer
- the Json buffer to fill out with the executor service's state.Copyright © 2021 the original authors or authors.