Class OrderedScheduler

  • All Implemented Interfaces:
    java.util.concurrent.Executor, java.util.concurrent.ExecutorService, java.util.concurrent.ScheduledExecutorService

    public class OrderedScheduler
    extends OrderedExecutor
    implements java.util.concurrent.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 Detail

      • newSchedulerBuilder

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

        protected java.util.concurrent.ExecutorService createSingleThreadExecutor​(java.util.concurrent.ThreadFactory factory)
        Overrides:
        createSingleThreadExecutor in class OrderedExecutor
      • getBoundedExecutor

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

        protected com.google.common.util.concurrent.ListeningScheduledExecutorService addExecutorDecorators​(java.util.concurrent.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​(java.lang.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​(java.lang.Object orderingKey,
                                                                                       java.util.concurrent.Callable<T> callable)
        schedules a one time action to execute with an ordering guarantee on the key.
        Parameters:
        orderingKey -
        callable -
      • scheduleOrdered

        public java.util.concurrent.ScheduledFuture<?> scheduleOrdered​(java.lang.Object orderingKey,
                                                                       java.lang.Runnable command,
                                                                       long delay,
                                                                       java.util.concurrent.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 java.util.concurrent.ScheduledFuture<?> scheduleAtFixedRateOrdered​(java.lang.Object orderingKey,
                                                                                  java.lang.Runnable command,
                                                                                  long initialDelay,
                                                                                  long period,
                                                                                  java.util.concurrent.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 java.util.concurrent.ScheduledFuture<?> scheduleWithFixedDelayOrdered​(java.lang.Object orderingKey,
                                                                                     java.lang.Runnable command,
                                                                                     long initialDelay,
                                                                                     long delay,
                                                                                     java.util.concurrent.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 java.util.concurrent.ScheduledFuture<?> schedule​(java.lang.Runnable command,
                                                                long delay,
                                                                java.util.concurrent.TimeUnit unit)
        Specified by:
        schedule in interface java.util.concurrent.ScheduledExecutorService
      • schedule

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

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

        public java.util.concurrent.ScheduledFuture<?> scheduleWithFixedDelay​(java.lang.Runnable command,
                                                                              long initialDelay,
                                                                              long delay,
                                                                              java.util.concurrent.TimeUnit unit)
        Specified by:
        scheduleWithFixedDelay in interface java.util.concurrent.ScheduledExecutorService