Interface NonBlockingManager

  • All Known Implementing Classes:
    NonBlockingManagerImpl

    public interface NonBlockingManager
    Manager utility for non-blocking operations.
    • Method Detail

      • scheduleWithFixedDelay

        default AutoCloseable scheduleWithFixedDelay​(Supplier<CompletionStage<?>> supplier,
                                                     long initialDelay,
                                                     long delay,
                                                     TimeUnit unit)
        Schedules the supplier that is executed after the initialDelay period and subsequently runs delay after the previous stage completes. The supplier must not block the thread in which it runs and should immediately return to avoid blocking the scheduling thread.

        The supplier will not be rescheduled if the supplier or the returned stage produce a Throwable.

        Parameters:
        supplier - non-blocking operation supplier.
        initialDelay - period of time before the supplier is invoked.
        delay - delay between subsequent supplier invocations.
        unit - time unit for delays.
        Returns:
        an AutoCloseable that cancels the scheduled task.
      • scheduleWithFixedDelay

        AutoCloseable scheduleWithFixedDelay​(Supplier<CompletionStage<?>> supplier,
                                             long initialDelay,
                                             long delay,
                                             TimeUnit unit,
                                             Predicate<? super Throwable> mayRepeatOnThrowable)
        Schedules the supplier that is executed after the initialDelay period and subsequently runs delay after the previous stage completes. The supplier must not block the thread in which it runs and should immediately return to avoid blocking the scheduling thread.

        This supplier method will not be rescheduled if the supplier throws any Throwable directly. If the CompletionStage returned from the supplier produces a Throwable, it is possible to reschedule the supplier if the given Throwable passes the mayRepeatOnThrowable predicate.

        Parameters:
        supplier - non-blocking operation supplier.
        initialDelay - period of time before the supplier is invoked.
        delay - delay between subsequent supplier invocations.
        unit - time unit for delays.
        mayRepeatOnThrowable - whether to continue scheduling if the provided supplier returns a Throwable
        Returns:
        an AutoCloseable that cancels the scheduled task.
      • complete

        <T> void complete​(CompletableFuture<? super T> future,
                          T value)
        Completes the provided future with the given value. If the future does not have any dependents it will complete it in the invoking thread. However, if there are any dependents it will complete it in a non blocking thread. This is a best effort to prevent a context switch for a stage that does not yet have a dependent while also handing off the dependent processing to a non blocking thread if necessary.
        Type Parameters:
        T - the type of the value
        Parameters:
        future - the future to complete
        value - the value to complete the future with
      • completeExceptionally

        void completeExceptionally​(CompletableFuture<?> future,
                                   Throwable t)
        Exceptionally completes the provided future with the given throble. If the future does not have any dependents it will complete it in the invoking thread. However, if there are any dependents it will complete it in a non blocking thread. This is a best effort to prevent a context switch for a stage that does not yet have a dependent while also handing off the dependent processing to a non blocking thread if necessary.
        Parameters:
        future - future to complete
        t - throwable to complete the future with