Package org.apache.cassandra.concurrent
Class WrappedExecutorPlus
- java.lang.Object
-
- org.apache.cassandra.concurrent.WrappedExecutorPlus
-
- All Implemented Interfaces:
java.util.concurrent.Executor
,java.util.concurrent.ExecutorService
,ExecutorPlus
,ResizableThreadPool
- Direct Known Subclasses:
CompactionManager.ValidationExecutor
public class WrappedExecutorPlus extends java.lang.Object implements ExecutorPlus
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.cassandra.concurrent.ExecutorPlus
ExecutorPlus.MaximumPoolSizeListener
-
-
Field Summary
Fields Modifier and Type Field Description protected ExecutorPlus
executor
-
Constructor Summary
Constructors Constructor Description WrappedExecutorPlus(ExecutorPlus executor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
awaitTermination(long timeout, java.util.concurrent.TimeUnit unit)
void
execute(java.lang.Runnable task)
void
execute(WithResources withResources, java.lang.Runnable task)
Invoketask
.int
getActiveTaskCount()
Returns the approximate number of threads that are actively executing tasks.long
getCompletedTaskCount()
Returns the approximate total number of tasks that have completed execution.int
getCorePoolSize()
Returns core pool size of thread pool, the minimum number of workers (where that makes sense for a thread pool, SEPExecutor does not have a minimum size).int
getMaximumPoolSize()
Returns maximum pool size of thread pool.int
getMaxTasksQueued()
int
getPendingTaskCount()
Returns the approximate total of tasks waiting to be executed.boolean
inExecutor()
<T> java.util.List<java.util.concurrent.Future<T>>
invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
<T> java.util.List<java.util.concurrent.Future<T>>
invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit)
<T> T
invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
<T> T
invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit)
boolean
isShutdown()
boolean
isTerminated()
void
maybeExecuteImmediately(java.lang.Runnable task)
MAY executetask
immediately, if the calling thread is permitted to do so.void
setCorePoolSize(int newCorePoolSize)
Allows user to resize minimum size of the thread pool.void
setMaximumPoolSize(int newMaximumPoolSize)
Allows user to resize maximum size of the thread pool.void
shutdown()
java.util.List<java.lang.Runnable>
shutdownNow()
Future<?>
submit(java.lang.Runnable task)
OverridesExecutorService.submit(Runnable)
to return a CassandraFuture
<T> Future<T>
submit(java.lang.Runnable task, T result)
OverridesExecutorService.submit(Runnable, Object)
to return a CassandraFuture
<T> Future<T>
submit(java.util.concurrent.Callable<T> task)
OverridesExecutorService.submit(Callable)
to return a CassandraFuture
Future<?>
submit(WithResources withResources, java.lang.Runnable task)
Invoketask
, returning a future yieldingnull
if successful, or the abnormal termination oftask
otherwise.<T> Future<T>
submit(WithResources withResources, java.lang.Runnable task, T result)
Invoketask
, returning a future yieldingresult
if successful, or the abnormal termination oftask
otherwise.<T> Future<T>
submit(WithResources withResources, java.util.concurrent.Callable<T> task)
Invoketask
, returning a future representing this computation.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.concurrent.ResizableThreadPool
oldestTaskQueueTime
-
-
-
-
Field Detail
-
executor
protected final ExecutorPlus executor
-
-
Constructor Detail
-
WrappedExecutorPlus
public WrappedExecutorPlus(ExecutorPlus executor)
-
-
Method Detail
-
maybeExecuteImmediately
public void maybeExecuteImmediately(java.lang.Runnable task)
Description copied from interface:ExecutorPlus
MAY executetask
immediately, if the calling thread is permitted to do so.- Specified by:
maybeExecuteImmediately
in interfaceExecutorPlus
-
execute
public void execute(WithResources withResources, java.lang.Runnable task)
Description copied from interface:ExecutorPlus
Invoketask
. The invoking thread will first instantiate the resources provided before invokingtask
, so that thread state may be modified and cleaned up. The invoking thread will execute something semantically equivlent to:try (Closeable close = withResources.get()) { task.run(); }
- Specified by:
execute
in interfaceExecutorPlus
- Parameters:
withResources
- the resources to create and hold while executingtask
task
- the task to execute
-
submit
public <T> Future<T> submit(WithResources withResources, java.util.concurrent.Callable<T> task)
Description copied from interface:ExecutorPlus
Invoketask
, returning a future representing this computation. The invoking thread will first instantiate the resources provided before invokingtask
, so that thread state may be modified and cleaned up. The invoking thread will execute something semantically equivlent to:try (Closeable close = withResources.get()) { return task.call(); }
- Specified by:
submit
in interfaceExecutorPlus
- Parameters:
withResources
- the resources to create and hold while executingtask
task
- the task to execute
-
submit
public <T> Future<T> submit(WithResources withResources, java.lang.Runnable task, T result)
Description copied from interface:ExecutorPlus
Invoketask
, returning a future yieldingresult
if successful, or the abnormal termination oftask
otherwise. The invoking thread will first instantiate the resources provided before invokingtask
, so that thread state may be modified and cleaned up. The invoking thread will execute something semantically equivlent to:try (Closeable close = withResources.get()) { task.run(); return result; }
- Specified by:
submit
in interfaceExecutorPlus
- Parameters:
withResources
- the resources to create and hold while executingtask
task
- the task to executeresult
- the result if successful
-
submit
public Future<?> submit(WithResources withResources, java.lang.Runnable task)
Description copied from interface:ExecutorPlus
Invoketask
, returning a future yieldingnull
if successful, or the abnormal termination oftask
otherwise. The invoking thread will first instantiate the resources provided before invokingtask
, so that thread state may be modified and cleaned uptry (Closeable close = withResources.get()) { task.run(); return null; }
- Specified by:
submit
in interfaceExecutorPlus
- Parameters:
withResources
- the resources to create and hold while executingtask
task
- the task to execute
-
inExecutor
public boolean inExecutor()
- Specified by:
inExecutor
in interfaceExecutorPlus
- Returns:
- true iff the caller is a worker thread actively serving this executor
-
submit
public <T> Future<T> submit(java.util.concurrent.Callable<T> task)
Description copied from interface:ExecutorPlus
OverridesExecutorService.submit(Callable)
to return a CassandraFuture
- Specified by:
submit
in interfaceExecutorPlus
- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
-
submit
public <T> Future<T> submit(java.lang.Runnable task, T result)
Description copied from interface:ExecutorPlus
OverridesExecutorService.submit(Runnable, Object)
to return a CassandraFuture
- Specified by:
submit
in interfaceExecutorPlus
- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
-
submit
public Future<?> submit(java.lang.Runnable task)
Description copied from interface:ExecutorPlus
OverridesExecutorService.submit(Runnable)
to return a CassandraFuture
- Specified by:
submit
in interfaceExecutorPlus
- Specified by:
submit
in interfacejava.util.concurrent.ExecutorService
-
getActiveTaskCount
public int getActiveTaskCount()
Description copied from interface:ResizableThreadPool
Returns the approximate number of threads that are actively executing tasks.- Specified by:
getActiveTaskCount
in interfaceResizableThreadPool
- Returns:
- the number of threads
-
getCompletedTaskCount
public long getCompletedTaskCount()
Description copied from interface:ResizableThreadPool
Returns the approximate total number of tasks that have completed execution. Because the states of tasks and threads may change dynamically during computation, the returned value is only an approximation, but one that does not ever decrease across successive calls.- Specified by:
getCompletedTaskCount
in interfaceResizableThreadPool
- Returns:
- the number of tasks
-
getPendingTaskCount
public int getPendingTaskCount()
Description copied from interface:ResizableThreadPool
Returns the approximate total of tasks waiting to be executed. Because the states of tasks and threads may change dynamically during computation, the returned value is only an approximation.- Specified by:
getPendingTaskCount
in interfaceResizableThreadPool
- Returns:
- the number of tasks
-
getMaxTasksQueued
public int getMaxTasksQueued()
- Specified by:
getMaxTasksQueued
in interfaceResizableThreadPool
-
getCorePoolSize
public int getCorePoolSize()
Description copied from interface:ResizableThreadPool
Returns core pool size of thread pool, the minimum number of workers (where that makes sense for a thread pool, SEPExecutor does not have a minimum size).- Specified by:
getCorePoolSize
in interfaceResizableThreadPool
-
setCorePoolSize
public void setCorePoolSize(int newCorePoolSize)
Description copied from interface:ResizableThreadPool
Allows user to resize minimum size of the thread pool.- Specified by:
setCorePoolSize
in interfaceResizableThreadPool
-
getMaximumPoolSize
public int getMaximumPoolSize()
Description copied from interface:ResizableThreadPool
Returns maximum pool size of thread pool.- Specified by:
getMaximumPoolSize
in interfaceResizableThreadPool
-
setMaximumPoolSize
public void setMaximumPoolSize(int newMaximumPoolSize)
Description copied from interface:ResizableThreadPool
Allows user to resize maximum size of the thread pool.- Specified by:
setMaximumPoolSize
in interfaceResizableThreadPool
-
invokeAll
public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks) throws java.lang.InterruptedException
- Specified by:
invokeAll
in interfaceExecutorPlus
- Specified by:
invokeAll
in interfacejava.util.concurrent.ExecutorService
- Throws:
java.lang.InterruptedException
-
invokeAll
public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
invokeAll
in interfaceExecutorPlus
- Specified by:
invokeAll
in interfacejava.util.concurrent.ExecutorService
- Throws:
java.lang.InterruptedException
-
invokeAny
public <T> T invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
- Specified by:
invokeAny
in interfaceExecutorPlus
- Specified by:
invokeAny
in interfacejava.util.concurrent.ExecutorService
- Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
invokeAny
public <T> T invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
- Specified by:
invokeAny
in interfaceExecutorPlus
- Specified by:
invokeAny
in interfacejava.util.concurrent.ExecutorService
- Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfacejava.util.concurrent.ExecutorService
-
shutdownNow
public java.util.List<java.lang.Runnable> shutdownNow()
- Specified by:
shutdownNow
in interfacejava.util.concurrent.ExecutorService
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdown
in interfacejava.util.concurrent.ExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminated
in interfacejava.util.concurrent.ExecutorService
-
awaitTermination
public boolean awaitTermination(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
awaitTermination
in interfacejava.util.concurrent.ExecutorService
- Throws:
java.lang.InterruptedException
-
execute
public void execute(java.lang.Runnable task)
- Specified by:
execute
in interfacejava.util.concurrent.Executor
-
-