Class OrderedScheduler

java.lang.Object
org.apache.bookkeeper.common.util.OrderedExecutor
org.apache.bookkeeper.common.util.OrderedScheduler
All Implemented Interfaces:
Executor, ExecutorService, ScheduledExecutorService

public class OrderedScheduler extends OrderedExecutor implements 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.
  • Method Details

    • newSchedulerBuilder

      public static OrderedScheduler.SchedulerBuilder newSchedulerBuilder()
      Create a builder to build ordered scheduler.
      Returns:
      builder to build ordered scheduler.
    • createSingleThreadExecutor

      protected ExecutorService createSingleThreadExecutor(ThreadFactory factory)
      Overrides:
      createSingleThreadExecutor in class OrderedExecutor
    • getBoundedExecutor

      protected com.google.common.util.concurrent.ListeningScheduledExecutorService getBoundedExecutor(ExecutorService executor)
      Overrides:
      getBoundedExecutor in class OrderedExecutor
    • addExecutorDecorators

      protected com.google.common.util.concurrent.ListeningScheduledExecutorService addExecutorDecorators(ExecutorService executor)
      Overrides:
      addExecutorDecorators in class OrderedExecutor
    • chooseThread

      public com.google.common.util.concurrent.ListeningScheduledExecutorService chooseThread()
      Overrides:
      chooseThread in class OrderedExecutor
    • chooseThread

      public com.google.common.util.concurrent.ListeningScheduledExecutorService chooseThread(Object orderingKey)
      Overrides:
      chooseThread in class OrderedExecutor
    • chooseThread

      public com.google.common.util.concurrent.ListeningScheduledExecutorService chooseThread(long orderingKey)
      Description copied from class: OrderedExecutor
      skip hashcode generation in this special case.
      Overrides:
      chooseThread in class OrderedExecutor
      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 ordering
      command - - the Runnable to execute
      delay - - the time from now to delay execution
      unit - - 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 ordering
      command - - the Runnable to execute
      initialDelay - - the time to delay first execution
      period - - the period between successive executions
      unit - - 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 ordering
      command - - the Runnable to execute
      initialDelay - - the time to delay first execution
      delay - - the delay between the termination of one execution and the commencement of the next
      unit - - 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

      public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)
      Specified by:
      schedule in interface ScheduledExecutorService
    • schedule

      public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit)
      Specified by:
      schedule in interface ScheduledExecutorService
    • scheduleAtFixedRate

      public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
      Specified by:
      scheduleAtFixedRate in interface ScheduledExecutorService
    • scheduleWithFixedDelay

      public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
      Specified by:
      scheduleWithFixedDelay in interface ScheduledExecutorService