Package com.tagtraum.core.util
Class MultiQueueExecutor
- java.lang.Object
-
- com.tagtraum.core.util.MultiQueueExecutor
-
- All Implemented Interfaces:
Executor
,ExecutorService
public class MultiQueueExecutor extends Object implements ExecutorService
Executor service that allows temporary suspension of execution for a given, task submitting thread. Onceblock()
has been called from a particular thread all following tasks submitted from this thread are queued, untilflush()
is called from that same thread. Some methods are not implemented completely and will throwUnsupportedOperationException
s when called in queue-mode. Queues are not automatically flushed upon termination.- Author:
- Hendrik Schreiber
-
-
Constructor Summary
Constructors Constructor Description MultiQueueExecutor(ExecutorService executorService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
awaitTermination(long timeout, TimeUnit unit)
void
block()
Starts blocking submitted tasks for the current thread.void
block(Thread thread)
Starts blocking submitted tasks for the given thread.void
execute(Runnable command)
void
flush()
Flushes all queued tasks for the current thread.void
flush(Thread thread)
Flushes all queued tasks for the given thread.ExecutorService
getSmuggler()
Returns the inner/wrappedExecutorService
.<T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>> tasks)
<T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
<T> T
invokeAny(Collection<? extends Callable<T>> tasks)
<T> T
invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
boolean
isShutdown()
boolean
isTerminated()
void
shutdown()
List<Runnable>
shutdownNow()
Future<?>
submit(Runnable task)
<T> Future<T>
submit(Runnable task, T result)
<T> Future<T>
submit(Callable<T> task)
-
-
-
Constructor Detail
-
MultiQueueExecutor
public MultiQueueExecutor(ExecutorService executorService)
-
-
Method Detail
-
getSmuggler
public ExecutorService getSmuggler()
Returns the inner/wrappedExecutorService
. Using this service essentially allows smuggling tasks past the queue.- Returns:
- the smuggler service
-
awaitTermination
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
awaitTermination
in interfaceExecutorService
- Throws:
InterruptedException
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfaceExecutorService
-
shutdownNow
public List<Runnable> shutdownNow()
- Specified by:
shutdownNow
in interfaceExecutorService
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdown
in interfaceExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminated
in interfaceExecutorService
-
flush
public void flush()
Flushes all queued tasks for the current thread.- See Also:
flush(Thread)
,block()
-
flush
public void flush(Thread thread)
Flushes all queued tasks for the given thread.- Parameters:
thread
- thread- See Also:
block(Thread)
-
block
public void block()
Starts blocking submitted tasks for the current thread. Is idempotent.
-
block
public void block(Thread thread)
Starts blocking submitted tasks for the given thread. Is idempotent.- Parameters:
thread
- thread- See Also:
flush(Thread)
-
submit
public <T> Future<T> submit(Callable<T> task)
- Specified by:
submit
in interfaceExecutorService
-
submit
public <T> Future<T> submit(Runnable task, T result)
- Specified by:
submit
in interfaceExecutorService
-
submit
public Future<?> submit(Runnable task)
- Specified by:
submit
in interfaceExecutorService
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
- Specified by:
invokeAll
in interfaceExecutorService
- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
invokeAll
in interfaceExecutorService
- Throws:
InterruptedException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException
- Specified by:
invokeAny
in interfaceExecutorService
- Throws:
InterruptedException
ExecutionException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
invokeAny
in interfaceExecutorService
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
-