Class StateFutureImpl<T>

  • All Implemented Interfaces:
    org.apache.flink.api.common.state.v2.StateFuture<T>, InternalStateFuture<T>

    @Internal
    public class StateFutureImpl<T>
    extends Object
    implements InternalStateFuture<T>
    The default implementation of StateFuture. This is managed by the runtime framework and should never be directly created in user code. It will handle the completion and callback trigger, and most of the design are borrowed from the CompletableFuture. In the basic version of this implementation, we wrap CompletableFuture for simplification. TODO: remove CompletableFuture.

    This class is on hot path and very complex, please take care of the performance as well as the running thread of each block when you decide to touch it.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void callbackFinished()
      Will be triggered when a callback finishes processing.
      void callbackRegistered()
      Will be triggered when a callback is registered.
      void complete​(T result)
      Complete this future.
      void completeExceptionally​(String message, Throwable ex)
      Fail this future and pass the given exception to the runtime.
      T get()
      Waits if necessary for the computation to complete, and then retrieves its result.
      boolean isDone()
      Returns true if completed in any fashion: normally, exceptionally, or via cancellation.
      <A> StateFutureImpl<A> makeNewStateFuture()
      Make a new future based on context of this future.
      void postComplete​(boolean inCallbackRunner)
      Will be triggered when this future completes.
      org.apache.flink.api.common.state.v2.StateFuture<Void> thenAccept​(org.apache.flink.util.function.ThrowingConsumer<? super T,​? extends Exception> action)  
      <U> org.apache.flink.api.common.state.v2.StateFuture<U> thenApply​(org.apache.flink.util.function.FunctionWithException<? super T,​? extends U,​? extends Exception> fn)  
      <U,​V>
      org.apache.flink.api.common.state.v2.StateFuture<V>
      thenCombine​(org.apache.flink.api.common.state.v2.StateFuture<? extends U> other, org.apache.flink.util.function.BiFunctionWithException<? super T,​? super U,​? extends V,​? extends Exception> fn)  
      <U> org.apache.flink.api.common.state.v2.StateFuture<U> thenCompose​(org.apache.flink.util.function.FunctionWithException<? super T,​? extends org.apache.flink.api.common.state.v2.StateFuture<U>,​? extends Exception> action)  
      org.apache.flink.api.common.state.v2.StateFuture<Boolean> thenConditionallyAccept​(org.apache.flink.util.function.FunctionWithException<? super T,​Boolean,​? extends Exception> condition, org.apache.flink.util.function.ThrowingConsumer<? super T,​? extends Exception> actionIfTrue)  
      org.apache.flink.api.common.state.v2.StateFuture<Boolean> thenConditionallyAccept​(org.apache.flink.util.function.FunctionWithException<? super T,​Boolean,​? extends Exception> condition, org.apache.flink.util.function.ThrowingConsumer<? super T,​? extends Exception> actionIfTrue, org.apache.flink.util.function.ThrowingConsumer<? super T,​? extends Exception> actionIfFalse)  
      <U> org.apache.flink.api.common.state.v2.StateFuture<org.apache.flink.api.java.tuple.Tuple2<Boolean,​U>> thenConditionallyApply​(org.apache.flink.util.function.FunctionWithException<? super T,​Boolean,​? extends Exception> condition, org.apache.flink.util.function.FunctionWithException<? super T,​? extends U,​? extends Exception> actionIfTrue)  
      <U,​V>
      org.apache.flink.api.common.state.v2.StateFuture<org.apache.flink.api.java.tuple.Tuple2<Boolean,​Object>>
      thenConditionallyApply​(org.apache.flink.util.function.FunctionWithException<? super T,​Boolean,​? extends Exception> condition, org.apache.flink.util.function.FunctionWithException<? super T,​? extends U,​? extends Exception> actionIfTrue, org.apache.flink.util.function.FunctionWithException<? super T,​? extends V,​? extends Exception> actionIfFalse)  
      <U> org.apache.flink.api.common.state.v2.StateFuture<org.apache.flink.api.java.tuple.Tuple2<Boolean,​U>> thenConditionallyCompose​(org.apache.flink.util.function.FunctionWithException<? super T,​Boolean,​? extends Exception> condition, org.apache.flink.util.function.FunctionWithException<? super T,​? extends org.apache.flink.api.common.state.v2.StateFuture<U>,​? extends Exception> actionIfTrue)  
      <U,​V>
      org.apache.flink.api.common.state.v2.StateFuture<org.apache.flink.api.java.tuple.Tuple2<Boolean,​Object>>
      thenConditionallyCompose​(org.apache.flink.util.function.FunctionWithException<? super T,​Boolean,​? extends Exception> condition, org.apache.flink.util.function.FunctionWithException<? super T,​? extends org.apache.flink.api.common.state.v2.StateFuture<U>,​? extends Exception> actionIfTrue, org.apache.flink.util.function.FunctionWithException<? super T,​? extends org.apache.flink.api.common.state.v2.StateFuture<V>,​? extends Exception> actionIfFalse)  
      void thenSyncAccept​(org.apache.flink.util.function.ThrowingConsumer<? super T,​? extends Exception> action)
      Accept the action in the same thread with the one of complete (or current thread if it has been completed).
    • Method Detail

      • thenApply

        public <U> org.apache.flink.api.common.state.v2.StateFuture<U> thenApply​(org.apache.flink.util.function.FunctionWithException<? super T,​? extends U,​? extends Exception> fn)
        Specified by:
        thenApply in interface org.apache.flink.api.common.state.v2.StateFuture<T>
      • thenAccept

        public org.apache.flink.api.common.state.v2.StateFuture<Void> thenAccept​(org.apache.flink.util.function.ThrowingConsumer<? super T,​? extends Exception> action)
        Specified by:
        thenAccept in interface org.apache.flink.api.common.state.v2.StateFuture<T>
      • thenCompose

        public <U> org.apache.flink.api.common.state.v2.StateFuture<U> thenCompose​(org.apache.flink.util.function.FunctionWithException<? super T,​? extends org.apache.flink.api.common.state.v2.StateFuture<U>,​? extends Exception> action)
        Specified by:
        thenCompose in interface org.apache.flink.api.common.state.v2.StateFuture<T>
      • thenCombine

        public <U,​V> org.apache.flink.api.common.state.v2.StateFuture<V> thenCombine​(org.apache.flink.api.common.state.v2.StateFuture<? extends U> other,
                                                                                           org.apache.flink.util.function.BiFunctionWithException<? super T,​? super U,​? extends V,​? extends Exception> fn)
        Specified by:
        thenCombine in interface org.apache.flink.api.common.state.v2.StateFuture<T>
      • thenConditionallyApply

        public <U,​V> org.apache.flink.api.common.state.v2.StateFuture<org.apache.flink.api.java.tuple.Tuple2<Boolean,​Object>> thenConditionallyApply​(org.apache.flink.util.function.FunctionWithException<? super T,​Boolean,​? extends Exception> condition,
                                                                                                                                                                 org.apache.flink.util.function.FunctionWithException<? super T,​? extends U,​? extends Exception> actionIfTrue,
                                                                                                                                                                 org.apache.flink.util.function.FunctionWithException<? super T,​? extends V,​? extends Exception> actionIfFalse)
        Specified by:
        thenConditionallyApply in interface org.apache.flink.api.common.state.v2.StateFuture<T>
      • thenConditionallyApply

        public <U> org.apache.flink.api.common.state.v2.StateFuture<org.apache.flink.api.java.tuple.Tuple2<Boolean,​U>> thenConditionallyApply​(org.apache.flink.util.function.FunctionWithException<? super T,​Boolean,​? extends Exception> condition,
                                                                                                                                                    org.apache.flink.util.function.FunctionWithException<? super T,​? extends U,​? extends Exception> actionIfTrue)
        Specified by:
        thenConditionallyApply in interface org.apache.flink.api.common.state.v2.StateFuture<T>
      • thenConditionallyAccept

        public org.apache.flink.api.common.state.v2.StateFuture<Boolean> thenConditionallyAccept​(org.apache.flink.util.function.FunctionWithException<? super T,​Boolean,​? extends Exception> condition,
                                                                                                 org.apache.flink.util.function.ThrowingConsumer<? super T,​? extends Exception> actionIfTrue,
                                                                                                 org.apache.flink.util.function.ThrowingConsumer<? super T,​? extends Exception> actionIfFalse)
        Specified by:
        thenConditionallyAccept in interface org.apache.flink.api.common.state.v2.StateFuture<T>
      • thenConditionallyAccept

        public org.apache.flink.api.common.state.v2.StateFuture<Boolean> thenConditionallyAccept​(org.apache.flink.util.function.FunctionWithException<? super T,​Boolean,​? extends Exception> condition,
                                                                                                 org.apache.flink.util.function.ThrowingConsumer<? super T,​? extends Exception> actionIfTrue)
        Specified by:
        thenConditionallyAccept in interface org.apache.flink.api.common.state.v2.StateFuture<T>
      • thenConditionallyCompose

        public <U,​V> org.apache.flink.api.common.state.v2.StateFuture<org.apache.flink.api.java.tuple.Tuple2<Boolean,​Object>> thenConditionallyCompose​(org.apache.flink.util.function.FunctionWithException<? super T,​Boolean,​? extends Exception> condition,
                                                                                                                                                                   org.apache.flink.util.function.FunctionWithException<? super T,​? extends org.apache.flink.api.common.state.v2.StateFuture<U>,​? extends Exception> actionIfTrue,
                                                                                                                                                                   org.apache.flink.util.function.FunctionWithException<? super T,​? extends org.apache.flink.api.common.state.v2.StateFuture<V>,​? extends Exception> actionIfFalse)
        Specified by:
        thenConditionallyCompose in interface org.apache.flink.api.common.state.v2.StateFuture<T>
      • thenConditionallyCompose

        public <U> org.apache.flink.api.common.state.v2.StateFuture<org.apache.flink.api.java.tuple.Tuple2<Boolean,​U>> thenConditionallyCompose​(org.apache.flink.util.function.FunctionWithException<? super T,​Boolean,​? extends Exception> condition,
                                                                                                                                                      org.apache.flink.util.function.FunctionWithException<? super T,​? extends org.apache.flink.api.common.state.v2.StateFuture<U>,​? extends Exception> actionIfTrue)
        Specified by:
        thenConditionallyCompose in interface org.apache.flink.api.common.state.v2.StateFuture<T>
      • makeNewStateFuture

        public <A> StateFutureImpl<A> makeNewStateFuture()
        Make a new future based on context of this future. Subclasses need to overload this method to generate their own instances (if needed).
        Returns:
        the new created future.
      • isDone

        public boolean isDone()
        Description copied from interface: InternalStateFuture
        Returns true if completed in any fashion: normally, exceptionally, or via cancellation.
        Specified by:
        isDone in interface InternalStateFuture<T>
        Returns:
        true if completed
      • get

        public T get()
        Description copied from interface: InternalStateFuture
        Waits if necessary for the computation to complete, and then retrieves its result.
        Specified by:
        get in interface InternalStateFuture<T>
      • callbackRegistered

        public void callbackRegistered()
        Will be triggered when a callback is registered.
      • postComplete

        public void postComplete​(boolean inCallbackRunner)
        Will be triggered when this future completes.
      • callbackFinished

        public void callbackFinished()
        Will be triggered when a callback finishes processing.
      • thenSyncAccept

        public void thenSyncAccept​(org.apache.flink.util.function.ThrowingConsumer<? super T,​? extends Exception> action)
        Description copied from interface: InternalStateFuture
        Accept the action in the same thread with the one of complete (or current thread if it has been completed).
        Specified by:
        thenSyncAccept in interface InternalStateFuture<T>
        Parameters:
        action - the action to perform.