Class PollingFuture<V>

  • Direct Known Subclasses:
    PerspectivePollingFuture

    public class PollingFuture<V>
    extends AbstractLifecycle
    Scaffolding for managing the fetching of a completable future that may need to poll or be executed on-demand.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected static class  PollingFuture.State  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static LoggerEx LOG  
    • Constructor Summary

      Constructors 
      Constructor Description
      PollingFuture​(java.util.concurrent.ScheduledExecutorService scheduler, java.util.concurrent.ExecutorService executor, java.util.function.Supplier<java.util.concurrent.CompletableFuture<V>> fetch, java.util.function.BiConsumer<V,​java.lang.Throwable> whenComplete, long rate, java.util.concurrent.TimeUnit rateTimeUnit, java.lang.String diagnosticId)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected long getInitialRate()
      Default implementation returns the rate from the constructor, but provides a place for subclasses to re-define the rate on startup if necessary.
      long getRateMillis()  
      protected void onShutdown()  
      protected void onStartup()  
      void setRate​(long rate, java.util.concurrent.TimeUnit unit)  
      void submitIfIdle()
      Submits the task immediately if currently idle or scheduled.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOG

        protected static final LoggerEx LOG
    • Constructor Detail

      • PollingFuture

        public PollingFuture​(java.util.concurrent.ScheduledExecutorService scheduler,
                             java.util.concurrent.ExecutorService executor,
                             java.util.function.Supplier<java.util.concurrent.CompletableFuture<V>> fetch,
                             java.util.function.BiConsumer<V,​java.lang.Throwable> whenComplete,
                             long rate,
                             java.util.concurrent.TimeUnit rateTimeUnit,
                             java.lang.String diagnosticId)
        Parameters:
        scheduler - No blocking work will be done on this scheduler
        executor - Value delivery will be done on this executor
        fetch - Fetch the next value. Don't block.
        whenComplete - Callback for when the value is received. May block. Will be called on the executor.
        rate - If positive, the task will be executed once on startup, and then repeatedly with this amount of time as a delay between executions. If zero or less, will be executed once on startup, and again whenever submitIfIdle() is called.
        rateTimeUnit - Time unit for the rate.
        diagnosticId - Will be set during task execution using MDC as "task-id" key
    • Method Detail

      • submitIfIdle

        public void submitIfIdle()
        Submits the task immediately if currently idle or scheduled.
      • getInitialRate

        protected long getInitialRate()
        Default implementation returns the rate from the constructor, but provides a place for subclasses to re-define the rate on startup if necessary.
      • setRate

        public void setRate​(long rate,
                            java.util.concurrent.TimeUnit unit)
      • getRateMillis

        public long getRateMillis()