public class OrderedExecutor
extends java.lang.Object
implements java.util.concurrent.ExecutorService
Object.hashCode()
method.| Modifier and Type | Class and Description |
|---|---|
static class |
OrderedExecutor.AbstractBuilder<T extends OrderedExecutor>
Abstract builder class to build
OrderedScheduler. |
static class |
OrderedExecutor.Builder
A builder class for an OrderedExecutor.
|
(package private) static class |
OrderedExecutor.ContextPreservingCallable<T>
Decorator class for a callable that preserves MDC context.
|
(package private) static class |
OrderedExecutor.ContextPreservingRunnable
Decorator class for a runnable that preserves MDC context.
|
protected class |
OrderedExecutor.TimedCallable<T>
Decorator class for a callable that measure the execution time.
|
protected class |
OrderedExecutor.TimedRunnable
Decorator class for a runnable that measure the execution time.
|
| Modifier and Type | Field and Description |
|---|---|
(package private) boolean |
enableBusyWait |
(package private) boolean |
enableThreadScopedMetrics |
(package private) int |
maxTasksInQueue |
(package private) java.lang.String |
name |
static int |
NO_TASK_LIMIT |
(package private) boolean |
preserveMdcForTaskExecution |
(package private) java.util.Random |
rand |
(package private) org.apache.bookkeeper.stats.OpStatsLogger |
taskExecutionStats |
(package private) org.apache.bookkeeper.stats.OpStatsLogger |
taskPendingStats |
(package private) long[] |
threadIds |
(package private) java.util.concurrent.ExecutorService[] |
threads |
(package private) boolean |
traceTaskExecution |
protected static long |
WARN_TIME_MICRO_SEC_DEFAULT |
(package private) long |
warnTimeMicroSec |
| Modifier | Constructor and Description |
|---|---|
protected |
OrderedExecutor(java.lang.String baseName,
int numThreads,
java.util.concurrent.ThreadFactory threadFactory,
org.apache.bookkeeper.stats.StatsLogger statsLogger,
boolean traceTaskExecution,
boolean preserveMdcForTaskExecution,
long warnTimeMicroSec,
int maxTasksInQueue,
boolean enableBusyWait,
boolean enableThreadScopedMetrics)
Constructs Safe executor.
|
| Modifier and Type | Method and Description |
|---|---|
protected java.util.concurrent.ExecutorService |
addExecutorDecorators(java.util.concurrent.ExecutorService executor) |
boolean |
awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit) |
java.util.concurrent.ExecutorService |
chooseThread() |
java.util.concurrent.ExecutorService |
chooseThread(long orderingKey)
skip hashcode generation in this special case.
|
java.util.concurrent.ExecutorService |
chooseThread(java.lang.Object orderingKey) |
protected static int |
chooseThreadIdx(long orderingKey,
int numThreads) |
protected java.util.concurrent.ExecutorService |
createSingleThreadExecutor(java.util.concurrent.ThreadFactory factory) |
void |
execute(java.lang.Runnable command) |
void |
executeOrdered(int orderingKey,
java.lang.Runnable r)
Schedules a one time action to execute with an ordering guarantee on the key.
|
void |
executeOrdered(long orderingKey,
java.lang.Runnable r)
Schedules a one time action to execute with an ordering guarantee on the key.
|
void |
executeOrdered(java.lang.Object orderingKey,
java.lang.Runnable r)
Schedules a one time action to execute with an ordering guarantee on the key.
|
void |
forceShutdown(long timeout,
java.util.concurrent.TimeUnit unit)
Force threads shutdown (cancel active requests) after specified delay,
to be used after shutdown() rejects new requests.
|
protected java.util.concurrent.ExecutorService |
getBoundedExecutor(java.util.concurrent.ExecutorService executor) |
long |
getThreadID(long orderingKey) |
<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() |
static OrderedExecutor.Builder |
newBuilder() |
boolean |
preserveMdc()
Flag describing executor's expectation in regards of MDC.
|
void |
shutdown() |
java.util.List<java.lang.Runnable> |
shutdownNow() |
<T> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> task) |
java.util.concurrent.Future<?> |
submit(java.lang.Runnable task) |
<T> java.util.concurrent.Future<T> |
submit(java.lang.Runnable task,
T result) |
<T> com.google.common.util.concurrent.ListenableFuture<T> |
submitOrdered(long orderingKey,
java.util.concurrent.Callable<T> task) |
protected <T> java.util.concurrent.Callable<T> |
timedCallable(java.util.concurrent.Callable<T> c) |
protected <T> java.util.Collection<? extends java.util.concurrent.Callable<T>> |
timedCallables(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks) |
protected java.lang.Runnable |
timedRunnable(java.lang.Runnable r) |
public static final int NO_TASK_LIMIT
protected static final long WARN_TIME_MICRO_SEC_DEFAULT
final java.lang.String name
final java.util.concurrent.ExecutorService[] threads
final long[] threadIds
final java.util.Random rand
final org.apache.bookkeeper.stats.OpStatsLogger taskExecutionStats
final org.apache.bookkeeper.stats.OpStatsLogger taskPendingStats
final boolean traceTaskExecution
final boolean preserveMdcForTaskExecution
final long warnTimeMicroSec
final int maxTasksInQueue
final boolean enableBusyWait
final boolean enableThreadScopedMetrics
protected OrderedExecutor(java.lang.String baseName,
int numThreads,
java.util.concurrent.ThreadFactory threadFactory,
org.apache.bookkeeper.stats.StatsLogger statsLogger,
boolean traceTaskExecution,
boolean preserveMdcForTaskExecution,
long warnTimeMicroSec,
int maxTasksInQueue,
boolean enableBusyWait,
boolean enableThreadScopedMetrics)
numThreads - - number of threadsbaseName - - base name of executor threadsthreadFactory - - for constructing threadsstatsLogger - - for reporting executor statstraceTaskExecution - - should we stat task executionpreserveMdcForTaskExecution - - should we preserve MDC for task executionwarnTimeMicroSec - - log long task exec warning after this intervalmaxTasksInQueue - - maximum items allowed in a thread queue. -1 for no limitpublic static OrderedExecutor.Builder newBuilder()
protected java.util.concurrent.ExecutorService createSingleThreadExecutor(java.util.concurrent.ThreadFactory factory)
protected java.util.concurrent.ExecutorService getBoundedExecutor(java.util.concurrent.ExecutorService executor)
protected java.util.concurrent.ExecutorService addExecutorDecorators(java.util.concurrent.ExecutorService executor)
public boolean preserveMdc()
public void executeOrdered(java.lang.Object orderingKey,
java.lang.Runnable r)
orderingKey - r - public void executeOrdered(long orderingKey,
java.lang.Runnable r)
orderingKey - r - public void executeOrdered(int orderingKey,
java.lang.Runnable r)
orderingKey - r - public <T> com.google.common.util.concurrent.ListenableFuture<T> submitOrdered(long orderingKey,
java.util.concurrent.Callable<T> task)
public long getThreadID(long orderingKey)
public java.util.concurrent.ExecutorService chooseThread()
public java.util.concurrent.ExecutorService chooseThread(java.lang.Object orderingKey)
public java.util.concurrent.ExecutorService chooseThread(long orderingKey)
orderingKey - long ordering keyprotected static int chooseThreadIdx(long orderingKey,
int numThreads)
protected java.lang.Runnable timedRunnable(java.lang.Runnable r)
protected <T> java.util.concurrent.Callable<T> timedCallable(java.util.concurrent.Callable<T> c)
protected <T> java.util.Collection<? extends java.util.concurrent.Callable<T>> timedCallables(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
public <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
submit in interface java.util.concurrent.ExecutorServicepublic <T> java.util.concurrent.Future<T> submit(java.lang.Runnable task,
T result)
submit in interface java.util.concurrent.ExecutorServicepublic java.util.concurrent.Future<?> submit(java.lang.Runnable task)
submit in interface java.util.concurrent.ExecutorServicepublic <T> java.util.List<java.util.concurrent.Future<T>> invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
throws java.lang.InterruptedException
invokeAll in interface java.util.concurrent.ExecutorServicejava.lang.InterruptedExceptionpublic <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
invokeAll in interface java.util.concurrent.ExecutorServicejava.lang.InterruptedExceptionpublic <T> T invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
throws java.lang.InterruptedException,
java.util.concurrent.ExecutionException
invokeAny in interface java.util.concurrent.ExecutorServicejava.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionpublic <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
invokeAny in interface java.util.concurrent.ExecutorServicejava.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.util.concurrent.TimeoutExceptionpublic void execute(java.lang.Runnable command)
execute in interface java.util.concurrent.Executorpublic void shutdown()
shutdown in interface java.util.concurrent.ExecutorServicepublic java.util.List<java.lang.Runnable> shutdownNow()
shutdownNow in interface java.util.concurrent.ExecutorServicepublic boolean isShutdown()
isShutdown in interface java.util.concurrent.ExecutorServicepublic boolean awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
awaitTermination in interface java.util.concurrent.ExecutorServicejava.lang.InterruptedExceptionpublic boolean isTerminated()
isTerminated in interface java.util.concurrent.ExecutorServicepublic void forceShutdown(long timeout,
java.util.concurrent.TimeUnit unit)
Copyright © 2011–2022 The Apache Software Foundation. All rights reserved.