Package org.apache.flink.core.state
Class StateFutureImpl<T>
- java.lang.Object
-
- org.apache.flink.core.state.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 ofStateFuture. 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 theCompletableFuture. In the basic version of this implementation, we wrapCompletableFuturefor 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceStateFutureImpl.AsyncFrameworkExceptionHandlerHandle exceptions thrown by async state callback framework.static interfaceStateFutureImpl.CallbackRunnerThe entry for a state future to submit task to mailbox.
-
Field Summary
Fields Modifier and Type Field Description protected StateFutureImpl.CallbackRunnercallbackRunnerThe callback runner.protected StateFutureImpl.AsyncFrameworkExceptionHandlerexceptionHandlerThe exception handler that handles callback framework's error.
-
Constructor Summary
Constructors Constructor Description StateFutureImpl(StateFutureImpl.CallbackRunner callbackRunner, StateFutureImpl.AsyncFrameworkExceptionHandler exceptionHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcallbackFinished()Will be triggered when a callback finishes processing.voidcallbackRegistered()Will be triggered when a callback is registered.voidcomplete(T result)Complete this future.voidcompleteExceptionally(String message, Throwable ex)Fail this future and pass the given exception to the runtime.<A> StateFutureImpl<A>makeNewStateFuture()Make a new future based on context of this future.voidpostComplete(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)voidthenSyncAccept(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).
-
-
-
Field Detail
-
callbackRunner
protected final StateFutureImpl.CallbackRunner callbackRunner
The callback runner.
-
exceptionHandler
protected final StateFutureImpl.AsyncFrameworkExceptionHandler exceptionHandler
The exception handler that handles callback framework's error.
-
-
Constructor Detail
-
StateFutureImpl
public StateFutureImpl(StateFutureImpl.CallbackRunner callbackRunner, StateFutureImpl.AsyncFrameworkExceptionHandler exceptionHandler)
-
-
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:
thenApplyin interfaceorg.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:
thenAcceptin interfaceorg.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:
thenComposein interfaceorg.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:
thenCombinein interfaceorg.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.
-
complete
public void complete(T result)
Description copied from interface:InternalStateFutureComplete this future.- Specified by:
completein interfaceInternalStateFuture<T>
-
completeExceptionally
public void completeExceptionally(String message, Throwable ex)
Description copied from interface:InternalStateFutureFail this future and pass the given exception to the runtime.- Specified by:
completeExceptionallyin interfaceInternalStateFuture<T>- Parameters:
message- the description of this exceptionex- the exception
-
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:InternalStateFutureAccept the action in the same thread with the one of complete (or current thread if it has been completed).- Specified by:
thenSyncAcceptin interfaceInternalStateFuture<T>- Parameters:
action- the action to perform.
-
-