Class CompletedOperationCache<K extends OperationKey,R extends Serializable>
- java.lang.Object
-
- org.apache.flink.runtime.rest.handler.async.CompletedOperationCache<K,R>
-
- All Implemented Interfaces:
AutoCloseable
,AutoCloseableAsync
@ThreadSafe public class CompletedOperationCache<K extends OperationKey,R extends Serializable> extends Object implements AutoCloseableAsync
Cache to manage ongoing operations.The cache allows to register ongoing operations by calling
#registerOngoingOperation(K, CompletableFuture)
, where theCompletableFuture
contains the operation result. Completed operations will be removed from the cache automatically after a fixed timeout.
-
-
Constructor Summary
Constructors Constructor Description CompletedOperationCache(Duration cacheDuration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableFuture<Void>
closeAsync()
Trigger the closing of the resource and return the corresponding close future.boolean
containsOperation(K operationKey)
Returns whether this cache contains an operation under the given operation key.Optional<OperationResult<R>>
get(K operationKey)
Returns an optional containing theOperationResult
for the specified key, or an empty optional if no operation is registered under the key.void
registerOngoingOperation(K operationKey, CompletableFuture<R> operationResultFuture)
Registers an ongoing operation with the cache.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.flink.util.AutoCloseableAsync
close
-
-
-
-
Constructor Detail
-
CompletedOperationCache
public CompletedOperationCache(Duration cacheDuration)
-
-
Method Detail
-
registerOngoingOperation
public void registerOngoingOperation(K operationKey, CompletableFuture<R> operationResultFuture)
Registers an ongoing operation with the cache.- Parameters:
operationResultFuture
- A future containing the operation result.- Throws:
IllegalStateException
- if the cache is already shutting down
-
containsOperation
public boolean containsOperation(K operationKey)
Returns whether this cache contains an operation under the given operation key.
-
get
public Optional<OperationResult<R>> get(K operationKey)
Returns an optional containing theOperationResult
for the specified key, or an empty optional if no operation is registered under the key.
-
closeAsync
public CompletableFuture<Void> closeAsync()
Description copied from interface:AutoCloseableAsync
Trigger the closing of the resource and return the corresponding close future.- Specified by:
closeAsync
in interfaceAutoCloseableAsync
- Returns:
- Future which is completed once the resource has been closed
-
-