Class AsyncNamedCacheClient<K,​V>

  • Type Parameters:
    K - the type of the cache keys
    V - the type of the cache values
    All Implemented Interfaces:
    com.tangosol.net.AsyncNamedCache<K,​V>, com.tangosol.net.AsyncNamedMap<K,​V>

    public class AsyncNamedCacheClient<K,​V>
    extends BaseGrpcClient<V>
    implements com.tangosol.net.AsyncNamedCache<K,​V>
    Implementation of a NamedCache.
    Since:
    20.06
    Author:
    Jonathan Knight 2019.11.22
    • Field Detail

      • VOID

        protected static final Void VOID
        A constant value to use for Void values.
      • f_synchronousCache

        protected final NamedCacheClient<K,​V> f_synchronousCache
        The synchronous version of this client.
      • f_listCacheDeactivationListeners

        protected final List<com.tangosol.internal.net.NamedCacheDeactivationListener> f_listCacheDeactivationListeners
        The list of NamedCacheDeactivationListener instances added to this client.
      • f_lockDeactivationListeners

        protected final Lock f_lockDeactivationListeners
      • m_listenerSupport

        protected com.tangosol.util.MapListenerSupport m_listenerSupport
        The map listener support.
      • m_aEvtFilter

        protected com.tangosol.util.LongArray<com.tangosol.util.Filter<?>> m_aEvtFilter
        The array of filter.
    • Method Detail

      • getNamedCache

        public com.tangosol.net.NamedCache<K,​V> getNamedCache()
        Specified by:
        getNamedCache in interface com.tangosol.net.AsyncNamedCache<K,​V>
      • getNamedMap

        public com.tangosol.net.NamedMap<K,​V> getNamedMap()
        Specified by:
        getNamedMap in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • aggregate

        public <R> CompletableFuture<R> aggregate​(Collection<? extends K> colKeys,
                                                  com.tangosol.util.InvocableMap.EntryAggregator<? super K,​? super V,​R> entryAggregator)
        Specified by:
        aggregate in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • aggregate

        public <R> CompletableFuture<R> aggregate​(com.tangosol.util.Filter<?> filter,
                                                  com.tangosol.util.InvocableMap.EntryAggregator<? super K,​? super V,​R> entryAggregator)
        Specified by:
        aggregate in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • invoke

        public <R> CompletableFuture<R> invoke​(K k,
                                               com.tangosol.util.InvocableMap.EntryProcessor<K,​V,​R> entryProcessor)
        Specified by:
        invoke in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • invokeAll

        public <R> CompletableFuture<Map<K,​R>> invokeAll​(Collection<? extends K> colKeys,
                                                               com.tangosol.util.InvocableMap.EntryProcessor<K,​V,​R> processor)
        Specified by:
        invokeAll in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • invokeAll

        public <R> CompletableFuture<Map<K,​R>> invokeAll​(com.tangosol.util.Filter<?> filter,
                                                               com.tangosol.util.InvocableMap.EntryProcessor<K,​V,​R> processor)
        Specified by:
        invokeAll in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • invokeAll

        public <R> CompletableFuture<Void> invokeAll​(Collection<? extends K> colKeys,
                                                     com.tangosol.util.InvocableMap.EntryProcessor<K,​V,​R> processor,
                                                     Consumer<? super Map.Entry<? extends K,​? extends R>> callback)
        Specified by:
        invokeAll in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • invokeAll

        public <R> CompletableFuture<Void> invokeAll​(com.tangosol.util.Filter<?> filter,
                                                     com.tangosol.util.InvocableMap.EntryProcessor<K,​V,​R> processor,
                                                     Consumer<? super Map.Entry<? extends K,​? extends R>> callback)
        Specified by:
        invokeAll in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • clear

        public CompletableFuture<Void> clear()
        Specified by:
        clear in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • containsKey

        public CompletableFuture<Boolean> containsKey​(K key)
        Specified by:
        containsKey in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • get

        public CompletableFuture<V> get​(K key)
        Specified by:
        get in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • getOrDefault

        public CompletableFuture<V> getOrDefault​(K key,
                                                 V defaultValue)
        Specified by:
        getOrDefault in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • invokeAll

        public <R> CompletableFuture<Map<K,​R>> invokeAll​(com.tangosol.util.InvocableMap.EntryProcessor<K,​V,​R> processor)
        Specified by:
        invokeAll in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • invokeAll

        public <R> CompletableFuture<Void> invokeAll​(com.tangosol.util.InvocableMap.EntryProcessor<K,​V,​R> processor,
                                                     Consumer<? super Map.Entry<? extends K,​? extends R>> callback)
        Specified by:
        invokeAll in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • invokeAll

        public <R> CompletableFuture<Void> invokeAll​(com.tangosol.util.InvocableMap.EntryProcessor<K,​V,​R> processor,
                                                     BiConsumer<? super K,​? super R> callback)
        Specified by:
        invokeAll in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • invokeAll

        public <R> CompletableFuture<Void> invokeAll​(Collection<? extends K> colKeys,
                                                     com.tangosol.util.InvocableMap.EntryProcessor<K,​V,​R> processor,
                                                     BiConsumer<? super K,​? super R> callback)
        Specified by:
        invokeAll in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • invokeAll

        public <R> CompletableFuture<Void> invokeAll​(com.tangosol.util.Filter<?> filter,
                                                     com.tangosol.util.InvocableMap.EntryProcessor<K,​V,​R> processor,
                                                     BiConsumer<? super K,​? super R> callback)
        Specified by:
        invokeAll in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • isEmpty

        public CompletableFuture<Boolean> isEmpty()
        Specified by:
        isEmpty in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • keySet

        public CompletableFuture<Set<K>> keySet()
        Specified by:
        keySet in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • put

        public CompletableFuture<Void> put​(K key,
                                           V value)
        Specified by:
        put in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • put

        public CompletableFuture<Void> put​(K key,
                                           V value,
                                           long ttl)
        Specified by:
        put in interface com.tangosol.net.AsyncNamedCache<K,​V>
      • putIfAbsent

        public CompletableFuture<V> putIfAbsent​(K key,
                                                V value)
        Specified by:
        putIfAbsent in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • putAll

        public CompletableFuture<Void> putAll​(Map<? extends K,​? extends V> map)
        Specified by:
        putAll in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • putAll

        public CompletableFuture<Void> putAll​(Map<? extends K,​? extends V> map,
                                              long cMillis)
        Specified by:
        putAll in interface com.tangosol.net.AsyncNamedCache<K,​V>
      • remove

        public CompletableFuture<V> remove​(K key)
        Specified by:
        remove in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • remove

        public CompletableFuture<Boolean> remove​(K key,
                                                 V value)
        Specified by:
        remove in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • replace

        public CompletableFuture<V> replace​(K key,
                                            V value)
        Specified by:
        replace in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • replace

        public CompletableFuture<Boolean> replace​(K key,
                                                  V oldValue,
                                                  V newValue)
        Specified by:
        replace in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • values

        public CompletableFuture<Collection<V>> values​(com.tangosol.util.Filter<?> filter,
                                                       Comparator<? super V> comparator)
        Specified by:
        values in interface com.tangosol.net.AsyncNamedMap<K,​V>
      • getAllInternal

        protected Stream<Entry> getAllInternal​(Collection<? extends K> colKeys)
        Helper method to obtain a Collection of Entry instances for the specified keys as a Stream.
        Parameters:
        colKeys - the keys to look up
        Returns:
        a Stream of Entry instances for the keys found in the cache
      • getAllInternalAsMap

        protected Map<K,​V> getAllInternalAsMap​(Collection<? extends K> colKeys)
        Helper method to obtain a Map of the keys/values found within the cache matching the provided Collection of keys.
        Parameters:
        colKeys - the keys to look up
        Returns:
        a Map containing keys/values for the keys found within the cache
      • getScopeName

        protected String getScopeName()
        Returns the scope name.
        Returns:
        the scope name
      • getCacheName

        protected String getCacheName()
        Returns the cache name.
        Returns:
        the cache name
      • getCacheService

        protected com.tangosol.net.CacheService getCacheService()
        Get the CacheService associated with this cache.
        Returns:
        the CacheService associated with this cache
      • setCacheService

        protected void setCacheService​(GrpcRemoteCacheService cacheService)
        Set the CacheService associated with this cache.
        Parameters:
        cacheService - the CacheService associated with this cache
      • getInternal

        protected CompletableFuture<V> getInternal​(Object key,
                                                   V defaultValue)
        Helper method for getting a value from the cache.
        Parameters:
        key - the key
        defaultValue - the value to return if this cache doesn't contain the provided key
        Returns:
        the value within the Cache, or defaultValue
      • getNamedCacheClient

        public NamedCacheClient<K,​V> getNamedCacheClient()
        Return the synchronous cache client.
        Returns:
        the synchronous cache client
      • invokeAllInternal

        protected void invokeAllInternal​(InvokeAllRequest request,
                                         io.grpc.stub.StreamObserver<Entry> observer)
        Helper method to perform invokeAll operations.
        Parameters:
        request - the InvokeAllRequest
        observer - the StreamObserver
      • invokeAllInternal

        protected void invokeAllInternal​(InvokeAllRequest request,
                                         io.grpc.stub.StreamObserver<Entry> observer,
                                         long nDeadline)
        Helper method to perform invokeAll operations.
        Parameters:
        request - the InvokeAllRequest
        observer - the StreamObserver
      • isActive

        protected CompletableFuture<Boolean> isActive()
        Return true if the cache is still active.
        Returns:
        true if the cache is still active
      • isReady

        protected CompletableFuture<Boolean> isReady()
        Returns whether this cache is ready to be used.

        An example of when this method would return false would be where a partitioned cache service that owns this cache has no store-enabled members.
        Returns:
        true if the cache is ready
        Since:
        14.1.1.2206.5
      • putInternal

        protected CompletableFuture<V> putInternal​(K key,
                                                   V value,
                                                   long cTtl)
        Helper method for storing a key/value pair within the cache.
        Parameters:
        key - the key
        value - the value
        cTtl - the time-to-live (may not be supported)
        Returns:
        a CompletableFuture returning the value previously associated with the specified key, if any
      • putAllInternal

        protected CompletableFuture<com.google.protobuf.Empty> putAllInternal​(Map<? extends K,​? extends V> map,
                                                                              long cMillis)
        Helper method for storing the contents of the provided map within the cache.
        Parameters:
        map - the Map of key/value pairs to store in the cache.
        cMillis - the expiry delay t apply to the entries
        Returns:
        a CompletableFuture
      • removeIndex

        protected <T,​E> CompletableFuture<Void> removeIndex​(com.tangosol.util.ValueExtractor<? super T,​? extends E> valueExtractor)
      • removeInternal

        protected CompletableFuture<V> removeInternal​(Object key)
        Remove the mapping for the given key, returning the associated value.
        Parameters:
        key - key whose mapping is to be removed from the map
        Returns:
        the value associated with the given key, or null if no mapping existed
      • removeInternal

        protected CompletableFuture<Boolean> removeInternal​(Object key,
                                                            Object value)
        Removes the entry for the specified key only if it is currently mapped to the specified value.
        Parameters:
        key - key with which the specified value is associated
        value - value expected to be associated with the specified key
        Returns:
        a CompletableFuture returning a boolean indicating whether the mapping was removed
      • removeMapListener

        protected CompletableFuture<Void> removeMapListener​(com.tangosol.util.MapListener<? super K,​? super V> mapListener)
        Removes the specified MapListener.
        Parameters:
        mapListener - the MapListener to remove
        Returns:
        a CompletableFuture returning Void
      • removeMapListener

        protected CompletableFuture<Void> removeMapListener​(com.tangosol.util.MapListener<? super K,​? super V> listener,
                                                            K key)
        Removes the MapListener associated with the specified key.
        Parameters:
        listener - the MapListener to remove
        key - the key the listener is associated with
        Returns:
        a CompletableFuture returning Void
      • removeMapListener

        protected CompletableFuture<Void> removeMapListener​(com.tangosol.util.MapListener<? super K,​? super V> listener,
                                                            com.tangosol.util.Filter<?> filter)
        Removes the MapListener associated with the specified Filter.
        Parameters:
        listener - the MapListener to remove
        filter - the filter the listener is associated with
        Returns:
        a CompletableFuture returning Void
      • removeRemoteFilterListener

        protected CompletableFuture<Void> removeRemoteFilterListener​(com.google.protobuf.ByteString filterBytes,
                                                                     long nFilterId,
                                                                     com.google.protobuf.ByteString triggerBytes)
        Sends the serialized Filter for un-registration with the cache server.
        Parameters:
        filterBytes - the serialized bytes of the Filter
        nFilterId - the ID of the Filter
        triggerBytes - the serialized bytes of the MapTriggerListener; pass ByteString.EMPTY if there is no trigger listener.
        Returns:
        CompletableFuture returning type Void
      • stream

        protected Stream<com.tangosol.util.InvocableMap.Entry<K,​V>> stream()
        Stream all entries within the cache.
        Returns:
        a Stream for processing entries within the cache.
      • stream

        protected Stream<com.tangosol.util.InvocableMap.Entry<K,​V>> stream​(com.tangosol.util.Filter<V> filter)
        Stream which filters the cache entries.
        Parameters:
        filter - the filter to apply to the Stream
        Returns:
        a Stream for processing entries within the cache.
        Throws:
        UnsupportedOperationException - this method is unsupported
      • truncate

        protected CompletableFuture<Void> truncate()
        Removes all mappings from this map.

        Note: the removal of entries caused by this truncate operation will not be observable. This includes any registered listeners, triggers, or interceptors. However, a CacheLifecycleEvent is raised to notify subscribers of the execution of this operation.

        Returns:
        a CompletableFuture returning Void
      • valuesInternal

        protected CompletableFuture<Collection<V>> valuesInternal​(com.tangosol.util.Filter<?> filter,
                                                                  Comparator comparator)
        Helper method to return the values of the cache.
        Parameters:
        filter - the Filter to apply
        comparator - the Comparator for ordering
        Returns:
        a Collection of values based on the provided Filter and Comparator
      • containsValue

        protected CompletableFuture<Boolean> containsValue​(Object oValue)
        Helper method for confirm presence of the value within the cache.
        Parameters:
        oValue - the value to check
        Returns:
        a CompletableFuture returning true if the cache contains the given value
      • getMapListenerSupport

        protected com.tangosol.util.MapListenerSupport getMapListenerSupport()
        Return the MapListenerSupport.
        Returns:
        the MapListenerSupport
      • initEvents

        protected void initEvents()
        Called by the constructor to initialize event support.
      • getFormat

        protected String getFormat()
        Return the serialization format.
        Returns:
        the serialization format
      • getKeysPage

        protected Stream<com.google.protobuf.BytesValue> getKeysPage​(com.google.protobuf.BytesValue cookie)
        Obtain a page of cache keys.
        Parameters:
        cookie - an opaque cooke used to determine the current page
        Returns:
        a page of cache keys
      • getEntriesPage

        protected Stream<EntryResult> getEntriesPage​(com.google.protobuf.ByteString cookie)
        Obtain a page of cache entries.
        Parameters:
        cookie - an opaque cooke used to determine the current page
        Returns:
        a page of cache entries
      • containsEntry

        protected boolean containsEntry​(K key,
                                        V value)
        Determine whether en entry exists in the cache with the specified key and value.
        Parameters:
        key - the cache key
        value - the cache value
        Returns:
        a page of cache keys
      • createDeactivationEvent

        protected <Ke,​Ve> com.tangosol.net.cache.CacheEvent<Ke,​Ve> createDeactivationEvent​(boolean destroyed)
        Helper method to create a new CacheEvent to signal cache truncation or destruction.
        Type Parameters:
        Ke - the CacheEvent key type
        Ve - the CacheEvent value type
        Parameters:
        destroyed - true if this event should represent a cache being destroyed
        Returns:
        a new CacheEvent to signal cache truncation or destruction
      • addDeactivationListener

        public void addDeactivationListener​(com.tangosol.internal.net.NamedCacheDeactivationListener listener)
        Add a NamedCacheDeactivationListener that will be notified when this AsyncNamedCacheClient is released or destroyed.
        Parameters:
        listener - the listener to add
      • addIndex

        protected <T,​E> CompletableFuture<Void> addIndex​(com.tangosol.util.ValueExtractor<? super T,​? extends E> extractor,
                                                               boolean fOrdered,
                                                               Comparator<? super E> comparator)
        Asynchronous implementation of QueryMap.addIndex(com.tangosol.util.ValueExtractor<? super T, ? extends E>, boolean, java.util.Comparator<? super E>).
        Type Parameters:
        T - the type of the value to extract from
        E - the type of value that will be extracted
        Parameters:
        extractor - the ValueExtractor object that is used to extract an indexable Object from a value stored in the indexed Map. Must not be null
        fOrdered - true iff the contents of the indexed information should be ordered; false otherwise
        comparator - the Comparator object which imposes an ordering on entries in the indexed map; or null if the entries' values natural ordering should be used
        Returns:
        CompletableFuture returning type Void
      • addMapListener

        protected CompletableFuture<Void> addMapListener​(com.tangosol.util.MapListener<? super K,​? super V> mapListener)
        Add a standard map listener that will receive all events (inserts, updates, deletes) that occur against the map, with the key, old-value and new-value included
        Parameters:
        mapListener - the MapEvent listener to add
        Returns:
        CompletableFuture returning type Void
      • addMapListener

        protected CompletableFuture<Void> addMapListener​(com.tangosol.util.MapListener<? super K,​? super V> mapListener,
                                                         K key,
                                                         boolean fLite)
        Add a map listener for a specific key.

        The listeners will receive MapEvent objects, but if fLite is passed as true, they might not contain the OldValue and NewValue properties.

        Parameters:
        mapListener - the MapEvent listener to add
        key - the key that identifies the entry for which to raise events
        fLite - true to indicate that the MapEvent objects do not have to include the OldValue and NewValue property values in order to allow optimizations
        Returns:
        CompletableFuture returning type Void
      • addMapListener

        protected CompletableFuture<Void> addMapListener​(com.tangosol.util.MapListener<? super K,​? super V> mapListener,
                                                         com.tangosol.util.Filter<?> filter,
                                                         boolean fLite)
        Add a map listener that receives events based on a filter evaluation.

        The listeners will receive MapEvent objects, but if fLite is passed as true, they might not contain the OldValue and NewValue properties.

        Parameters:
        mapListener - the MapEvent listener to add
        filter - a filter that will be passed MapEvent objects to select from; a MapEvent will be delivered to the listener only if the filter evaluates to true for that MapEvent (see MapEventFilter); null is equivalent to a filter that always returns true
        fLite - true to indicate that the MapEvent objects do not have to include the OldValue and NewValue property values in order to allow optimizations
        Returns:
        CompletableFuture returning type Void
      • addKeyMapListener

        protected CompletableFuture<Void> addKeyMapListener​(com.tangosol.util.MapListener<? super K,​? super V> listener,
                                                            Object key,
                                                            boolean fLite)
        Add a map listener for a specific key.

        The listeners will receive MapEvent objects, but if fLite is passed as true, they might not contain the OldValue and NewValue properties.

        Parameters:
        listener - the MapEvent listener to add
        key - the key that identifies the entry for which to raise events
        fLite - true to indicate that the MapEvent objects do not have to include the OldValue and NewValue property values in order to allow optimizations
        Returns:
        CompletableFuture returning type Void
      • addFilterMapListener

        protected CompletableFuture<Void> addFilterMapListener​(com.tangosol.util.MapListener<? super K,​? super V> listener,
                                                               com.tangosol.util.Filter<?> filter,
                                                               boolean fLite)
        Add a map listener that receives events based on a filter evaluation.

        The listeners will receive MapEvent objects, but if fLite is passed as true, they might not contain the OldValue and NewValue properties.

        Parameters:
        listener - the MapEvent listener to add
        filter - a filter that will be passed MapEvent objects to select from; a MapEvent will be delivered to the listener only if the filter evaluates to true for that MapEvent (see MapEventFilter); null is equivalent to a filter that always returns true
        fLite - true to indicate that the MapEvent objects do not have to include the OldValue and NewValue property values in order to allow optimizations
        Returns:
        CompletableFuture returning type Void
      • addRemoteFilterListener

        protected CompletableFuture<Void> addRemoteFilterListener​(com.google.protobuf.ByteString filterBytes,
                                                                  long nFilterId,
                                                                  boolean fLite,
                                                                  com.google.protobuf.ByteString triggerBytes)
        Sends the serialized Filter for registration with the cache server.
        Parameters:
        filterBytes - the serialized bytes of the Filter
        nFilterId - the ID of the Filter
        fLite - true to indicate that the MapEvent objects do not have to include the OldValue and NewValue property values in order to allow optimizations
        triggerBytes - the serialized bytes of the MapTriggerListener; pass ByteString.EMPTY if there is no trigger listener.
        Returns:
        CompletableFuture returning type Void
      • registerFilter

        protected long registerFilter​(com.tangosol.util.Filter<?> filter)
        Register the Filter locally.
        Parameters:
        filter - the Filter
        Returns:
        the registration ID of the Filter
      • getFilterId

        protected long getFilterId​(com.tangosol.util.Filter<?> filter)
        Obtain the registration ID for the provided filter.
        Parameters:
        filter - the filter whose ID it is to look up
        Returns:
        the registration ID or zero if the filter hasn't been registered
      • dispatch

        protected void dispatch​(MapEventResponse response)
        Dispatch the received MapEventResponse for processing by local listeners.

        This method is taken from code in the TDE RemoteNamedCache.

        Parameters:
        response - the MapEventResponse to process
      • getListenerCount

        public int getListenerCount()
        Return the number of listeners registered with this map.
        Returns:
        the number of listeners registered with this map
      • getEventDispatcher

        protected GrpcCacheLifecycleEventDispatcher getEventDispatcher()
        Returns the event dispatcher for this cache.
        Returns:
        the event dispatcher for this cache
      • handleException

        protected static <T> T handleException​(T result,
                                               Throwable t)
        Returns the arguments unmodified unless the error is a StatusRuntimeException with a status of Status.UNIMPLEMENTED, then an UnsupportedOperationException will be raised instead.
        Type Parameters:
        T - the result type
        Parameters:
        result - the result - ignored
        t - the error, if any
        Returns:
        the result unmodified, or if the error is Status.UNIMPLEMENTED an UnsupportedOperationException will be thrown
        Since:
        14.1.1.2206.5