Class 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.
    • 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: BMap
        Retrieves 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 separate flush mechanism.
        Specified by:
        getFuture in interface BMap<K,​V>
        Parameters:
        key - The key.
        Returns:
        An ARFutureWithFlag that represents the eventual completion of the value retrieval.
      • getPendingRequests

        @NotNull
        public @NotNull java.util.Set<K> getPendingRequests()
        Description copied from interface: BMap
        Returns 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:
        getPendingRequests in interface BMap<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: BMap
        Puts a fully resolved value into the map, immediately fulfilling any waiting future.
        Specified by:
        putResolved in interface BMap<K,​V>
        Parameters:
        key - The key for the resolved value.
        value - The resolved value.
      • putError

        public void putError​(@NotNull
                             K key,
                             @NotNull
                             @NotNull java.lang.Throwable error)
        Description copied from interface: BMap
        Marks the future for a key as completed with an error.
        Specified by:
        putError in interface BMap<K,​V>
        Parameters:
        key - The key associated with the error.
        error - The error to complete the future with.
      • forValueUpdate

        public EventConsumer<RMap.Update<K,​V>> forValueUpdate()
        Description copied from interface: BMap
        Returns an EventConsumer that fires when a value in the map is definitively resolved.
        Specified by:
        forValueUpdate in interface BMap<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: BMap
        Returns 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:
        getRequestsFor in interface BMap<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: BMap
        Checks 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:
        isRequests in interface BMap<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: BMap
        Checks 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 to getRequestsFor.
        Specified by:
        isRequestsFor in interface BMap<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: Destroyable
        Initiates the destruction process.
        Specified by:
        destroy in interface Destroyable
        Parameters:
        force - If true, forces the destruction; otherwise, attempts a graceful shutdown.
        Returns:
        An AFuture representing the result of the destruction process.
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<K,​V>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<K,​V>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<K,​V>
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<K,​V>
      • get

        public ARFutureWithFlag<V> get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<K,​V>
      • remove

        public ARFutureWithFlag<V> remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<K,​V>
      • keySet

        @NotNull
        public @NotNull RSet<K> keySet()
        Specified by:
        keySet in interface java.util.Map<K,​V>
        Specified by:
        keySet in interface RMap<K,​V>
      • entrySet

        @NotNull
        public @NotNull RSet<java.util.Map.Entry<K,​ARFutureWithFlag<V>>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<K,​V>
        Specified by:
        entrySet in interface RMap<K,​V>