Class ContinuousQueryCache<K,​V_BACK,​V_FRONT>

  • Type Parameters:
    K - the type of the cache entry keys
    V_BACK - the type of the entry values in the back cache that is used as the source for this ContinuousQueryCache
    V_FRONT - the type of the entry values in this ContinuousQueryCache, which will be the same as V_BACK, unless a transformer is specified when creating this ContinuousQueryCache
    All Implemented Interfaces:
    CacheMap<K,​V_FRONT>, NamedCache<K,​V_FRONT>, NamedCollection, NamedMap<K,​V_FRONT>, Releasable, ConcurrentMap<K,​V_FRONT>, InvocableMap<K,​V_FRONT>, ObservableMap<K,​V_FRONT>, QueryMap<K,​V_FRONT>, AutoCloseable, Map<K,​V_FRONT>

    public class ContinuousQueryCache<K,​V_BACK,​V_FRONT>
    extends AbstractKeySetBasedMap<K,​V_FRONT>
    implements NamedCache<K,​V_FRONT>
    Create a materialized view of a NamedCache using the Coherence Continuous Query capability.

    In addition to providing an up-to-date view of the backing NamedCache, this class supports server-side transformation of cache values. For example, you could create a client-side view of a cache containing Portfolio instances that only contains the value of each portfolio:

    
       NamedCache<String, Portfolio> cache =
             CacheFactory.getTypedCache("portfolio", TypeAssertion.withoutTypeChecking());
       NamedCache<String, Double>    cqc   = new ContinuousQueryCache<>(cache,
                                                                        AlwaysFilter.INSTANCE,
                                                                        Portfolio::getValue);
     
    Since:
    Coherence 3.1
    Author:
    cp 2006.01.19
    • Field Detail

      • STATE_DISCONNECTED

        public static final int STATE_DISCONNECTED
        State: Disconnected state. The content of the ContinuousQueryCache is not fully synchronized with the underlying [clustered] cache. If the value of the ReconnectInterval property is zero, it must be configured (synchronized) before it can be used.
        Since:
        Coherence 3.4
        See Also:
        Constant Field Values
      • STATE_CONFIGURING

        public static final int STATE_CONFIGURING
        State: The ContinuousQueryCache is configuring or re-configuring its listeners and content.
        See Also:
        Constant Field Values
      • STATE_CONFIGURED

        public static final int STATE_CONFIGURED
        State: The ContinuousQueryCache has been configured.
        See Also:
        Constant Field Values
      • STATE_SYNCHRONIZED

        public static final int STATE_SYNCHRONIZED
        State: The ContinuousQueryCache has been configured and fully synchronized.
        See Also:
        Constant Field Values
      • m_sName

        protected String m_sName
        The name of the underlying NamedCache. A copy is kept here because the reference to the underlying NamedCache is discarded when this cache is released.
      • m_filter

        protected Filter m_filter
        The filter that represents the subset of information from the underlying NamedCache that this ContinuousQueryCache represents.
      • m_fCacheValues

        protected boolean m_fCacheValues
        The option of whether or not to locally cache values.
      • m_transformer

        protected ValueExtractor<? super V_BACK,​? extends V_FRONT> m_transformer
        The transformer that should be used to convert values from the underlying cache.
      • m_fReadOnly

        protected boolean m_fReadOnly
        The option to disallow modifications through this ContinuousQueryCache interface.
      • m_cReconnectMillis

        protected long m_cReconnectMillis
        The interval (in milliseconds) that indicates how often the ContinuousQueryCache should attempt to synchronize its content with the underlying cache in case the connection is severed.
      • m_ldtConnectionTimestamp

        protected volatile long m_ldtConnectionTimestamp
        The timestamp when the synchronization was last attempted.
      • m_mapLocal

        protected ObservableMap<K,​V_FRONT> m_mapLocal
        The keys that are in this ContinuousQueryCache, and (if m_fCacheValues is true) the corresponding values as well.
      • m_nState

        protected volatile int m_nState
        State of the ContinuousQueryCache. One of the STATE_* enums.
      • m_mapSyncReq

        protected volatile Map m_mapSyncReq
        While the ContinuousQueryCache is configuring or re-configuring its listeners and content, any events that are received must be logged to ensure that the corresponding content is in sync.
      • m_eventQueue

        protected volatile TaskDaemon m_eventQueue
        The event queue for this ContinuousQueryCache.
      • m_fListeners

        protected boolean m_fListeners
        Keeps track of whether the ContinuousQueryCache has listeners that require this cache to cache values.
      • m_filterAdd

        protected MapEventFilter m_filterAdd
        The MapEventFilter that uses the ContinuousQueryCache's filter to select events that would add elements to this cache's contents.
      • m_filterRemove

        protected MapEventFilter m_filterRemove
        The MapEventFilter that uses the ContinuousQueryCache's filter to select events that would remove elements from this cache's contents.
      • m_listenerAdd

        protected MapListener<K,​V_FRONT> m_listenerAdd
        The listener that gets information about what should be in this cache.
      • m_listenerRemove

        protected MapListener<K,​V_FRONT> m_listenerRemove
        The listener that gets information about what should be thrown out of this cache.
      • m_mapIndex

        protected Map m_mapIndex
        The map of indexes maintained by this cache. The keys of the Map are ValueExtractor objects, and for each key, the corresponding value stored in the Map is a MapIndex object.
      • m_listenerDeactivation

        protected com.tangosol.internal.net.NamedCacheDeactivationListener m_listenerDeactivation
        The NamedCacheDeactivationListener.
        Since:
        12.2.1.4
      • m_mapListener

        protected MapListener<? super K,​? super V_FRONT> m_mapListener
        The optional MapListener that may be provided during ContinuousQueryCache construction.
        Since:
        12.2.1.4
      • m_converterFromBinary

        protected Converter m_converterFromBinary
        Converter that will be used to convert values from binary.
        Since:
        12.2.1.4
      • m_converterToBinary

        protected Converter m_converterToBinary
        Converter that will be used to convert values to binary.
        Since:
        12.2.1.4
      • m_loader

        protected ClassLoader m_loader
        The ClassLoader to use when de-serializing/serializing keys and values.
        Since:
        12.2.1.4
    • Constructor Detail

      • ContinuousQueryCache

        public ContinuousQueryCache​(NamedCache<K,​V_BACK> cache)
        Create a locally materialized view of a NamedCache using a Filter. A materialized view is an implementation of Continuous Query exposed through the standard NamedCache API.

        This constructor will result in a ContinuousQueryCache that caches both its keys and values locally.

        Parameters:
        cache - the NamedCache with which the view will be created
        Since:
        12.2.1.4
      • ContinuousQueryCache

        public ContinuousQueryCache​(Supplier<NamedCache<K,​V_BACK>> supplierCache)
        Create a locally materialized view of a NamedCache using a Filter. A materialized view is an implementation of Continuous Query exposed through the standard NamedCache API.

        This constructor will result in a ContinuousQueryCache that caches both its keys and values locally.

        Parameters:
        supplierCache - a Supplier that returns a NamedCache with which the ContinuousQueryCache will be created The Supplier must return a new instance each time Supplier.get() is called
        Since:
        12.2.1.4
      • ContinuousQueryCache

        public ContinuousQueryCache​(NamedCache<K,​V_BACK> cache,
                                    Filter filter)
        Create a locally materialized view of a NamedCache using a Filter. A materialized view is an implementation of Continuous Query exposed through the standard NamedCache API.

        This constructor will result in a ContinuousQueryCache that caches both its keys and values locally.

        Parameters:
        cache - the NamedCache to create a view of
        filter - the filter that defines the view
      • ContinuousQueryCache

        public ContinuousQueryCache​(Supplier<NamedCache<K,​V_BACK>> supplierCache,
                                    Filter filter)
        Create a locally materialized view of a NamedCache using a Filter. A materialized view is an implementation of Continuous Query exposed through the standard NamedCache API.

        This constructor will result in a ContinuousQueryCache that caches both its keys and values locally.

        Parameters:
        supplierCache - a Supplier that returns a NamedCache with which the ContinuousQueryCache will be created The Supplier must return a new instance each time Supplier.get() is called
        filter - the Filter that defines the view
        Since:
        12.2.1.4
      • ContinuousQueryCache

        public ContinuousQueryCache​(NamedCache<K,​V_BACK> cache,
                                    Filter filter,
                                    ValueExtractor<? super V_BACK,​? extends V_FRONT> transformer)
        Create a locally materialized view of a NamedCache using a Filter and a transformer. A materialized view is an implementation of Continuous Query exposed through the standard NamedCache API.

        This constructor will result in a read-only ContinuousQueryCache that caches both its keys and transformed values locally.

        Parameters:
        cache - the NamedCache to create a view of
        filter - the Filter that defines the view
        transformer - the ValueExtractor that should be used to transform values retrieved from the underlying NamedCache before storing them locally
      • ContinuousQueryCache

        public ContinuousQueryCache​(NamedCache<K,​V_BACK> cache,
                                    Filter filter,
                                    boolean fCacheValues)
        Create a materialized view of a NamedCache using a Filter. A materialized view is an implementation of Continuous Query exposed through the standard NamedCache API.
        Parameters:
        cache - the NamedCache to create a view of
        filter - the Filter that defines the view
        fCacheValues - pass true to cache both the keys and values of the materialized view locally, or false to only cache the keys
      • ContinuousQueryCache

        public ContinuousQueryCache​(NamedCache<K,​V_BACK> cache,
                                    Filter filter,
                                    MapListener<? super K,​? super V_FRONT> listener)
        Create a materialized view of a NamedCache using a Filter. A materialized view is an implementation of Continuous Query exposed through the standard NamedCache API. This constructor allows a client to receive all events, including those that result from the initial population of the ContinuousQueryCache. In other words, all contents of the ContinuousQueryCache will be delivered to the listener as a sequence of events, including those items that already exist in the underlying (unfiltered) cache.
        Parameters:
        cache - the NamedCache to create a view of
        filter - the Filter that defines the view
        listener - a MapListener that will receive all the events from the ContinuousQueryCache, including those corresponding to its initial population
      • ContinuousQueryCache

        public ContinuousQueryCache​(NamedCache<K,​V_BACK> cache,
                                    Filter filter,
                                    MapListener<? super K,​? super V_FRONT> listener,
                                    ValueExtractor<? super V_BACK,​? extends V_FRONT> transformer)
        Create a materialized view of a NamedCache using a Filter. A materialized view is an implementation of Continuous Query exposed through the standard NamedCache API.

        This constructor will result in a read-only ContinuousQueryCache that caches both its keys and transformed values locally. It will also allow a client to receive all events, including those that result from the initial population of the ContinuousQueryCache. In other words, all contents of the ContinuousQueryCache will be delivered to the listener as a sequence of events, including those items that already exist in the underlying (unfiltered) cache.

        Parameters:
        cache - the NamedCache to create a view of
        filter - the Filter that defines the view
        listener - a MapListener that will receive all the events from the ContinuousQueryCache, including those corresponding to its initial population
        transformer - the ValueExtractor that should be used to transform values retrieved from the underlying NamedCache before storing them locally
      • ContinuousQueryCache

        public ContinuousQueryCache​(NamedCache<K,​V_BACK> cache,
                                    Filter filter,
                                    boolean fCacheValues,
                                    MapListener<? super K,​? super V_FRONT> listener,
                                    ValueExtractor<? super V_BACK,​? extends V_FRONT> transformer)
        Construct the ContinuousQueryCache.
        Parameters:
        cache - the NamedCache to create a view of
        filter - the Filter that defines the view
        fCacheValues - pass true to cache both the keys and values of the materialized view locally, or false to only cache the keys
        listener - an optional MapListener that will receive all events starting from the initialization of the ContinuousQueryCache
        transformer - an optional ValueExtractor that would be used to transform values retrieved from the underlying cache before storing them locally; if specified, this ContinuousQueryCache will become "read-only"
      • ContinuousQueryCache

        public ContinuousQueryCache​(Supplier<NamedCache<K,​V_BACK>> supplierCache,
                                    Filter filter,
                                    boolean fCacheValues,
                                    MapListener<? super K,​? super V_FRONT> listener,
                                    ValueExtractor<? super V_BACK,​? extends V_FRONT> transformer,
                                    ClassLoader loader)
        Create a materialized view of a NamedCache using a Filter. A materialized view is an implementation of Continuous Query exposed through the standard NamedCache API.

        This constructor will result in a read-only ContinuousQueryCache that caches both its keys and transformed values locally. It will also allow a client to receive all events, including those that result from the initial population of the ContinuousQueryCache. In other words, all contents of the ContinuousQueryCache will be delivered to the listener as a sequence of events, including those items that already exist in the underlying (unfiltered) cache.

        Parameters:
        supplierCache - a Supplier that returns a NamedCache with which the ContinuousQueryCache will be created. The Supplier must return a new instance each time Supplier.get() is called
        filter - the Filter that defines the view
        fCacheValues - pass true to cache both the keys and values of the materialized view locally, or false to only cache the keys
        listener - an optional MapListener that will receive all events starting from the initialization of the ContinuousQueryCache
        transformer - an optional ValueExtractor that would be used to transform values retrieved from the underlying cache before storing them locally; if specified, this ContinuousQueryCache will become read-only
        loader - an optional ClassLoader
        Since:
        12.2.1.4
    • Method Detail

      • getFilter

        public Filter getFilter()
        Obtain the Filter that this ContinuousQueryCache is using to query the underlying NamedCache.
        Returns:
        the Filter that this cache uses to select its contents from the underlying NamedCache
      • getTransformer

        public ValueExtractor<? super V_BACK,​? extends V_FRONT> getTransformer()
        Obtain the transformer that this ContinuousQueryCache is using to transform the results from the underlying cache prior to storing them locally.
        Returns:
        the ValueExtractor that this cache uses to transform entries from the underlying cache
        Since:
        12.2.1.4
      • getMapListener

        public MapListener<? super K,​? super V_FRONT> getMapListener()
        Obtain the configured MapListener for this ContinuousQueryCache.
        Returns:
        the MapListener for this ContinuousQueryCache
        Since:
        12.2.1.4
      • isCacheValues

        public boolean isCacheValues()
        Determine if this ContinuousQueryCache caches values locally.
        Returns:
        true if this object caches values locally, and false if it relies on the underlying NamedCache
      • setCacheValues

        public void setCacheValues​(boolean fCacheValues)
        Modify the local-caching option for the ContinuousQueryCache. By changing this value from false to true, the ContinuousQueryCache will fully realize its contents locally and maintain them coherently in a manner analogous to the Coherence Near Cache. By changing this value from true to false, the ContinuousQueryCache will discard its locally cached data and rely on the underlying NamedCache.

        Parameters:
        fCacheValues - pass true to enable local caching, or false to disable it
      • isTransformed

        public boolean isTransformed()
        Determine if this ContinuousQueryCache transforms values.
        Returns:
        true if this ContinuousQueryCache has been configured to transform values
      • isReadOnly

        public boolean isReadOnly()
        Determine if this ContinuousQueryCache disallows data modification operations.
        Returns:
        true if this ContinuousQueryCache has been configured as read-only
      • setReadOnly

        public void setReadOnly​(boolean fReadOnly)
        Modify the read-only option for the ContinuousQueryCache. Note that the cache can be made read-only, but the opposite (making it mutable) is explicitly disallowed.
        Parameters:
        fReadOnly - pass true to prohibit clients from making modifications to this cache
      • instantiateInternalCache

        protected ObservableMap<K,​V_FRONT> instantiateInternalCache()
        Create the internal cache used by the ContinuousQueryCache.
        Returns:
        a new ObservableMap that will represent the materialized view of the ContinuousQueryCache
      • getInternalCache

        protected ObservableMap<K,​V_FRONT> getInternalCache()
        Obtain a reference to the internal cache. The internal cache maintains all of the keys in the ContinuousQueryCache, and if isCacheValues() is true, it also maintains the up-to-date values corresponding to those keys.
        Returns:
        the internal cache that represents the materialized view of the ContinuousQueryCache
      • isObserved

        protected boolean isObserved()
        Determine if the ContinuousQueryCache has any listeners that cannot be served by this Map listening to lite events.
        Returns:
        true iff there is at least one listener
      • setObserved

        protected void setObserved​(boolean fObserved)
        Specify whether the ContinuousQueryCache has any listeners that cannot be served by this Map listening to lite events.
        Parameters:
        fObserved - true iff there is at least one listener
      • getState

        public int getState()
        Obtain the state of the ContinuousQueryCache.
        Returns:
        one of the STATE_ enums
      • changeState

        protected void changeState​(int nState)
        Change the state of the ContinuousQueryCache.
        Parameters:
        nState - one of the STATE_ enums
      • resetCacheRefs

        protected void resetCacheRefs()
        Reset cache references to null.
      • getReconnectInterval

        public long getReconnectInterval()
        Return the reconnection interval (in milliseconds). This value indicates the period in which re-synchronization with the underlying cache will be delayed in the case the connection is severed. During this time period, local content can be accessed without triggering re-synchronization of the local content.
        Returns:
        a reconnection interval (in milliseconds)
        Since:
        Coherence 3.4
        See Also:
        setReconnectInterval(long)
      • setReconnectInterval

        public void setReconnectInterval​(long cReconnectMillis)
        Specify the reconnection interval (in milliseconds). This value indicates the period in which re-synchronization with the underlying cache will be delayed in the case the connection is severed. During this time period, local content can be accessed without triggering re-synchronization of the local content.
        Parameters:
        cReconnectMillis - reconnection interval (in milliseconds). A value of zero or less means that the ContinuousQueryCache cannot be used when not connected.
        Since:
        Coherence 3.4
      • setCacheName

        public void setCacheName​(String sCacheName)
        Set the cache name for this ContinuousQueryCache as returned by getCacheName().

        Note: setting the cache name to be consistent with the cache name of the NamedCache this CQC is backed by will ensure data structures that cache NamedCache instances based upon the reported cache name would result in an appropriate cache hit.

        Parameters:
        sCacheName - the name this CQC should report as its cache name
        Since:
        12.2.1.4
      • put

        public V_FRONT put​(K oKey,
                           V_FRONT oValue)
        Description copied from class: AbstractKeyBasedMap
        Associates the specified value with the specified key in this map.
        Specified by:
        put in interface CacheMap<K,​V_BACK>
        Specified by:
        put in interface ConcurrentMap<K,​V_BACK>
        Specified by:
        put in interface Map<K,​V_BACK>
        Overrides:
        put in class AbstractKeyBasedMap<K,​V_FRONT>
        Parameters:
        oKey - key with which the specified value is to be associated
        oValue - value to be associated with the specified key
        Returns:
        previous value associated with specified key, or null if there was no mapping for key
      • putAll

        public void putAll​(Map<? extends K,​? extends V_FRONT> map)
        Description copied from class: AbstractKeyBasedMap
        Copies all of the mappings from the specified map to this map. The effect of this call is equivalent to that of calling AbstractKeyBasedMap.put(K, V) on this map once for each mapping in the passed map. The behavior of this operation is unspecified if the passed map is modified while the operation is in progress.
        Specified by:
        putAll in interface ConcurrentMap<K,​V_BACK>
        Specified by:
        putAll in interface Map<K,​V_BACK>
        Overrides:
        putAll in class AbstractKeyBasedMap<K,​V_FRONT>
        Parameters:
        map - the Map containing the key/value pairings to put into this Map
      • remove

        public V_FRONT remove​(Object oKey)
        Description copied from class: AbstractKeyBasedMap
        Removes the mapping for this key from this map if present. Expensive: updates both the underlying cache and the local cache.
        Specified by:
        remove in interface ConcurrentMap<K,​V_BACK>
        Specified by:
        remove in interface Map<K,​V_BACK>
        Overrides:
        remove in class AbstractKeyBasedMap<K,​V_FRONT>
        Parameters:
        oKey - key whose mapping is to be removed from the map
        Returns:
        previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.
      • getAll

        public Map<K,​V_FRONT> getAll​(Collection<? extends K> colKeys)
        Description copied from class: AbstractKeyBasedMap
        Get all the specified keys, if they are in the Map. For each key that is in the cache, that key and its corresponding value will be placed in the map that is returned by this method. The absence of a key in the returned map indicates that it was not in the cache, which may imply (for caches that can load behind the scenes) that the requested data could not be loaded.
        Specified by:
        getAll in interface CacheMap<K,​V_BACK>
        Specified by:
        getAll in interface NamedMap<K,​V_BACK>
        Overrides:
        getAll in class AbstractKeyBasedMap<K,​V_FRONT>
        Parameters:
        colKeys - a collection of keys that may be in the named cache
        Returns:
        a Map of keys to values for the specified keys passed in colKeys
      • put

        public V_FRONT put​(K oKey,
                           V_FRONT oValue,
                           long cMillis)
        Description copied from interface: NamedCache
        Associates the specified value with the specified key in this cache and allows to specify an expiry for the cache entry.

        Note: Though NamedCache interface extends CacheMap, not all implementations currently support this functionality.

        For example, if a cache is configured to be a replicated, optimistic or distributed cache then its backing map must be configured as a local cache. If a cache is configured to be a near cache then the front map must to be configured as a local cache and the back map must support this feature as well, typically by being a distributed cache backed by a local cache (as above.)

        Specified by:
        put in interface CacheMap<K,​V_BACK>
        Specified by:
        put in interface NamedCache<K,​V_BACK>
        Parameters:
        oKey - key with which the specified value is to be associated
        oValue - value to be associated with the specified key
        cMillis - the number of milliseconds until the cache entry will expire, also referred to as the entry's "time to live"; pass CacheMap.EXPIRY_DEFAULT to use the cache's default time-to-live setting; pass CacheMap.EXPIRY_NEVER to indicate that the cache entry should never expire; this milliseconds value is not a date/time value, such as is returned from System.currentTimeMillis()
        Returns:
        previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values
      • removeBlind

        protected boolean removeBlind​(Object oKey)
        Removes the mapping for this key from this map if present. This method exists to allow sub-classes to optimize remove functionality for situations in which the original value is not required.
        Overrides:
        removeBlind in class AbstractKeyBasedMap<K,​V_FRONT>
        Parameters:
        oKey - key whose mapping is to be removed from the map
        Returns:
        true iff the Map changed as the result of this operation
      • getInternalKeySet

        protected Set<K> getInternalKeySet()
        Description copied from class: AbstractKeySetBasedMap
        Obtain a set of keys that are represented by this Map.

        The AbstractKeySetBasedMap only utilizes the internal key set as a read-only resource.

        Specified by:
        getInternalKeySet in class AbstractKeySetBasedMap<K,​V_FRONT>
        Returns:
        an internal Set of keys that are contained by this Map
      • addMapListener

        public void addMapListener​(MapListener<? super K,​? super V_FRONT> listener)
        Description copied from interface: ObservableMap
        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. This has the same result as the following call:
           addMapListener(listener, (Filter) null, false);
         
        Specified by:
        addMapListener in interface ObservableMap<K,​V_BACK>
        Parameters:
        listener - the MapEvent listener to add
      • removeMapListener

        public void removeMapListener​(MapListener<? super K,​? super V_FRONT> listener)
        Description copied from interface: ObservableMap
        Remove a standard map listener that previously signed up for all events. This has the same result as the following call:
           removeMapListener(listener, (Filter) null);
         
        Specified by:
        removeMapListener in interface ObservableMap<K,​V_BACK>
        Parameters:
        listener - the listener to remove
      • addMapListener

        public void addMapListener​(MapListener<? super K,​? super V_FRONT> listener,
                                   K oKey,
                                   boolean fLite)
        Description copied from interface: ObservableMap
        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.

        To unregister the MapListener, use the ObservableMap.removeMapListener(MapListener, Object) method.

        Specified by:
        addMapListener in interface ObservableMap<K,​V_BACK>
        Parameters:
        listener - the MapEvent listener to add
        oKey - 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
      • removeMapListener

        public void removeMapListener​(MapListener<? super K,​? super V_FRONT> listener,
                                      K oKey)
        Description copied from interface: ObservableMap
        Remove a map listener that previously signed up for events about a specific key.
        Specified by:
        removeMapListener in interface ObservableMap<K,​V_BACK>
        Parameters:
        listener - the listener to remove
        oKey - the key that identifies the entry for which to raise events
      • addMapListener

        public void addMapListener​(MapListener<? super K,​? super V_FRONT> listener,
                                   Filter filter,
                                   boolean fLite)
        Description copied from interface: ObservableMap
        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.

        To unregister the MapListener, use the ObservableMap.removeMapListener(MapListener, Filter) method.

        Specified by:
        addMapListener in interface ObservableMap<K,​V_BACK>
        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 alway 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
      • removeMapListener

        public void removeMapListener​(MapListener<? super K,​? super V_FRONT> listener,
                                      Filter filter)
        Description copied from interface: ObservableMap
        Remove a map listener that previously signed up for events based on a filter evaluation.
        Specified by:
        removeMapListener in interface ObservableMap<K,​V_BACK>
        Parameters:
        listener - the listener to remove
        filter - the filter that was passed into the corresponding addMapListener() call
      • keySet

        public Set<K> keySet​(Filter filter)
        Description copied from interface: QueryMap
        Return a set view of the keys contained in this map for entries that satisfy the criteria expressed by the filter.

        Unlike the Map.keySet() method, the set returned by this method may not be backed by the map, so changes to the set may not reflected in the map, and vice-versa.

        Note: The Partitioned Cache implements the QueryMap interface using the Parallel Query feature.

        Specified by:
        keySet in interface QueryMap<K,​V_BACK>
        Parameters:
        filter - the Filter object representing the criteria that the entries of this map should satisfy
        Returns:
        a set of keys for entries that satisfy the specified criteria
      • entrySet

        public Set<Map.Entry<K,​V_FRONT>> entrySet​(Filter filter)
        Description copied from interface: QueryMap
        Return a set view of the entries contained in this map that satisfy the criteria expressed by the filter. Each element in the returned set is a Map.Entry.

        Unlike the Map.entrySet() method, the set returned by this method may not be backed by the map, so changes to the set may not be reflected in the map, and vice-versa.

        Note: The Partitioned Cache implements the QueryMap interface using the Parallel Query feature.

        Specified by:
        entrySet in interface QueryMap<K,​V_BACK>
        Parameters:
        filter - the Filter object representing the criteria that the entries of this map should satisfy
        Returns:
        a set of entries that satisfy the specified criteria
      • entrySet

        public Set<Map.Entry<K,​V_FRONT>> entrySet​(Filter filter,
                                                        Comparator comparator)
        Description copied from interface: QueryMap
        Return a set view of the entries contained in this map that satisfy the criteria expressed by the filter. Each element in the returned set is a Map.Entry. It is further guaranteed that its iterator will traverse the set in such a way that the entry values come up in ascending order, sorted by the specified Comparator or according to the natural ordering (see Comparable).

        Unlike the Map.entrySet() method, the set returned by this method may not be backed by the map, so changes to the set may not be reflected in the map, and vice-versa.

        Note: The Partitioned Cache implements the QueryMap interface using the Parallel Query feature.

        Specified by:
        entrySet in interface QueryMap<K,​V_BACK>
        Parameters:
        filter - the Filter object representing the criteria that the entries of this map should satisfy
        comparator - the Comparator object which imposes an ordering on entries in the resulting set; or null if the entries' values natural ordering should be used
        Returns:
        a set of entries that satisfy the specified criteria
        See Also:
        ChainedComparator
      • addIndex

        public <T,​E> void addIndex​(ValueExtractor<? super T,​? extends E> extractor,
                                         boolean fOrdered,
                                         Comparator<? super E> comparator)
        If isCacheValues() is true, the index will be created locally as well as on the NamedCache this ContinuousQueryCache wraps, otherwise, the index will be created on the wrapped NamedCache only.
        Specified by:
        addIndex in interface QueryMap<K,​V_BACK>
        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
        Throws:
        IllegalArgumentException - if extractor is an instance of MapTriggerListener
        See Also:
        QueryMap.addIndex(ValueExtractor, boolean, Comparator)
      • removeIndex

        public <T,​E> void removeIndex​(ValueExtractor<? super T,​? extends E> extractor)
        If isCacheValues() is true, the index will be removed locally, however, this call will not cause the index on the NamedCache this ContinuousQueryCache wraps. Developers must remove the index on the wrapped cache manually.
        Specified by:
        removeIndex in interface QueryMap<K,​V_BACK>
        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 Map.
        See Also:
        QueryMap.removeIndex(ValueExtractor), getCache()
      • truncate

        public void truncate()
        Description copied from interface: NamedMap
        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.

        Specified by:
        truncate in interface NamedMap<K,​V_BACK>
      • invoke

        public <R> R invoke​(K key,
                            InvocableMap.EntryProcessor<K,​V_FRONT,​R> processor)
        Invoke the passed EntryProcessor against the Entry specified by the passed key, returning the result of the invocation.

        In order to invoke an entry processor on a back cache in a type-safe manner you must use getCache().invoke() instead.

        Specified by:
        invoke in interface InvocableMap<K,​V_BACK>
        Type Parameters:
        R - the type of value returned by the EntryProcessor
        Parameters:
        key - the key to process; it is not required to exist within the Map
        processor - the EntryProcessor to use to process the specified key
        Returns:
        the result of the invocation as returned from the EntryProcessor
      • invokeAll

        public <R> Map<K,​R> invokeAll​(Collection<? extends K> collKeys,
                                            InvocableMap.EntryProcessor<K,​V_FRONT,​R> processor)
        Invoke the passed EntryProcessor against the entries specified by the passed keys, returning the result of the invocation for each.

        In order to invoke an entry processor on a back cache in a type-safe manner you must use getCache().invokeAll() instead.

        Specified by:
        invokeAll in interface InvocableMap<K,​V_BACK>
        Type Parameters:
        R - the type of value returned by the EntryProcessor
        Parameters:
        collKeys - the keys to process; these keys are not required to exist within the Map
        processor - the EntryProcessor to use to process the specified keys
        Returns:
        a Map containing the results of invoking the EntryProcessor against each of the specified keys
      • invokeAll

        public <R> Map<K,​R> invokeAll​(Filter filter,
                                            InvocableMap.EntryProcessor<K,​V_FRONT,​R> processor)
        Invoke the passed EntryProcessor against the set of entries that are selected by the given Filter, returning the result of the invocation for each.

        Unless specified otherwise, InvocableMap implementations will perform this operation in two steps: (1) use the filter to retrieve a matching entry set; (2) apply the agent to every filtered entry. This algorithm assumes that the agent's processing does not affect the result of the specified filter evaluation, since the filtering and processing could be performed in parallel on different threads. If this assumption does not hold, the processor logic has to be idempotent, or at least re-evaluate the filter. This could be easily accomplished by wrapping the processor with the ConditionalProcessor.

        In order to invoke an entry processor on a back cache in a type-safe manner you must use getCache().invokeAll() instead.

        Specified by:
        invokeAll in interface InvocableMap<K,​V_BACK>
        Type Parameters:
        R - the type of value returned by the EntryProcessor
        Parameters:
        filter - a Filter that results in the set of keys to be processed
        processor - the EntryProcessor to use to process the specified keys
        Returns:
        a Map containing the results of invoking the EntryProcessor against the keys that are selected by the given Filter
      • aggregate

        public <R> R aggregate​(Collection<? extends K> collKeys,
                               InvocableMap.EntryAggregator<? super K,​? super V_FRONT,​R> aggregator)
        Description copied from interface: InvocableMap
        Perform an aggregating operation against the entries specified by the passed keys.
        Specified by:
        aggregate in interface InvocableMap<K,​V_BACK>
        Type Parameters:
        R - the type of value returned by the EntryAggregator
        Parameters:
        collKeys - the Collection of keys that specify the entries within this Map to aggregate across
        aggregator - the EntryAggregator that is used to aggregate across the specified entries of this Map
        Returns:
        the result of the aggregation
      • aggregate

        public <R> R aggregate​(Filter filter,
                               InvocableMap.EntryAggregator<? super K,​? super V_FRONT,​R> aggregator)
        Description copied from interface: InvocableMap
        Perform an aggregating operation against the set of entries that are selected by the given Filter.
        Specified by:
        aggregate in interface InvocableMap<K,​V_BACK>
        Type Parameters:
        R - the type of value returned by the EntryAggregator
        Parameters:
        filter - the Filter that is used to select entries within this Map to aggregate across
        aggregator - the EntryAggregator that is used to aggregate across the selected entries of this Map
        Returns:
        the result of the aggregation
      • lock

        public boolean lock​(Object oKey,
                            long cWait)
        Description copied from interface: ConcurrentMap
        Attempt to lock the specified item within the specified period of time.

        The item doesn't have to exist to be locked. While the item is locked there is known to be a lock holder which has an exclusive right to modify (calling put and remove methods) that item.

        Lock holder is an abstract concept that depends on the ConcurrentMap implementation. For example, holder could be a cluster member or a thread (or both).

        Locking strategy may vary for concrete implementations as well. Lock could have an expiration time (this lock is sometimes called a "lease") or be held indefinitely (until the lock holder terminates).

        Some implementations may allow the entire map to be locked. If the map is locked in such a way, then only a lock holder is allowed to perform any of the "put" or "remove" operations. Pass the special constant ConcurrentMap.LOCK_ALL as the oKey parameter to indicate the map lock.

        Specified by:
        lock in interface ConcurrentMap<K,​V_BACK>
        Parameters:
        oKey - key being locked
        cWait - the number of milliseconds to continue trying to obtain a lock; pass zero to return immediately; pass -1 to block the calling thread until the lock could be obtained
        Returns:
        true if the item was successfully locked within the specified time; false otherwise
      • lock

        public boolean lock​(Object oKey)
        Description copied from interface: ConcurrentMap
        Attempt to lock the specified item and return immediately.

        This method behaves exactly as if it simply performs the call lock(oKey, 0).

        Specified by:
        lock in interface ConcurrentMap<K,​V_BACK>
        Parameters:
        oKey - key being locked
        Returns:
        true if the item was successfully locked; false otherwise
      • unlock

        public boolean unlock​(Object oKey)
        Description copied from interface: ConcurrentMap
        Unlock the specified item. The item doesn't have to exist to be unlocked. If the item is currently locked, only the holder of the lock could successfully unlock it.
        Specified by:
        unlock in interface ConcurrentMap<K,​V_BACK>
        Parameters:
        oKey - key being unlocked
        Returns:
        true if the item was successfully unlocked; false otherwise
      • async

        public AsyncNamedCache<K,​V_FRONT> async​(AsyncNamedMap.Option... options)
        Return an asynchronous wrapper for this NamedCache.

        By default, the order of execution of asynchronous operation invoked on the returned AsyncNamedCache will be preserved by ensuring that all operations invoked from the same client thread are executed on the server sequentially, using the same unit-of-order. This tends to provide the best performance for fast, non-blocking operations.

        However, when invoking CPU-intensive or blocking operations, such as read- or write-through operations that access remote database or web service, for example, it may be very beneficial to allow the server to parallelize execution by passing AsyncNamedMap.OrderBy.none() configuration option to this method. Note, that in that case there are no guarantees for the order of execution.

        This method returns an AsyncNamedCache instantiated from the back NamedMap. Transformers and filters defined on this CQC are not applied to the returned AsyncNamedCache.

        Specified by:
        async in interface NamedCache<K,​V_BACK>
        Specified by:
        async in interface NamedMap<K,​V_BACK>
        Parameters:
        options - the configuration options
        Returns:
        asynchronous wrapper for this NamedCache
      • isActive

        public boolean isActive()
        Description copied from interface: NamedMap
        Returns true if this map is not released or destroyed. In other words, calling isActive() is equivalent to calling !cache.isReleased() && !cache.isDestroyed().
        Specified by:
        isActive in interface NamedMap<K,​V_BACK>
        Specified by:
        isActive in interface Releasable
        Returns:
        true if the cache is active, otherwise false
      • isReady

        public boolean isReady()
        Description copied from interface: NamedMap
        Returns whether this NamedMap 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 storage-enabled members.
        Specified by:
        isReady in interface NamedMap<K,​V_BACK>
        Returns:
        return true if the NamedMap may be used otherwise returns false.
      • release

        public void release()
        Description copied from interface: Releasable
        Release local resources associated with this Releasable instance.
        Specified by:
        release in interface Releasable
      • destroy

        public void destroy()
        Description copied from interface: NamedCollection
        Release and destroy this instance of NamedCollection.

        Warning: This method is used to completely destroy the specified collection across the cluster. All references in the entire cluster to this collection will be invalidated, the collection data will be cleared, and all internal resources will be released.

        Specified by:
        destroy in interface NamedCollection
      • isDestroyed

        public boolean isDestroyed()
        Description copied from interface: NamedCollection
        Specifies whether or not this NamedCollection has been destroyed. Implementations must override this method to provide the necessary information.
        Specified by:
        isDestroyed in interface NamedCollection
        Returns:
        true if the NamedCollection has been destroyed; false otherwise
      • isReleased

        public boolean isReleased()
        Description copied from interface: Releasable
        Specifies whether or this Releasable has been released.

        Implementations must override this method to provide the necessary information.
        Specified by:
        isReleased in interface Releasable
        Returns:
        true if the Releasable has been released; false otherwise
      • getInternal

        protected V_FRONT getInternal​(Object oKey)
        Return the value from the back cache, transforming it in the process if necessary.
        Parameters:
        oKey - the key to get the associated value for
        Returns:
        the value for the given key
      • getAllInternal

        protected Map<K,​V_FRONT> getAllInternal​(Collection<? extends K> colKeys)
        Return multiple values from the back cache, transforming them in the process if necessary.
        Parameters:
        colKeys - the keys to get the associated values for
        Returns:
        the value for the given key
      • entrySetInternal

        protected Set<Map.Entry<K,​V_FRONT>> entrySetInternal​(Filter filter)
        Return multiple values from the back cache based on a filter, transforming them in the process if necessary.
        Parameters:
        filter - the Filter to find the entries for
        Returns:
        the value for the given key
      • entrySetInternal

        protected Set<Map.Entry<K,​V_FRONT>> entrySetInternal​(Filter filter,
                                                                   Comparator comparator)
        Return multiple values from the back cache based on a filter, transforming them in the process if necessary.
        Parameters:
        filter - the Filter to find the entries for
        comparator - the Comparator
        Returns:
        the value for the given key
      • mergeFilter

        protected Filter mergeFilter​(Filter filter)
        Return a filter which merges the ContinuousQueueCache's filter with the supplied filter.
        Parameters:
        filter - the filter to merge with this cache's filter
        Returns:
        the merged filter
      • checkReadOnly

        protected void checkReadOnly()
        Check the read-only setting to verify that the cache is NOT read-only.
        Throws:
        IllegalStateException - if the ContinuousQueryCache is read-only
      • checkEntry

        protected void checkEntry​(Map.Entry entry)
        Check the passed value to verify that it does belong in this ContinuousQueryCache.
        Parameters:
        entry - a key value pair to check.
        Throws:
        IllegalArgumentException - if the entry does not belong in this ContinuousQueryCache (based on the cache's filter)
      • checkEntry

        protected void checkEntry​(Object oKey,
                                  Object oValue)
        Check the passed value to verify that it does belong in this ContinuousQueryCache.
        Parameters:
        oKey - the key for the entry
        oValue - the value for the entry
        Throws:
        IllegalArgumentException - if the entry does not belong in this ContinuousQueryCache (based on the cache's filter)
      • getStateString

        protected String getStateString​(int nState)
        Return a String description of the provided STATE_* variables.
        Parameters:
        nState - the state for which a description will be returned
        Returns:
        the state description
        Throws:
        IllegalStateException - if an unknown state is provided
        Since:
        12.2.1.4.5
      • configureSynchronization

        protected void configureSynchronization​(boolean fReload)
        Set up the listeners that keep the ContinuousQueryCache up-to-date.
        Parameters:
        fReload - pass true to force a data reload
      • createUnexpectedStateException

        protected RuntimeException createUnexpectedStateException​(int nExpectedState,
                                                                  int nActualState)
        Simple helper to create an exception for communicating invalid state transitions.
        Parameters:
        nExpectedState - expected state
        nActualState - actual state
        Returns:
        a new RuntimeException with a description of the invalid state transition
        Since:
        12.2.1.4.5
      • ensureSynchronized

        protected void ensureSynchronized​(boolean fReload)
        Ensure that the ContinuousQueryCache listeners have been registered and its content synchronized with the underlying NamedCache.
        Parameters:
        fReload - the value to pass to the #configureSynchronization method if the ContinuousQueryCache needs to be configured and synchronized
      • isEventDeferred

        protected boolean isEventDeferred​(Object oKey)
        Called when an event has occurred. Allows the key to be logged as requiring deferred synchronization if the event occurs during the configuration or population of the ContinuousQueryCache.
        Parameters:
        oKey - the key that the event is related to
        Returns:
        true if the event processing has been deferred
      • ensureIndexMap

        protected Map ensureIndexMap()
        Ensure that the map of indexes maintained by this cache exists.
        Returns:
        the map of indexes.
      • getIndexMap

        protected Map getIndexMap()
        Get the map of indexes maintained by this cache.
        Returns:
        the map of indexes.
      • releaseIndexMap

        protected void releaseIndexMap()
        Release the the entire index map.
      • releaseListeners

        protected void releaseListeners()
        Release the listeners.
      • instantiateAddListener

        protected MapListener<K,​V_FRONT> instantiateAddListener()
        Factory Method: Instantiate a MapListener for adding items to the ContinuousQueryCache, and (if there are listeners on the ContinuousQueryCache) for dispatching inserts and updates.
        Returns:
        a new MapListener that will add items to and update items in the ContinuousQueryCache
      • instantiateRemoveListener

        protected MapListener<K,​V_FRONT> instantiateRemoveListener()
        Factory Method: Instantiate a MapListener for evicting items from the ContinuousQueryCache.
        Returns:
        a new MapListener that will listen to all events that will remove items from the ContinuousQueryCache
      • registerServiceListener

        protected void registerServiceListener()
        Instantiate and register a MemberListener with the underlying cache service.

        The primary goal of that listener is invalidation of the front map in case of the service [automatic] restart.

      • unregisterServiceListener

        protected void unregisterServiceListener()
        Unregister underlying cache service member listener.
      • registerDeactivationListener

        protected void registerDeactivationListener()
        Instantiate and register a NamedCacheDeactivationListener with the underlying cache service.

        The primary goal of that listener is invalidation of the named cache in case the named caches is destroyed / truncated.

        Since:
        12.2.1.4
      • unregisterDeactivationListener

        protected void unregisterDeactivationListener()
        Unregister underlying cache service member listener.
      • instantiateEventRouter

        protected ContinuousQueryCache.EventRouter<K,​V_FRONT> instantiateEventRouter​(MapListener<? super K,​? super V_FRONT> listener,
                                                                                           boolean fLite)
        Factory Method: Instantiate a listener on the internal map that will direct events to the passed listener, either synchronously or asynchronously as appropriate.
        Parameters:
        listener - the listener to route to
        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:
        a new ContinuousQueryCache.EventRouter specific to the passed listener
      • instantiateEventQueue

        protected TaskDaemon instantiateEventQueue()
        Create a self-processing event queue.
        Returns:
        a TaskDaemon onto which events can be placed in order to be dispatched asynchronously
      • getEventQueue

        protected TaskDaemon getEventQueue()
        Obtain this ContinuousQueryCache's event queue.
        Returns:
        the event queue that this ContinuousQueryCache uses to dispatch its events to its non-synchronous listeners
      • ensureEventQueue

        protected TaskDaemon ensureEventQueue()
        Obtain the existing event queue or create one if none exists.
        Returns:
        the event queue that this ContinuousQueryCache uses to dispatch its events to its non-synchronous listeners
      • shutdownEventQueue

        protected void shutdownEventQueue()
        Shut down running event queue.
      • ensureInflated

        protected V_FRONT ensureInflated​(Object oKey,
                                         Object oValue)
        If the internal cache value associated with the provided key is Binary, deserialize the value and store it back to the internal cache in its deserialized form.
        Parameters:
        oKey - the key
        oValue - optional original value associated with the key. If not provided, there will be a cost of an additional call to obtain the value currently associated with the key
        Returns:
        the deserialized value
        Since:
        12.2.1.4
      • fromInternal

        protected <T> T fromInternal​(Object binValue)
        Deserialize the provided Binary value.
        Type Parameters:
        T - the type parameter
        Parameters:
        binValue - the Binary value to deserialize
        Returns:
        the deserialized result
        Since:
        12.2.1.4
      • toInternal

        protected Binary toInternal​(Object oValue)
        Serialize the provided value into a Binary.
        Parameters:
        oValue - the object to serialize.
        Returns:
        the serialized result
        Since:
        12.2.1.4
      • instantiateConverterMap

        protected Map<K,​V_FRONT> instantiateConverterMap​(Map<K,​V_FRONT> map)
        Provides out-bound conversion (i.e. conversion to values clients expect) of internal values.
        Parameters:
        map - the Map to wrap
        Returns:
        the Map that will be returned to the client
        Since:
        12.2.1.4
      • isBinaryNamedCache

        protected boolean isBinaryNamedCache()
        Return true if the current back cache is configured to use Binary values.
        Returns:
        true if the back cache is configured to use Binary values
        Since:
        12.2.1.4
      • instantiateSerializer

        protected Serializer instantiateSerializer()
        Create a Serializer appropriate for the mode this cache is operating under (i.e., binary vs non-binary).
        Returns:
        a new Serializer
        Since:
        12.2.1.4
      • ensureConverters

        protected NamedCache ensureConverters​(NamedCache cache)
        Instantiate the converters necessary to support the processing mode that this ContinuousQueryCache will be operating under.
        Parameters:
        cache - the underlying cache
        Returns:
        the named cache
        Since:
        12.2.1.4
      • getDefaultName

        protected static String getDefaultName​(String sCacheName,
                                               Filter filter,
                                               ValueExtractor transformer)
        Return the default name used by the CQC.
        Parameters:
        sCacheName - the cache name this CQC is backed by
        filter - the filter that reduces the set of entries of this CQC
        transformer - the transformer to apply to the raw entries
        Returns:
        the default name used by the CQC