Package io.aether.utils.rcollections
Class BMapImpl<K,V>
- java.lang.Object
-
- io.aether.utils.rcollections.BMapImpl<K,V>
-
- Type Parameters:
K- The type of the key.V- The type of the value to be retrieved asynchronously.
- All Implemented Interfaces:
Destroyable,BMap<K,V>,RFMap<K,V>,RMap<K,ARFutureWithFlag<V>>,java.util.Map<K,ARFutureWithFlag<V>>
public class BMapImpl<K,V> extends java.lang.Object implements BMap<K,V>
Implementation of BMap that manages request throttling and exposure of pending requests for integration with a batching/flushing mechanism (like in AetherCloudClient), supporting multiple concurrent request senders.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K extends java.lang.Object,V extends java.lang.Object>
-
Nested classes/interfaces inherited from interface io.aether.utils.rcollections.RMap
RMap.Update<K,V>
-
-
Constructor Summary
Constructors Constructor Description BMapImpl(int initialCapacity, java.lang.String name, long timeoutMs)Constructs a new BMapImpl.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)AFuturedestroy(boolean force)Initiates the destruction process.@NotNull RSet<java.util.Map.Entry<K,ARFutureWithFlag<V>>>entrySet()EventConsumer<java.util.Map.Entry<K,ARFutureWithFlag<V>>>forRemove()EventConsumer<RMap.Update<K,ARFutureWithFlag<V>>>forUpdate()EventConsumer<RMap.Update<K,V>>forValueUpdate()Returns an EventConsumer that fires when a value in the map is definitively resolved.ARFutureWithFlag<V>get(java.lang.Object key)@NotNull ARFutureWithFlag<V>getFuture(K key)Retrieves the ARFutureWithFlag associated with the key.@NotNull java.util.Set<K>getPendingRequests()Returns a set of keys that currently require fetching from the external service.K[]getRequestsFor(java.lang.Class<K> elementType, java.lang.Object sender)Returns an array of keys that are queued for network submission by this specific sender.booleanisEmpty()booleanisRequests()Checks if there is any work available globally (e.g., items in the new request pool).booleanisRequestsFor(@NotNull java.lang.Object sender)Checks if there are any pending requests (newly available or timed-out) for the specified sender.@NotNull RSet<K>keySet()@Nullable ARFutureWithFlag<V>put(K key, ARFutureWithFlag<V> value)voidputError(K key, @NotNull java.lang.Throwable error)Marks the future for a key as completed with an error.voidputResolved(K key, @NotNull AConsumer<V> updater, V value)voidputResolved(K key, V value)Puts a fully resolved value into the map, immediately fulfilling any waiting future.ARFutureWithFlag<V>remove(java.lang.Object key)intsize()@NotNull RCollection<ARFutureWithFlag<V>>values()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Methods inherited from interface io.aether.utils.rcollections.RFMap
mapFuture, mapKeyFuture, mapValFuture
-
Methods inherited from interface io.aether.utils.rcollections.RMap
clear, link, map, mapKey, mapToFutures, mapToValues, mapVal, mapVal, putAll
-
-
-
-
Constructor Detail
-
BMapImpl
public BMapImpl(int initialCapacity, java.lang.String name, long timeoutMs)Constructs a new BMapImpl.- Parameters:
initialCapacity- The initial capacity for the internal map.name- A descriptive name (not used in this implementation).timeoutMs- The request timeout duration in milliseconds (not used in this implementation).
-
-
Method Detail
-
getFuture
@NotNull public @NotNull ARFutureWithFlag<V> getFuture(@NotNull K key)
Description copied from interface:BMapRetrieves the ARFutureWithFlag associated with the key. If the value is not present or the previous request has timed out, this method must conditionally add the key to the new request pool for later batching by a separateflushmechanism.
-
getPendingRequests
@NotNull public @NotNull java.util.Set<K> getPendingRequests()
Description copied from interface:BMapReturns a set of keys that currently require fetching from the external service. This method is designed for systems needing exclusive control over batching and clears the internal pool of newly requested keys upon return.- Specified by:
getPendingRequestsin interfaceBMap<K,V>- Returns:
- A Set of keys that were queued for network submission.
-
putResolved
public void putResolved(@NotNull K key, @NotNull V value)Description copied from interface:BMapPuts a fully resolved value into the map, immediately fulfilling any waiting future.- Specified by:
putResolvedin interfaceBMap<K,V>- Parameters:
key- The key for the resolved value.value- The resolved value.
-
putResolved
public void putResolved(@NotNull K key, @NotNull @NotNull AConsumer<V> updater, V value)- Specified by:
putResolvedin interfaceBMap<K,V>
-
putError
public void putError(@NotNull K key, @NotNull @NotNull java.lang.Throwable error)Description copied from interface:BMapMarks the future for a key as completed with an error.
-
forValueUpdate
public EventConsumer<RMap.Update<K,V>> forValueUpdate()
Description copied from interface:BMapReturns an EventConsumer that fires when a value in the map is definitively resolved.- Specified by:
forValueUpdatein interfaceBMap<K,V>- Returns:
- The EventConsumer for resolved value updates (K, V).
-
getRequestsFor
public K[] getRequestsFor(java.lang.Class<K> elementType, java.lang.Object sender)
Description copied from interface:BMapReturns an array of keys that are queued for network submission by this specific sender. This array includes keys that are newly available and keys for which this sender's previous request has timed out.The implementing class is responsible for transferring new requests and updating the sender's flush time during this call.
- Specified by:
getRequestsForin interfaceBMap<K,V>- Parameters:
elementType- The Class of the key type for array creation (often K.class).sender- The object responsible for sending the network request (e.g., ConnectionWork).- Returns:
- An array of keys (K[]) that are queued for network submission by this sender.
-
isRequests
public boolean isRequests()
Description copied from interface:BMapChecks if there is any work available globally (e.g., items in the new request pool). This method is a fast check intended to avoid unnecessary work.- Specified by:
isRequestsin interfaceBMap<K,V>- Returns:
- True if work might be available globally, false otherwise.
-
isRequestsFor
public boolean isRequestsFor(@NotNull @NotNull java.lang.Object sender)Description copied from interface:BMapChecks if there are any pending requests (newly available or timed-out) for the specified sender. This method is a fast check intended to avoid unnecessary calls togetRequestsFor.- Specified by:
isRequestsForin interfaceBMap<K,V>- Parameters:
sender- The sender object.- Returns:
- True if work might be available for this sender, false otherwise.
-
destroy
public AFuture destroy(boolean force)
Description copied from interface:DestroyableInitiates the destruction process.- Specified by:
destroyin interfaceDestroyable- Parameters:
force- If true, forces the destruction; otherwise, attempts a graceful shutdown.- Returns:
- An AFuture representing the result of the destruction process.
-
forUpdate
public EventConsumer<RMap.Update<K,ARFutureWithFlag<V>>> forUpdate()
-
forRemove
public EventConsumer<java.util.Map.Entry<K,ARFutureWithFlag<V>>> forRemove()
-
containsKey
public boolean containsKey(java.lang.Object key)
-
containsValue
public boolean containsValue(java.lang.Object value)
-
get
public ARFutureWithFlag<V> get(java.lang.Object key)
-
put
@Nullable public @Nullable ARFutureWithFlag<V> put(K key, ARFutureWithFlag<V> value)
-
remove
public ARFutureWithFlag<V> remove(java.lang.Object key)
-
values
@NotNull public @NotNull RCollection<ARFutureWithFlag<V>> values()
-
-