Class ScheduledObjectOneWorkExecutor<O>
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- de.aristaflow.adept2.util.threading.AFThreadPoolExecutor
-
- de.aristaflow.adept2.util.threading.CachedThreadPoolExecutor
-
- de.aristaflow.adept2.util.threading.executor.AbstractObjectSpecificExecutor<O,O,R>
-
- de.aristaflow.adept2.util.threading.executor.AbstractObjectOneWorkExecutor<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
-
- de.aristaflow.adept2.util.threading.executor.ScheduledObjectOneWorkExecutor<O>
-
- Type Parameters:
O
- The type of object for which work is registered.
- All Implemented Interfaces:
Executor
,ExecutorService
public class ScheduledObjectOneWorkExecutor<O> extends AbstractObjectOneWorkExecutor<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
This scheduled one work executor handles the usual pending work for before and after a flush. Additionally, it allows to add work with a specific delay. Only one piece of work with delay is allowed for each object. If delayed work exists, additional work will be refused, that is, the waiting work is considered as pending work.
To realise the delay, the work will be managed by a scheduled executor. After the delay elapsed, the scheduled executor will not execute the delayed work directly but try to add it for normal execution by the object one work executor. For adding delayed work after the delay elapsed the normal restrictions apply, that is, if there is already pending work, the delayed work will be cancelled. If a flush is pending, the delayed work will be pending for after the flush unless such work already exists.Adding delayed work will not affect existing pending work. When overriding delayed work, only existing delayed work will be overridden. If there is other pending work as soon as overriding delayed work should be executed, the delayed work will be cancelled.
When overriding with immediate work, delayed work will be cancelled. When flushing with abortion, delayed work will be ignored.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ScheduledObjectOneWorkExecutor.ScheduledRuntimeData
This class extendsRuntimeData
by a runnable which will be delayed and the corresponding future stemming from scheduling the runnable in the scheduling executor.-
Nested classes/interfaces inherited from class de.aristaflow.adept2.util.threading.executor.AbstractObjectOneWorkExecutor
AbstractObjectOneWorkExecutor.RuntimeData
-
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
-
-
Field Summary
Fields Modifier and Type Field Description protected ThreadLocal<Queue<Long>>
delays
The delays for scheduled and submitted work.protected ScheduledExecutorService
scheduled
The scheduled executor service executing runnables which add work that should be delayed.-
Fields inherited from class de.aristaflow.adept2.util.threading.executor.AbstractObjectOneWorkExecutor
blockUntilFlush, overridingWork
-
Fields inherited from class de.aristaflow.adept2.util.threading.executor.AbstractObjectSpecificExecutor
abortCount, flushPending, logger, objects, shutdownPending
-
Fields inherited from class de.aristaflow.adept2.util.threading.CachedThreadPoolExecutor
fullSize, realCoreSize, realMaxSize, workSize
-
Fields inherited from class de.aristaflow.adept2.util.threading.AFThreadPoolExecutor
activeThreads, completedTasks, HYSTERESIS, submittedTasks
-
-
Constructor Summary
Constructors Constructor Description ScheduledObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, boolean prestart, int scheduledPoolSize, Adept2ThreadFactory threadFactory)
Deprecated, for removal: This API element is subject to removal in a future version.ScheduledObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, boolean prestart, int scheduledPoolSize, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics)
Deprecated, for removal: This API element is subject to removal in a future version.ScheduledObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, boolean prestart, int scheduledPoolSize, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, Level minLogLevelPoolStatistics)
Deprecated, for removal: This API element is subject to removal in a future version.ScheduledObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, int scheduledPoolSize, Adept2ThreadFactory threadFactory)
Creates a new thread pool executor with the designated (maximum) amount of (core) threads (and unlimited objects), accepting exactly one piece of work per object.ScheduledObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, int scheduledPoolSize, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics)
Creates a new thread pool executor with the designated (maximum) amount of (core) threads, accepting exactly one piece of work per object.ScheduledObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, int scheduledPoolSize, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, Level minLogLevelPoolStatistics)
Creates a new thread pool executor with the designated (maximum) amount of (core) threads, accepting exactly one piece of work per object.ScheduledObjectOneWorkExecutor(boolean blockUntilFlush, int maxPoolSize, Adept2ThreadFactory threadFactory)
Creates a new thread pool executor with an unlimited amount of objects and the designated maximum amount of threads, accepting exactly one piece of work per object.ScheduledObjectOneWorkExecutor(boolean blockUntilFlush, Adept2ThreadFactory threadFactory)
Deprecated, for removal: This API element is subject to removal in a future version.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ScheduledObjectOneWorkExecutor.ScheduledRuntimeData
addDelayedRunnable(O registeredObject, Runnable runnable, long delay)
Creates scheduled runtime data for the designated object having the designated runnable as delayed runnable.protected ScheduledObjectOneWorkExecutor.ScheduledRuntimeData
addDelayedRunnable(O registeredObject, Runnable runnable, long delay, AbstractObjectOneWorkExecutor.RuntimeData rtData)
Creates scheduled runtime data for the designated object having the designated runnable as delayed runnable and the pending runnables from the designated runtime data.protected ScheduledObjectOneWorkExecutor.ScheduledRuntimeData
addNewPendingAfterFlush(ScheduledObjectOneWorkExecutor.ScheduledRuntimeData rtData, Runnable pendingAfterFlush)
Creates runtime data having the same data as the designated runtime data except for the pending after flush which will be the designated runnable.protected ScheduledObjectOneWorkExecutor.ScheduledRuntimeData
addNewPendingBeforeFlush(Runnable pendingBeforeFlush, ScheduledObjectOneWorkExecutor.ScheduledRuntimeData rtData)
Creates runtime data having the same data as the designated runtime data except for the pending before flush which will be the designated runnable.protected ObjectRunnable<O,O>
addRunnable(O registeredObject, O indexObject, Runnable task)
Adds the designated runnable for the designated object and index object to this executor.protected <T> Pair<Future<T>,Map<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>>
cancelAndFlush(boolean shutdownRequest, Map<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData> pending, Callable<T> task, Collection<ObjectRunnable<O,O>> objectRunnables)
Cancels the designated pending work (if appropriate), flushes (i. e. waits for or aborts the designated runnables) and executes the designated task.protected void
clearAbortedPendingWork(boolean shutdownRequest)
Removes all pending work that should be aborted for an aborting flush, that is, it removes the from the data structures, e. g.protected ScheduledObjectOneWorkExecutor.ScheduledRuntimeData
createPendingAfterFlush(Runnable pendingAfterFlush)
Creates runtime data having the designated runnable as pending after flush.protected ScheduledObjectOneWorkExecutor.ScheduledRuntimeData
createPendingBeforeFlush(Runnable pendingBeforeFlush)
Creates runtime data having the designated runnable as pending before flush.protected ScheduledObjectOneWorkRunnable<O>
createScheduledObjectRunnable(O object)
Creates a new object runnable.protected void
enqueueDelayedRunnable(O registeredObject, O indexObject, Pair<ObjectRunnable<O,O>,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData> pair)
Removes the delayed runnable from the designated scheduled runtime data for the designated (registered and index) object and adds it as normal pending work.void
execute(O object, Runnable task)
Executes the designated task for the designated object.void
executeOverride(O object, Runnable task)
Executes the designated task for the designated object and overrides pending work if this exists.<T> Pair<Future<T>,Map<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>>
flushAndExecute(boolean abortPending, Callable<T> task)
Flushes all work and executes the designated task.protected List<Runnable>
getOutstandingRunnables(Map<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData> outstandingWork)
Gets a list of runnables which have not been executed based on the designated outstanding work.protected ScheduledObjectOneWorkExecutor.ScheduledRuntimeData
removePendingBeforeFlush(ScheduledObjectOneWorkExecutor.ScheduledRuntimeData rtData)
Creates runtime data having the same data as the designated runtime data except for the pending before flush which will benull
.Future<?>
schedule(O object, Runnable task, long delay)
Schedules the designated runnable to be executed after the designated delay for the designated object.<V> Future<V>
schedule(O object, Callable<V> task, long delay)
Schedules the designated callable to be executed after the designated delay for the designated object.Future<?>
scheduleOverride(O object, Runnable task, long delay)
Schedules the designated runnable to be executed after the designated delay for the designated object and overrides existing delayed work.<V> Future<V>
scheduleOverride(O object, Callable<V> task, long delay)
Schedules the designated callable to be executed after the designated delay for the designated object and overrides existing delayed work.protected void
shutdownRunnableRun()
This method is therun()
method of the shutdown runnable.Future<?>
submit(O object, Runnable task)
Submits the designated task for the designated object.<T> Future<T>
submit(O object, Callable<T> task)
Submits the designated task for the designated object.<T> Pair<Future<T>,Map<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>>
submitAndFlush(boolean abortPending, Callable<T> task)
Submits the designated task and flushes all work.Future<?>
submitOverride(O object, Runnable task)
Submits the designated task for the designated object and overrides existing pending work.<T> Future<T>
submitOverride(O object, Callable<T> task)
Submits the designated task for the designated object and overrides existing pending work.protected ScheduledObjectOneWorkExecutor.ScheduledRuntimeData
switchPendingAfterFlush(ScheduledObjectOneWorkExecutor.ScheduledRuntimeData rtData)
Creates runtime data having pending before flush taken from pending after flush from the designated runtime and pending after flush beingnull
.-
Methods inherited from class de.aristaflow.adept2.util.threading.executor.AbstractObjectOneWorkExecutor
createObjectOneWorkRunnable, executeShutdown, getIndexObjectFor, restartPendingWork
-
Methods inherited from class de.aristaflow.adept2.util.threading.executor.AbstractObjectSpecificExecutor
flushAndExecuteUnchecked, isShutdown, restart, shutdown, shutdownNow
-
Methods inherited from class de.aristaflow.adept2.util.threading.CachedThreadPoolExecutor
afterExecute, execute
-
Methods inherited from class de.aristaflow.adept2.util.threading.AFThreadPoolExecutor
beforeExecute, logPoolStatistics, newTaskFor, newTaskFor, recalculateLogLimits, setCorePoolSize, setLogExecuteCallStack, setMaximumPoolSize, updateQueueLimit
-
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setKeepAliveTime, setRejectedExecutionHandler, setThreadFactory, terminated, toString
-
-
-
-
Field Detail
-
scheduled
protected final ScheduledExecutorService scheduled
The scheduled executor service executing runnables which add work that should be delayed.
-
delays
protected final ThreadLocal<Queue<Long>> delays
The delays for scheduled and submitted work. This is required since the interface of the superclass does not know the delays and does not have them in the API.
To allow for nested/reentrant submissions and schedules, each call to a schedule or submit method adds a delay to this queue. Submissions without delay use-1
.
-
-
Constructor Detail
-
ScheduledObjectOneWorkExecutor
@Deprecated(since="14.4.0", forRemoval=true) public ScheduledObjectOneWorkExecutor(boolean blockUntilFlush, Adept2ThreadFactory threadFactory)
Deprecated, for removal: This API element is subject to removal in a future version.Creates a new thread pool executor with an unlimited amount of threads and objects, accepting exactly one piece of work per object. It uses the designated thread factory for creating threads. The threads will stay idle for 60 seconds before they terminate. It will also have a scheduled executor service with two threads also using the designated thread factory.- Parameters:
blockUntilFlush
- Whether work should be blocked for each object until the next flush. Otherwise work is allowed as soon as the work of the object has started.threadFactory
- The factory to use when the (scheduled) executor creates a new thread.
-
ScheduledObjectOneWorkExecutor
public ScheduledObjectOneWorkExecutor(boolean blockUntilFlush, int maxPoolSize, Adept2ThreadFactory threadFactory)
Creates a new thread pool executor with an unlimited amount of objects and the designated maximum amount of threads, accepting exactly one piece of work per object. It uses the designated thread factory for creating threads. The threads will stay idle for 60 seconds before they terminate. It will also have a scheduled executor service with two threads also using the designated thread factory.- Parameters:
blockUntilFlush
- Whether work should be blocked for each object until the next flush. Otherwise work is allowed as soon as the work of the object has started.maxPoolSize
- The maximum number of threads allowed in the pool. Set this to the number of objects allowed to be executed concurrently or less.threadFactory
- The factory to use when the (scheduled) executor creates a new thread.
-
ScheduledObjectOneWorkExecutor
public ScheduledObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, int scheduledPoolSize, Adept2ThreadFactory threadFactory)
Creates a new thread pool executor with the designated (maximum) amount of (core) threads (and unlimited objects), accepting exactly one piece of work per object. It uses the designated thread factory for creating threads. The threads will stay idle for 60 seconds before they terminate. It will also have a scheduled executor service with the designated amount of threads and also using the designated thread factory.- Parameters:
blockUntilFlush
- Whether work should be blocked for each object until the next flush. Otherwise work is allowed as soon as the work of the object has started.corePoolSize
- The number of threads to keep in the pool of the executor service all the time, even if they are idle.maxPoolSize
- The maximum number of threads allowed in the pool. Set this to the number of objects allowed to be executed concurrently or less.scheduledPoolSize
- The number of threads to keep in the pool of the separate scheduled executor service, even if they are idle. These threads are not for executing work but for enqueuing delayed work.threadFactory
- The factory to use when the (scheduled) executor creates a new thread.
-
ScheduledObjectOneWorkExecutor
@Deprecated(since="14.4.0", forRemoval=true) public ScheduledObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, boolean prestart, int scheduledPoolSize, Adept2ThreadFactory threadFactory)
Deprecated, for removal: This API element is subject to removal in a future version.Creates a new thread pool executor with the designated (maximum) amount of (core) threads (and unlimited objects), accepting exactly one piece of work per object. It uses the designated thread factory for creating threads. The threads will stay idle for 60 seconds before they terminate. It will also have a scheduled executor service with the designated amount of threads and also using the designated thread factory.- Parameters:
blockUntilFlush
- Whether work should be blocked for each object until the next flush. Otherwise work is allowed as soon as the work of the object has started.corePoolSize
- The number of threads to keep in the pool of the executor service, even if they are idle.maxPoolSize
- The maximum number of threads to allow in the pool of the executor service.prestart
- Whether all core threads in the executor service should be prestarted.scheduledPoolSize
- The number of threads to keep in the pool of the separate scheduled executor service, even if they are idle. These threads are not for executing work but for enqueuing delayed work.threadFactory
- The factory to use when the (scheduled) executor creates a new thread.
-
ScheduledObjectOneWorkExecutor
public ScheduledObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, int scheduledPoolSize, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics)
Creates a new thread pool executor with the designated (maximum) amount of (core) threads, accepting exactly one piece of work per object. The work will be prioritised using the designated comparator, work exceeding the threads will be enqueued. The executor uses the designated thread factory for creating threads. The non-core threads will stay idle for 60 seconds before they terminate. It will also have a scheduled executor service with the designated amount of threads and also using the same thread factory.- Parameters:
blockUntilFlush
- Whether work should be blocked for each object until the next flush. Otherwise work is allowed as soon as the work of the object has started.corePoolSize
- The number of threads to keep in the (object work) pool all the time, even if they are idle.maxPoolSize
- The maximum number of threads allowed in the (object work) pool. Set this to the number of objects allowed to be executed concurrently or less.scheduledPoolSize
- The number of threads to keep in the pool of the separate scheduled executor service, even if they are idle. These threads are not for executing work but for enqueuing delayed work.comparator
- The comparator used to determine the priority of work.threadFactory
- The factory to use when the executor creates a new thread. Also the logger from this thread factory will be used by this executor.queueLimitPoolStatistics
- The amount of tasks in the queue before warnings will be logged. Use-1
to use the default limits.minLogLevelPoolStatistics
- The log level which need to be reached for logging pool statistics. Pool statistics logs with a lower log level will be ignored.
-
ScheduledObjectOneWorkExecutor
@Deprecated(since="14.4.0", forRemoval=true) public ScheduledObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, boolean prestart, int scheduledPoolSize, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics)
Deprecated, for removal: This API element is subject to removal in a future version.Creates a new thread pool executor with the designated (maximum) amount of (core) threads, accepting exactly one piece of work per object. The work will be prioritised using the designated comparator, work exceeding the threads will be enqueued. The executor uses the designated thread factory for creating threads. The non-core threads will stay idle for 60 seconds before they terminate. It will also have a scheduled executor service with the designated amount of threads and also using the same thread factory.- Parameters:
blockUntilFlush
- Whether work should be blocked for each object until the next flush. Otherwise work is allowed as soon as the work of the object has started.corePoolSize
- The number of threads to keep in the (object work) pool, even if they are idle.maxPoolSize
- The maximum number of threads to allow in the (object work) pool.prestart
- Whether all core threads should be prestarted.scheduledPoolSize
- The number of threads to keep in the pool of the separate scheduled executor service, even if they are idle. These threads are not for executing work but for enqueuing delayed work.comparator
- The comparator used to determine the priority of work.threadFactory
- The factory to use when the executor creates a new thread. Also the logger from this thread factory will be used by this executor.queueLimitPoolStatistics
- The amount of tasks in the queue before warnings will be logged. Use-1
to use the default limits.minLogLevelPoolStatistics
- The log level which need to be reached for logging pool statistics. Pool statistics logs with a lower log level will be ignored.
-
ScheduledObjectOneWorkExecutor
public ScheduledObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, int scheduledPoolSize, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, Level minLogLevelPoolStatistics)
Creates a new thread pool executor with the designated (maximum) amount of (core) threads, accepting exactly one piece of work per object. The work will be prioritised using the designated comparator, work exceeding the threads will be enqueued. The executor uses the designated thread factory for creating threads. The non-core threads will stay idle for 60 seconds before they terminate. It will also have a scheduled executor service with the designated amount of threads and also using the same thread factory.- Parameters:
blockUntilFlush
- Whether work should be blocked for each object until the next flush. Otherwise work is allowed as soon as the work of the object has started.corePoolSize
- The number of threads to keep in the (object work) pool all the time, even if they are idle.maxPoolSize
- The maximum number of threads allowed in the (object work) pool. Set this to the number of objects allowed to be executed concurrently or less.scheduledPoolSize
- The number of threads to keep in the pool of the separate scheduled executor service, even if they are idle. These threads are not for executing work but for enqueuing delayed work.comparator
- The comparator used to determine the priority of work.threadFactory
- The factory to use when the executor creates a new thread. Also the logger from this thread factory will be used by this executor.minLogLevelPoolStatistics
- The log level which need to be reached for logging pool statistics. Pool statistics logs with a lower log level will be ignored.
-
ScheduledObjectOneWorkExecutor
@Deprecated(since="14.4.0", forRemoval=true) public ScheduledObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, boolean prestart, int scheduledPoolSize, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, Level minLogLevelPoolStatistics)
Deprecated, for removal: This API element is subject to removal in a future version.Creates a new thread pool executor with the designated (maximum) amount of (core) threads, accepting exactly one piece of work per object. The work will be prioritised using the designated comparator, work exceeding the threads will be enqueued. The executor uses the designated thread factory for creating threads. The non-core threads will stay idle for 60 seconds before they terminate. It will also have a scheduled executor service with the designated amount of threads and also using the same thread factory.- Parameters:
blockUntilFlush
- Whether work should be blocked for each object until the next flush. Otherwise work is allowed as soon as the work of the object has started.corePoolSize
- The number of threads to keep in the (object work) pool, even if they are idle.maxPoolSize
- The maximum number of threads to allow in the (object work) pool.prestart
- Whether all core threads should be prestarted.scheduledPoolSize
- The number of threads to keep in the pool of the separate scheduled executor service, even if they are idle. These threads are not for executing work but for enqueuing delayed work.comparator
- The comparator used to determine the priority of work.threadFactory
- The factory to use when the executor creates a new thread. Also the logger from this thread factory will be used by this executor.minLogLevelPoolStatistics
- The log level which need to be reached for logging pool statistics. Pool statistics logs with a lower log level will be ignored.
-
-
Method Detail
-
execute
public void execute(O object, Runnable task)
Description copied from class:AbstractObjectSpecificExecutor
Executes the designated task for the designated object. This just creates the index object, adds the runnable and executes it if not terminated or waiting for a flush.
How the runnable and the objects are handled depends on the actual implementation.- Overrides:
execute
in classAbstractObjectSpecificExecutor<O,O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
object
- The object for which to execute the designated task.task
- The task which to execute.- See Also:
CachedThreadPoolExecutor.execute(Runnable)
-
flushAndExecute
public <T> Pair<Future<T>,Map<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>> flushAndExecute(boolean abortPending, Callable<T> task)
Description copied from class:AbstractObjectSpecificExecutor
Flushes all work and executes the designated task. When aborting, all registered work will be removed and returned. Otherwisenull
will be returned and the object work will restart after the designated task has been executed.
This method can be called concurrently. It is ensured that all concurrent flushs will be executed before the object work will restart. The tasks of concurrent flushs will be executed concurrently!- Overrides:
flushAndExecute
in classAbstractObjectSpecificExecutor<O,O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
abortPending
- Whether the present work should be cancelled. In this case the corresponding runtime data will be returned.task
- The task which to execute without any object work running.- Returns:
- A pair containing the future representing the designated task and as second element
either
null
in case no abortion is requested otherwise the managed objects and the runtime data of the aborted work.
-
submit
public Future<?> submit(O object, Runnable task)
Description copied from class:AbstractObjectSpecificExecutor
Submits the designated task for the designated object.- Overrides:
submit
in classAbstractObjectSpecificExecutor<O,O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
object
- The object for which to execute the designated task.task
- The task which to execute.- Returns:
- A
Future
representing pending completion of the task - See Also:
AbstractExecutorService.submit(Runnable)
-
submit
public <T> Future<T> submit(O object, Callable<T> task)
Description copied from class:AbstractObjectSpecificExecutor
Submits the designated task for the designated object.- Overrides:
submit
in classAbstractObjectSpecificExecutor<O,O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
object
- The object for which to execute the designated task.task
- The task which to execute.- Returns:
- A
Future
representing pending completion of the task - See Also:
AbstractExecutorService.submit(Callable)
-
submitAndFlush
public <T> Pair<Future<T>,Map<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>> submitAndFlush(boolean abortPending, Callable<T> task)
Description copied from class:AbstractObjectSpecificExecutor
Submits the designated task and flushes all work. When aborting, all registered work will be removed and returned. Otherwisenull
will be returned and the work will restart after the designated task has been executed.
This method can be called concurrently. It is ensured that all concurrent flushs will be executed before the work will restart. The tasks of concurrent flushs will be executed concurrently!- Overrides:
submitAndFlush
in classAbstractObjectSpecificExecutor<O,O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
abortPending
- Whether the present work should be cancelled. In this case the corresponding runnables will be returned.task
- The task which to execute without any object work running.- Returns:
- A pair containing the future representing the designated task and as second element
either
null
in case no abortion is requested otherwise the managed objects and the runtime data of the aborted work. - See Also:
AbstractObjectSpecificExecutor.flushAndExecute(boolean, Callable)
-
executeOverride
public void executeOverride(O object, Runnable task)
Description copied from class:AbstractObjectOneWorkExecutor
Executes the designated task for the designated object and overrides pending work if this exists.- Overrides:
executeOverride
in classAbstractObjectOneWorkExecutor<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
object
- The object for which to execute the designated task.task
- The task which to execute.- See Also:
AbstractObjectSpecificExecutor.execute(Object, Runnable)
-
submitOverride
public Future<?> submitOverride(O object, Runnable task)
Description copied from class:AbstractObjectOneWorkExecutor
Submits the designated task for the designated object and overrides existing pending work.- Overrides:
submitOverride
in classAbstractObjectOneWorkExecutor<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
object
- The object for which to execute the designated task.task
- The task which to execute.- Returns:
- A
Future
representing pending completion of the task - See Also:
AbstractObjectSpecificExecutor.submit(Object, Runnable)
-
submitOverride
public <T> Future<T> submitOverride(O object, Callable<T> task)
Description copied from class:AbstractObjectOneWorkExecutor
Submits the designated task for the designated object and overrides existing pending work.- Overrides:
submitOverride
in classAbstractObjectOneWorkExecutor<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
object
- The object for which to execute the designated task.task
- The task which to execute.- Returns:
- A
Future
representing pending completion of the task - See Also:
AbstractObjectSpecificExecutor.submit(Object, Callable)
-
schedule
public Future<?> schedule(O object, Runnable task, long delay)
Schedules the designated runnable to be executed after the designated delay for the designated object. After the designated delay, the work will be addedAbstractExecutorService.submit(Runnable)
normally. The returned future belongs to the delayed execution not the scheduling.- Parameters:
object
- The object for which to execute the designated delayed task.task
- The task which to execute after the designated delay.delay
- The delay in milliseconds before to submit the designated task for execution.- Returns:
- A
Future
representing pending completion of the delayed task. - Throws:
RejectedExecutionException
- if the executor has been shut down, aRejectedExecutionException
will be thrown.- See Also:
AbstractExecutorService.submit(Runnable)
,ScheduledExecutorService.schedule(Runnable, long, TimeUnit)
-
scheduleOverride
public Future<?> scheduleOverride(O object, Runnable task, long delay)
Schedules the designated runnable to be executed after the designated delay for the designated object and overrides existing delayed work. After the designated delay, the work will be addedAbstractExecutorService.submit(Runnable)
normally. The returned future belongs to the delayed execution not the scheduling.- Parameters:
object
- The object for which to execute the designated delayed task.task
- The task which to execute after the designated delay.delay
- The delay in milliseconds before to submit the designated task for execution.- Returns:
- A
Future
representing pending completion of the delayed task. - Throws:
RejectedExecutionException
- if the executor has been shut down, aRejectedExecutionException
will be thrown.- See Also:
submitOverride(Object, Runnable)
,ScheduledExecutorService.schedule(Runnable, long, TimeUnit)
-
schedule
public <V> Future<V> schedule(O object, Callable<V> task, long delay)
Schedules the designated callable to be executed after the designated delay for the designated object. After the designated delay, the work will be addedAbstractExecutorService.submit(Callable)
normally. The returned future belongs to the delayed execution not the scheduling.- Parameters:
object
- The object for which to execute the designated delayed task.task
- The task which to execute after the designated delay.delay
- The delay in milliseconds before to submit the designated task for execution.- Returns:
- A
Future
representing pending completion of the delayed task. - Throws:
RejectedExecutionException
- if the executor has been shut down, aRejectedExecutionException
will be thrown.- See Also:
AbstractExecutorService.submit(Callable)
,ScheduledExecutorService.schedule(Callable, long, TimeUnit)
-
scheduleOverride
public <V> Future<V> scheduleOverride(O object, Callable<V> task, long delay)
Schedules the designated callable to be executed after the designated delay for the designated object and overrides existing delayed work. After the designated delay, the work will be addedAbstractExecutorService.submit(Callable)
normally. The returned future belongs to the delayed execution not the scheduling.- Parameters:
object
- The object for which to execute the designated delayed task.task
- The task which to execute after the designated delay.delay
- The delay in milliseconds before to submit the designated task for execution.- Returns:
- A
Future
representing pending completion of the delayed task. - Throws:
RejectedExecutionException
- if the executor has been shut down, aRejectedExecutionException
will be thrown.- See Also:
submitOverride(Object, Callable)
,ScheduledExecutorService.schedule(Callable, long, TimeUnit)
-
enqueueDelayedRunnable
protected void enqueueDelayedRunnable(O registeredObject, O indexObject, Pair<ObjectRunnable<O,O>,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData> pair)
Removes the delayed runnable from the designated scheduled runtime data for the designated (registered and index) object and adds it as normal pending work. This may also create the appropriateObjectRunnable
and adds it to the executor.- Parameters:
registeredObject
- The object the delayed runnable has been registered for.indexObject
- The index object of the delayed runnable.pair
- The pair ofObjectRunnable
and runtime data for the designated object.
-
addRunnable
protected ObjectRunnable<O,O> addRunnable(O registeredObject, O indexObject, Runnable task)
Description copied from class:AbstractObjectSpecificExecutor
Adds the designated runnable for the designated object and index object to this executor.
Implementations may store the work internally for later execution or assign it to an already existing active element (usually a thread). If they need a new active element for the designated runnable, they have to return a new runnable which will then be added to this executor using the normalCachedThreadPoolExecutor.execute(Runnable)
. If they returnnull
, they have to assign the runnable to an active element eventually and arbitrarily.The caller has the lock on
objects
.- Overrides:
addRunnable
in classAbstractObjectOneWorkExecutor<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
registeredObject
- The object for which this runnable has been registered.indexObject
- The object with which this runnable is managed and executed within the corresponding object-specific executor service.task
- The task which to execute.- Returns:
- A runnable which to add to the executor so that this gets a new active element
(thread). This will be handled via
CachedThreadPoolExecutor.execute(Runnable)
, which means the runnable will be executed independently from other work and a new thread may be started for it.
-
clearAbortedPendingWork
protected void clearAbortedPendingWork(boolean shutdownRequest)
Removes all pending work that should be aborted for an aborting flush, that is, it removes the from the data structures, e. g.objects
. This method only affects data structures, it does not affect any executed work. The caller will take care of this shortly.The caller has the lock on
objects
. Only removes the entries which do not have work pending for after a flush in case this is no shutdown request. Otherwise all objects and all work will be removed. Only removes the entries which do not have a delayed runnable in case this is no shutdown request. Otherwise all objects and all work will be removed.- Overrides:
clearAbortedPendingWork
in classAbstractObjectOneWorkExecutor<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
shutdownRequest
- Whether this flush is caused by aAbstractObjectSpecificExecutor.shutdownNow()
. In this case all work has to be aborted, even the work pending after a flush.
-
cancelAndFlush
protected <T> Pair<Future<T>,Map<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>> cancelAndFlush(boolean shutdownRequest, Map<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData> pending, Callable<T> task, Collection<ObjectRunnable<O,O>> objectRunnables)
Description copied from class:AbstractObjectSpecificExecutor
Cancels the designated pending work (if appropriate), flushes (i. e. waits for or aborts the designated runnables) and executes the designated task.The caller has the lock on
objects
.- Overrides:
cancelAndFlush
in classAbstractObjectOneWorkExecutor<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
shutdownRequest
- Whether this flush is caused by aAbstractObjectSpecificExecutor.shutdownNow()
. In this case all work has to be aborted, even the work pending after a flush.pending
- The pending work that will not be executed due to abort ornull
if running work should not be aborted.task
- The task which to execute without any object work running.objectRunnables
- The currently running work. This will either be aborted or awaited for flushing.- Returns:
- A pair containing the future representing the designated task and as second element
either
null
in case no abortion is requested otherwise the managed objects and the runtime data of the aborted work. Note that the runtime data may contain work that is not cancelled by the flush. This depends on the runtime data.
-
shutdownRunnableRun
protected void shutdownRunnableRun()
Description copied from class:AbstractObjectSpecificExecutor
This method is therun()
method of the shutdown runnable. It shuts down this executor. Subclasses may override it for additional shutdown behaviour.- Overrides:
shutdownRunnableRun
in classAbstractObjectSpecificExecutor<O,O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
-
getOutstandingRunnables
protected List<Runnable> getOutstandingRunnables(Map<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData> outstandingWork)
Description copied from class:AbstractObjectSpecificExecutor
Gets a list of runnables which have not been executed based on the designated outstanding work.
This method will be called after an immediate shutdown which aborts pending work. Depending on the implementation, the designated runtime data may contain runnables which have not been executed and should therefore be returned to conform to the interface of an executor service.
The caller does not have the lock onobjects
.- Overrides:
getOutstandingRunnables
in classAbstractObjectOneWorkExecutor<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
outstandingWork
- The pending work that has been aborted due to the immediate shutdown.- Returns:
- A list of runnables stemming from the designated outstanding work.
-
createPendingBeforeFlush
protected ScheduledObjectOneWorkExecutor.ScheduledRuntimeData createPendingBeforeFlush(Runnable pendingBeforeFlush)
Description copied from class:AbstractObjectOneWorkExecutor
Creates runtime data having the designated runnable as pending before flush.- Specified by:
createPendingBeforeFlush
in classAbstractObjectOneWorkExecutor<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
pendingBeforeFlush
- The runnable which to have as pending before flush.- Returns:
- Newly created runtime data having the designated runnable as pending before flush.
-
createPendingAfterFlush
protected ScheduledObjectOneWorkExecutor.ScheduledRuntimeData createPendingAfterFlush(Runnable pendingAfterFlush)
Description copied from class:AbstractObjectOneWorkExecutor
Creates runtime data having the designated runnable as pending after flush.- Specified by:
createPendingAfterFlush
in classAbstractObjectOneWorkExecutor<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
pendingAfterFlush
- The runnable which to have as pending after flush.- Returns:
- Newly created runtime data having the designated runnable as pending after flush.
-
addNewPendingBeforeFlush
protected ScheduledObjectOneWorkExecutor.ScheduledRuntimeData addNewPendingBeforeFlush(Runnable pendingBeforeFlush, ScheduledObjectOneWorkExecutor.ScheduledRuntimeData rtData)
Description copied from class:AbstractObjectOneWorkExecutor
Creates runtime data having the same data as the designated runtime data except for the pending before flush which will be the designated runnable.- Specified by:
addNewPendingBeforeFlush
in classAbstractObjectOneWorkExecutor<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
pendingBeforeFlush
- The runnable which to have as pending before flush.rtData
- The runtime data from which to take over most of the data.- Returns:
- Runtime data having the same data as the designated runtime data except for the pending before flush which will be the designated runnable.
-
addNewPendingAfterFlush
protected ScheduledObjectOneWorkExecutor.ScheduledRuntimeData addNewPendingAfterFlush(ScheduledObjectOneWorkExecutor.ScheduledRuntimeData rtData, Runnable pendingAfterFlush)
Description copied from class:AbstractObjectOneWorkExecutor
Creates runtime data having the same data as the designated runtime data except for the pending after flush which will be the designated runnable.- Specified by:
addNewPendingAfterFlush
in classAbstractObjectOneWorkExecutor<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
rtData
- The runtime data from which to take over most of the data.pendingAfterFlush
- The runnable which to have as pending after flush.- Returns:
- Runtime data having the same data as the designated runtime data except for the pending after flush which will be the designated runnable.
-
addDelayedRunnable
protected ScheduledObjectOneWorkExecutor.ScheduledRuntimeData addDelayedRunnable(O registeredObject, Runnable runnable, long delay)
Creates scheduled runtime data for the designated object having the designated runnable as delayed runnable. This also adds the runnable to the scheduled executor.- Parameters:
registeredObject
- The object for which to add delayed work.runnable
- The work which to add for the designated object with the designated delay.delay
- The delay in milliseconds before to run the designated work.- Returns:
- Newly created scheduled runtime data having just the designated runnable as delayed runnable.
-
addDelayedRunnable
protected ScheduledObjectOneWorkExecutor.ScheduledRuntimeData addDelayedRunnable(O registeredObject, Runnable runnable, long delay, AbstractObjectOneWorkExecutor.RuntimeData rtData)
Creates scheduled runtime data for the designated object having the designated runnable as delayed runnable and the pending runnables from the designated runtime data. This also adds the runnable to the scheduled executor.- Parameters:
registeredObject
- The object for which to add delayed work.runnable
- The work which to add for the designated object with the designated delay.delay
- The delay in milliseconds before to run the designated work.rtData
- The runtime data providing the pending runnables for the returned scheduled runtime data.- Returns:
- Scheduled runtime data having the designated runnable as delayed runnable and the pending runnables from the designated runtime data.
-
createScheduledObjectRunnable
protected ScheduledObjectOneWorkRunnable<O> createScheduledObjectRunnable(O object)
Creates a new object runnable. This method allows subclasses to create more specific runnables.- Parameters:
object
- The object for which to create a runnable.- Returns:
- A new runnable for the designated object.
-
removePendingBeforeFlush
protected ScheduledObjectOneWorkExecutor.ScheduledRuntimeData removePendingBeforeFlush(ScheduledObjectOneWorkExecutor.ScheduledRuntimeData rtData)
Description copied from class:AbstractObjectOneWorkExecutor
Creates runtime data having the same data as the designated runtime data except for the pending before flush which will benull
.- Specified by:
removePendingBeforeFlush
in classAbstractObjectOneWorkExecutor<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
rtData
- The runtime data from which to take over most of the data.- Returns:
- Runtime data having the same data as the designated runtime data except for the pending
before flush which will be
null
.
-
switchPendingAfterFlush
protected ScheduledObjectOneWorkExecutor.ScheduledRuntimeData switchPendingAfterFlush(ScheduledObjectOneWorkExecutor.ScheduledRuntimeData rtData)
Description copied from class:AbstractObjectOneWorkExecutor
Creates runtime data having pending before flush taken from pending after flush from the designated runtime and pending after flush beingnull
.
This has to be called when restarting after a flush.- Specified by:
switchPendingAfterFlush
in classAbstractObjectOneWorkExecutor<O,ScheduledObjectOneWorkExecutor.ScheduledRuntimeData>
- Parameters:
rtData
- The runtime data from which to take over the data.- Returns:
- Runtime data having pending before flush taken from pending after flush from the
designated runtime and pending after flush being
null
.
-
-