Class OrderedScheduler
java.lang.Object
org.apache.bookkeeper.common.util.OrderedExecutor
org.apache.bookkeeper.common.util.OrderedScheduler
- All Implemented Interfaces:
Executor,ExecutorService,ScheduledExecutorService
This class provides supports submitting tasks with an ordering key, so that tasks submitted
with the same key will always be executed in order, but tasks across
different keys can be unordered. This retains parallelism while retaining the
basic amount of ordering we want (e.g. , per ledger handle). Ordering is
achieved by hashing the key objects to threads by their
Object.hashCode()
method.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) classstatic classBuilder to build ordered scheduler.Nested classes/interfaces inherited from class org.apache.bookkeeper.common.util.OrderedExecutor
OrderedExecutor.AbstractBuilder<T extends OrderedExecutor>, OrderedExecutor.Builder, OrderedExecutor.ContextPreservingCallable<T>, OrderedExecutor.ContextPreservingRunnable, OrderedExecutor.TimedCallable<T>, OrderedExecutor.TimedRunnable -
Field Summary
Fields inherited from class org.apache.bookkeeper.common.util.OrderedExecutor
enableBusyWait, enableThreadScopedMetrics, maxTasksInQueue, name, NO_TASK_LIMIT, preserveMdcForTaskExecution, rand, taskExecutionStats, taskPendingStats, threadIds, threads, traceTaskExecution, WARN_TIME_MICRO_SEC_DEFAULT, warnTimeMicroSec -
Method Summary
Modifier and TypeMethodDescriptionprotected com.google.common.util.concurrent.ListeningScheduledExecutorServiceaddExecutorDecorators(ExecutorService executor) com.google.common.util.concurrent.ListeningScheduledExecutorServicecom.google.common.util.concurrent.ListeningScheduledExecutorServicechooseThread(long orderingKey) skip hashcode generation in this special case.com.google.common.util.concurrent.ListeningScheduledExecutorServicechooseThread(Object orderingKey) protected ExecutorServicecreateSingleThreadExecutor(ThreadFactory factory) protected com.google.common.util.concurrent.ListeningScheduledExecutorServicegetBoundedExecutor(ExecutorService executor) Create a builder to build ordered scheduler.<V> ScheduledFuture<V>scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) scheduleAtFixedRateOrdered(Object orderingKey, Runnable command, long initialDelay, long period, TimeUnit unit) Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period.scheduleOrdered(Object orderingKey, Runnable command, long delay, TimeUnit unit) Creates and executes a one-shot action that becomes enabled after the given delay.scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) scheduleWithFixedDelayOrdered(Object orderingKey, Runnable command, long initialDelay, long delay, TimeUnit unit) Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.<T> com.google.common.util.concurrent.ListenableFuture<T>submitOrdered(Object orderingKey, Callable<T> callable) schedules a one time action to execute with an ordering guarantee on the key.Methods inherited from class org.apache.bookkeeper.common.util.OrderedExecutor
awaitTermination, chooseThreadIdx, execute, executeOrdered, executeOrdered, executeOrdered, forceShutdown, getThreadID, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated, newBuilder, preserveMdc, shutdown, shutdownNow, submit, submit, submit, submitOrdered, timedCallable, timedCallables, timedRunnableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow, submit, submit, submit
-
Method Details
-
newSchedulerBuilder
Create a builder to build ordered scheduler.- Returns:
- builder to build ordered scheduler.
-
createSingleThreadExecutor
- Overrides:
createSingleThreadExecutorin classOrderedExecutor
-
getBoundedExecutor
protected com.google.common.util.concurrent.ListeningScheduledExecutorService getBoundedExecutor(ExecutorService executor) - Overrides:
getBoundedExecutorin classOrderedExecutor
-
addExecutorDecorators
protected com.google.common.util.concurrent.ListeningScheduledExecutorService addExecutorDecorators(ExecutorService executor) - Overrides:
addExecutorDecoratorsin classOrderedExecutor
-
chooseThread
public com.google.common.util.concurrent.ListeningScheduledExecutorService chooseThread()- Overrides:
chooseThreadin classOrderedExecutor
-
chooseThread
public com.google.common.util.concurrent.ListeningScheduledExecutorService chooseThread(Object orderingKey) - Overrides:
chooseThreadin classOrderedExecutor
-
chooseThread
public com.google.common.util.concurrent.ListeningScheduledExecutorService chooseThread(long orderingKey) Description copied from class:OrderedExecutorskip hashcode generation in this special case.- Overrides:
chooseThreadin classOrderedExecutor- Parameters:
orderingKey- long ordering key- Returns:
- the thread for executing this order key
-
submitOrdered
public <T> com.google.common.util.concurrent.ListenableFuture<T> submitOrdered(Object orderingKey, Callable<T> callable) schedules a one time action to execute with an ordering guarantee on the key.- Parameters:
orderingKey-callable-
-
scheduleOrdered
public ScheduledFuture<?> scheduleOrdered(Object orderingKey, Runnable command, long delay, TimeUnit unit) Creates and executes a one-shot action that becomes enabled after the given delay.- Parameters:
orderingKey- - the key used for orderingcommand- - the Runnable to executedelay- - the time from now to delay executionunit- - the time unit of the delay parameter- Returns:
- a ScheduledFuture representing pending completion of the task and whose get() method will return null upon completion
-
scheduleAtFixedRateOrdered
public ScheduledFuture<?> scheduleAtFixedRateOrdered(Object orderingKey, Runnable command, long initialDelay, long period, TimeUnit unit) Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period.For more details check
ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit).- Parameters:
orderingKey- - the key used for orderingcommand- - the Runnable to executeinitialDelay- - the time to delay first executionperiod- - the period between successive executionsunit- - the time unit of the initialDelay and period parameters- Returns:
- a ScheduledFuture representing pending completion of the task, and whose get() method will throw an exception upon cancellation
-
scheduleWithFixedDelayOrdered
public ScheduledFuture<?> scheduleWithFixedDelayOrdered(Object orderingKey, Runnable command, long initialDelay, long delay, TimeUnit unit) Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.For more details check
ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit).- Parameters:
orderingKey- - the key used for orderingcommand- - the Runnable to executeinitialDelay- - the time to delay first executiondelay- - the delay between the termination of one execution and the commencement of the nextunit- - the time unit of the initialDelay and delay parameters- Returns:
- a ScheduledFuture representing pending completion of the task, and whose get() method will throw an exception upon cancellation
-
schedule
- Specified by:
schedulein interfaceScheduledExecutorService
-
schedule
- Specified by:
schedulein interfaceScheduledExecutorService
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) - Specified by:
scheduleAtFixedRatein interfaceScheduledExecutorService
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) - Specified by:
scheduleWithFixedDelayin interfaceScheduledExecutorService
-