@ThreadSafe public class CompletedOperationCache<K extends OperationKey,R extends Serializable> extends Object implements AutoCloseableAsync
The cache allows to register ongoing operations by calling #registerOngoingOperation(K,
CompletableFuture)
, where the CompletableFuture
contains the operation result. Completed
operations will be removed from the cache automatically after a fixed timeout.
Constructor and Description |
---|
CompletedOperationCache(Duration cacheDuration) |
Modifier and Type | Method and 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 the
OperationResult 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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close
public CompletedOperationCache(Duration cacheDuration)
public void registerOngoingOperation(K operationKey, CompletableFuture<R> operationResultFuture)
operationResultFuture
- A future containing the operation result.IllegalStateException
- if the cache is already shutting downpublic boolean containsOperation(K operationKey)
public Optional<OperationResult<R>> get(K operationKey)
OperationResult
for the specified key, or an empty
optional if no operation is registered under the key.public CompletableFuture<Void> closeAsync()
AutoCloseableAsync
closeAsync
in interface AutoCloseableAsync
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.