Class AbstractObjectOneWorkExecutor<O,R extends AbstractObjectOneWorkExecutor.RuntimeData>
- 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,R>
-
- Type Parameters:
O
- The type of object for which work is registered.R
- The runtime data stored for each object.
- All Implemented Interfaces:
Executor
,ExecutorService
- Direct Known Subclasses:
ObjectOneWorkExecutor
,ScheduledObjectOneWorkExecutor
public abstract class AbstractObjectOneWorkExecutor<O,R extends AbstractObjectOneWorkExecutor.RuntimeData> extends AbstractObjectSpecificExecutor<O,O,R>
A one work executor allows for an arbitrary amount of objects having work, but only one piece of work is allowed for each object at a time. If work is added for an object that has pending work, the new work will be silently ignored and cancelled immediately. Instead of the completion of previous work this can also last until the next flush.
It is also possible to add new work that overrides (and cancel) previous pending work. This will not override running work.As object-specific executor, the indexed objects are the same as the registered objects. The runtime data is an own class
AbstractObjectOneWorkExecutor.RuntimeData
which is a pair of runnables that are registered for the corresponding object. The first runnable is the one pending to be executed after the current work but before a flush. This work will be cancelled if flushing is with abortion. It will benull
if there is no more work or if the work should block until the next flush. The second runnable is work which is added while a flush is pending. This is executed right after all pending flushs have been executed.
To prevent starvation, each piece of work will be executed by an arbitrary thread; work for the same object will only be executed by the same thread when shutting down.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractObjectOneWorkExecutor.RuntimeData
This class represents runtime data for an one work executor.-
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 boolean
blockUntilFlush
Whether work should be blocked for each object until the next flush.protected Collection<Thread>
overridingWork
The threads that are currently submitting or executing a piece of work that should override existing (pending) work.-
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 Modifier Constructor Description protected
AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, boolean prestart, Adept2ThreadFactory threadFactory)
Deprecated, for removal: This API element is subject to removal in a future version.protected
AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, boolean prestart, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics)
Deprecated, for removal: This API element is subject to removal in a future version.protected
AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, boolean prestart, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics)
Deprecated, for removal: This API element is subject to removal in a future version.protected
AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, boolean prestart, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, Level minLogLevelPoolStatistics)
Deprecated, for removal: This API element is subject to removal in a future version.protected
AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, 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.protected
AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics)
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.protected
AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, 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.protected
AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, 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.protected
AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int maxPoolSize, Adept2ThreadFactory threadFactory)
Creates a new thread pool executor with an unlimited amount objects and the designated maximum amount of threads, accepting exactly one piece of work per object.protected
AbstractObjectOneWorkExecutor(boolean blockUntilFlush, Adept2ThreadFactory threadFactory)
Deprecated, for removal: This API element is subject to removal in a future version.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract R
addNewPendingAfterFlush(R 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 abstract R
addNewPendingBeforeFlush(Runnable pendingBeforeFlush, R 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,R>>
cancelAndFlush(boolean shutdownRequest, Map<O,R> 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 ObjectOneWorkRunnable<O,R>
createObjectOneWorkRunnable(O object)
Creates a new object runnable.protected abstract R
createPendingAfterFlush(Runnable pendingAfterFlush)
Creates runtime data having the designated runnable as pending after flush.protected abstract R
createPendingBeforeFlush(Runnable pendingBeforeFlush)
Creates runtime data having the designated runnable as pending before flush.void
executeOverride(O object, Runnable task)
Executes the designated task for the designated object and overrides pending work if this exists.protected void
executeShutdown(Runnable shutdown)
Executes the designated shutdown task which contains a flush callingThreadPoolExecutor.shutdown()
without abortion.protected O
getIndexObjectFor(O object)
Gets the object used for managing and executing runnables within this executor.protected List<Runnable>
getOutstandingRunnables(Map<O,R> outstandingWork)
Gets a list of runnables which have not been executed based on the designated outstanding work.protected abstract R
removePendingBeforeFlush(R rtData)
Creates runtime data having the same data as the designated runtime data except for the pending before flush which will benull
.protected void
restartPendingWork()
Checks for whether there is work pending for after a restart.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 abstract R
switchPendingAfterFlush(R 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.AbstractObjectSpecificExecutor
execute, flushAndExecute, flushAndExecuteUnchecked, isShutdown, restart, shutdown, shutdownNow, shutdownRunnableRun, submit, submit, submitAndFlush
-
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
-
blockUntilFlush
protected final boolean 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.
-
overridingWork
protected final Collection<Thread> overridingWork
The threads that are currently submitting or executing a piece of work that should override existing (pending) work. Overriding needs to be considered withinaddRunnable(Object, Object, Runnable)
, using this collection avoids the need for an additional method parameter (which would require an ugly interface change).
-
-
Constructor Detail
-
AbstractObjectOneWorkExecutor
@Deprecated(since="14.4.0", forRemoval=true) protected AbstractObjectOneWorkExecutor(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.- 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 executor creates a new thread.
-
AbstractObjectOneWorkExecutor
protected AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int maxPoolSize, Adept2ThreadFactory threadFactory)
Creates a new thread pool executor with an unlimited amount 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.- 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 executor creates a new thread.
-
AbstractObjectOneWorkExecutor
protected AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, 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.- 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 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.threadFactory
- The factory to use when the executor creates a new thread.
-
AbstractObjectOneWorkExecutor
@Deprecated(since="14.4.0", forRemoval=true) protected AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, boolean prestart, 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.- 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, even if they are idle.maxPoolSize
- The maximum number of threads to allow in the pool.prestart
- Whether all core threads should be prestarted.threadFactory
- The factory to use when the executor creates a new thread.
-
AbstractObjectOneWorkExecutor
protected AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics)
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.- 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 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.threadFactory
- The factory to use when the executor creates a new thread.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.
-
AbstractObjectOneWorkExecutor
@Deprecated(since="14.4.0", forRemoval=true) protected AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, boolean prestart, 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 (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.- 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, even if they are idle.maxPoolSize
- The maximum number of threads to allow in the pool.prestart
- Whether all core threads should be prestarted.threadFactory
- The factory to use when the executor creates a new thread.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.
-
AbstractObjectOneWorkExecutor
protected AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, 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 maximum pool size 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.- 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 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.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.
-
AbstractObjectOneWorkExecutor
@Deprecated(since="14.4.0", forRemoval=true) protected AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, boolean prestart, 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 maximum pool size 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.- 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, even if they are idle.maxPoolSize
- The maximum number of threads to allow in the pool.prestart
- Whether all core threads should be prestarted.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.
-
AbstractObjectOneWorkExecutor
protected AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, 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 maximum pool size 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.- 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 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.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.
-
AbstractObjectOneWorkExecutor
@Deprecated(since="14.4.0", forRemoval=true) protected AbstractObjectOneWorkExecutor(boolean blockUntilFlush, int corePoolSize, int maxPoolSize, boolean prestart, 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 maximum pool size 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.- 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, even if they are idle.maxPoolSize
- The maximum number of threads to allow in the pool.prestart
- Whether all core threads should be prestarted.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.
-
-
Method Detail
-
executeOverride
public void executeOverride(O object, Runnable task)
Executes the designated task for the designated object and overrides pending work if this exists.- Parameters:
object
- The object for which to execute the designated task.task
- The task which to execute.- Throws:
RejectedExecutionException
- if the executor has been shut down, aRejectedExecutionException
will be thrown.- See Also:
AbstractObjectSpecificExecutor.execute(Object, Runnable)
-
submitOverride
public Future<?> submitOverride(O object, Runnable task)
Submits the designated task for the designated object and overrides existing pending work.- 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 - Throws:
RejectedExecutionException
- if the executor has been shut down, aRejectedExecutionException
will be thrown.- See Also:
AbstractObjectSpecificExecutor.submit(Object, Runnable)
-
submitOverride
public <T> Future<T> submitOverride(O object, Callable<T> task)
Submits the designated task for the designated object and overrides existing pending work.- 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 - Throws:
RejectedExecutionException
- if the executor has been shut down, aRejectedExecutionException
will be thrown.- See Also:
AbstractObjectSpecificExecutor.submit(Object, Callable)
-
getIndexObjectFor
protected O getIndexObjectFor(O object)
Description copied from class:AbstractObjectSpecificExecutor
Gets the object used for managing and executing runnables within this executor.- Specified by:
getIndexObjectFor
in classAbstractObjectSpecificExecutor<O,O,R extends AbstractObjectOneWorkExecutor.RuntimeData>
- Parameters:
object
- The object for which a runnable is registered.- Returns:
- The object used for managing and executing runnables (registered for the designated object) within this executor.
-
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
.- Specified by:
addRunnable
in classAbstractObjectSpecificExecutor<O,O,R extends AbstractObjectOneWorkExecutor.RuntimeData>
- 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.- Specified by:
clearAbortedPendingWork
in classAbstractObjectSpecificExecutor<O,O,R extends AbstractObjectOneWorkExecutor.RuntimeData>
- 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,R>> cancelAndFlush(boolean shutdownRequest, Map<O,R> 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
.- Specified by:
cancelAndFlush
in classAbstractObjectSpecificExecutor<O,O,R extends AbstractObjectOneWorkExecutor.RuntimeData>
- 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.
-
restartPendingWork
protected void restartPendingWork()
Checks for whether there is work pending for after a restart. If so, makes this the current work and creates a newObjectRunnable
for executing this pending work.- Overrides:
restartPendingWork
in classAbstractObjectSpecificExecutor<O,O,R extends AbstractObjectOneWorkExecutor.RuntimeData>
-
executeShutdown
protected void executeShutdown(Runnable shutdown)
Description copied from class:AbstractObjectSpecificExecutor
Executes the designated shutdown task which contains a flush callingThreadPoolExecutor.shutdown()
without abortion.
This method is only called if there is pending work. So the implementation may decide on how and when to execute the shutdown runnable.The caller has the lock on
objects
.- Specified by:
executeShutdown
in classAbstractObjectSpecificExecutor<O,O,R extends AbstractObjectOneWorkExecutor.RuntimeData>
- Parameters:
shutdown
- The task which to perform to shutdown.
-
getOutstandingRunnables
protected List<Runnable> getOutstandingRunnables(Map<O,R> 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
.- Specified by:
getOutstandingRunnables
in classAbstractObjectSpecificExecutor<O,O,R extends AbstractObjectOneWorkExecutor.RuntimeData>
- 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.
-
createObjectOneWorkRunnable
protected ObjectOneWorkRunnable<O,R> createObjectOneWorkRunnable(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.
-
createPendingBeforeFlush
protected abstract R createPendingBeforeFlush(Runnable pendingBeforeFlush)
Creates runtime data having the designated runnable as pending before flush.- 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 abstract R createPendingAfterFlush(Runnable pendingAfterFlush)
Creates runtime data having the designated runnable as pending after flush.- 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 abstract R addNewPendingBeforeFlush(Runnable pendingBeforeFlush, R 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.- 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 abstract R addNewPendingAfterFlush(R 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.- Parameters:
pendingAfterFlush
- The runnable which to have as pending after 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 after flush which will be the designated runnable.
-
removePendingBeforeFlush
protected abstract R removePendingBeforeFlush(R rtData)
Creates runtime data having the same data as the designated runtime data except for the pending before flush which will benull
.- 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 abstract R switchPendingAfterFlush(R rtData)
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.- 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
.
-
-