Oracle® Fusion Middleware C++ API Reference for Oracle Coherence
12c (12.1.3.0.0)

E47891-01

coherence/net/cache/ContinuousQueryCache.hpp

00001 /*
00002 * ContinuousQueryCache.hpp
00003 *
00004 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
00005 *
00006 * Oracle is a registered trademarks of Oracle Corporation and/or its
00007 * affiliates.
00008 *
00009 * This software is the confidential and proprietary information of Oracle
00010 * Corporation. You shall not disclose such confidential and proprietary
00011 * information and shall use it only in accordance with the terms of the
00012 * license agreement you entered into with Oracle.
00013 *
00014 * This notice may not be removed or altered.
00015 */
00016 #ifndef COH_CONTINUOUS_QUERY_CACHE_HPP
00017 #define COH_CONTINUOUS_QUERY_CACHE_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/net/CacheService.hpp"
00022 #include "coherence/net/NamedCache.hpp"
00023 #include "coherence/util/AbstractMap.hpp"
00024 #include "coherence/util/Comparator.hpp"
00025 #include "coherence/util/filter/MapEventFilter.hpp"
00026 #include "coherence/util/MapEvent.hpp"
00027 #include "coherence/util/MapIndex.hpp"
00028 #include "coherence/util/MapListener.hpp"
00029 #include "coherence/util/MultiplexingMapListener.hpp"
00030 #include "coherence/util/Set.hpp"
00031 #include "coherence/util/ValueExtractor.hpp"
00032 
00033 COH_OPEN_NAMESPACE3(coherence,net,cache)
00034 
00035 using coherence::net::CacheService;
00036 using coherence::net::NamedCache;
00037 using coherence::util::AbstractMap;
00038 using coherence::util::Comparator;
00039 using coherence::util::Filter;
00040 using coherence::util::filter::MapEventFilter;
00041 using coherence::util::MapEvent;
00042 using coherence::util::MapIndex;
00043 using coherence::util::MapListener;
00044 using coherence::util::MultiplexingMapListener;
00045 using coherence::util::Set;
00046 using coherence::util::ValueExtractor;
00047 
00048 
00049 /**
00050 * Create a materialized view of a NamedCache using the Coherence
00051 * <i>Continuous Query</i> capability.
00052 *
00053 * @author tb, js  2008.07.23
00054 */
00055 class COH_EXPORT ContinuousQueryCache
00056     : public class_spec<ContinuousQueryCache,
00057         extends<AbstractMap>,
00058         implements<NamedCache> >
00059     {
00060     friend class factory<ContinuousQueryCache>;
00061 
00062     // ----- constructors ---------------------------------------------------
00063 
00064     protected:
00065         /**
00066         * Create a materialized view of a NamedCache using a Filter. A
00067         * materialized view is an implementation of <i>Continuous Query</i>
00068         * exposed through the standard NamedCache API. This constructor
00069         * allows a client to receive all events, including those that result
00070         * from the initial population of the ContinuousQueryCache. In other
00071         * words, all contents of the ContinuousQueryCache will be delivered
00072         * to the listener as a sequence of events, including those items that
00073         * already exist in the underlying (unfiltered) cache.
00074         *
00075         * @param hCache        the NamedCache to create a view of
00076         * @param vFilter       the Filter that defines the view
00077         * @param fCacheValues  pass true to cache both the keys and values of
00078         *                      the materialized view locally, or false to
00079         *                      only cache the keys
00080         * @param hListener     an initial MapListener that will receive all
00081         *                      the events from the ContinuousQueryCache,
00082         *                      including those corresponding to its initial
00083         *                      population
00084         * @param vTransformer  the transformer that should be used to convert
00085         *                      values from the underlying cache before storing
00086         *                      them locally
00087         */
00088         ContinuousQueryCache(NamedCache::Handle hCache,
00089                 Filter::View vFilter, bool fCacheValues = false,
00090                 MapListener::Handle  hListener    = NULL,
00091                 ValueExtractor::View vTransformer = NULL);
00092 
00093 
00094     // ----- accessors ------------------------------------------------------
00095 
00096     public:
00097         /**
00098         * Obtain the NamedCache that this ContinuousQueryCache is based on.
00099         *
00100         * @return the underlying NamedCache
00101         */
00102         virtual NamedCache::View getCache() const;
00103 
00104         /**
00105         * Obtain the NamedCache that this ContinuousQueryCache is based on.
00106         *
00107         * @return the underlying NamedCache
00108         */
00109         virtual NamedCache::Handle getCache();
00110 
00111         /**
00112         * Obtain the Filter that this ContinuousQueryCache is using to query
00113         * the underlying NamedCache.
00114         *
00115         * @return the Filter that this cache uses to select its contents from
00116         *         the underlying NamedCache
00117         */
00118         virtual Filter::View getFilter() const;
00119 
00120         /**
00121         * Determine if this ContinuousQueryCache caches values locally.
00122         *
00123         * @return true if this object caches values locally, and false if it
00124         *        relies on the underlying NamedCache
00125         */
00126         virtual bool isCacheValues() const;
00127 
00128         /**
00129         * Modify the local-caching option for the ContinuousQueryCache. By
00130         * changing this value from <tt>false</tt> to <tt>true</tt>, the
00131         * ContinuousQueryCache will fully realize its contents locally and
00132         * maintain them coherently in a manner analogous to the Coherence
00133         * NearCache. By changing this value from <tt>true</tt> to
00134         * <tt>false</tt>, the ContinuousQueryCache will discard its locally
00135         * cached data and rely on the underlying NamedCache.
00136         *
00137         * @param fCacheValues pass true to enable local caching, or false to
00138         *                     disable it
00139         */
00140         virtual void setCacheValues(bool fCacheValues);
00141 
00142         /**
00143         * Determine if this ContinuousQueryCache disallows data modification
00144         * operations.
00145         *
00146         * @return true if this ContinuousQueryCache has been configured as
00147         *         read-only
00148         */
00149         virtual bool isReadOnly() const;
00150 
00151         /**
00152         * Modify the read-only option for the ContinuousQueryCache. Note that
00153         * the cache can be made read-only, but the opposite (making it
00154         * mutable) is explicitly disallowed.
00155         *
00156         * @param fReadOnly  pass true to prohibit clients from making
00157         *                   modifications to this cache
00158         */
00159         virtual void setReadOnly(bool fReadOnly);
00160 
00161 
00162         /**
00163         * Obtain the state of the ContinousQueryCache.
00164         *
00165         * @return  one of the STATE_ enums
00166         */
00167         virtual int32_t getState() const;
00168 
00169         /**
00170         * Return a reconnection interval (in milliseconds). This value
00171         * indicates how often the ContinuousQueryCache should attempt to
00172         * re-connect with the underlying [clustered] cache in case the
00173         * connection is severed.
00174         *
00175         * @return a reconnection interval (in milliseconds)
00176         */
00177         virtual int64_t getReconnectInterval() const;
00178 
00179         /**
00180         * Specify a reconnection interval (in milliseconds). This value
00181         * indicates how often the ContinuousQueryCache should attempt to
00182         * re-connect with the underlying [clustered] cache in case the
00183         * connection is severed.
00184         *
00185         * @param cReconnectMillis  reconnection interval (in milliseconds).
00186         *        The value of zero means that the ContinuousQueryCache cannot
00187         *        be used when not connected. If the value is positive, the
00188         *        local content could be accessed (read-only) even if
00189         *        connection is severed.
00190         */
00191         virtual void setReconnectInterval(int64_t cReconnectMillis);
00192 
00193     protected:
00194         /**
00195         * Create the internal cache used by the ContinuousQueryCache.
00196         *
00197         * @return a new ObservableMap that will represent the materialized
00198         *         view of the ContinuousQueryCache
00199         */
00200         virtual ObservableMap::Handle instantiateInternalCache();
00201 
00202         /**
00203         * Obtain a reference to the internal cache. The internal cache
00204         * maintains all of the keys in the ContinuousQueryCache, and if
00205         * isCacheValues()is true, it also maintains the up-to-date values
00206         * corresponding to those keys.
00207         *
00208         * @return the internal cache that represents the materialized view of
00209         *         the ContinuousQueryCache
00210         */
00211         virtual ObservableMap::View getInternalCache() const;
00212 
00213         /**
00214         * Obtain a reference to the internal cache. The internal cache
00215         * maintains all of the keys in the ContinuousQueryCache, and if
00216         * isCacheValues()is true, it also maintains the up-to-date values
00217         * corresponding to those keys.
00218         *
00219         * @return the internal cache that represents the materialized view of
00220         *         the ContinuousQueryCache
00221         */
00222         virtual ObservableMap::Handle getInternalCache();
00223 
00224         /**
00225         * Determine if the ContinuousQueryCache has any listeners that cannot
00226         * be served by this Map listening to lite events.
00227         *
00228         * @return true iff there is at least one listener
00229         */
00230         virtual bool isObserved() const;
00231 
00232         /**
00233         * Specify whether the ContinuousQueryCache has any listeners that
00234         * cannot be served by this Map listening to lite events.
00235         *
00236         * @param fObserved  true iff there is at least one listener
00237         */
00238         virtual void setObserved(bool fObserved);
00239 
00240         /**
00241         * Change the state of the ContinousQueryCache.
00242         *
00243         * @param nState  one of the STATE_ enums
00244         */
00245         virtual void changeState(int32_t nState) const;
00246 
00247 
00248     // ----- Map interface --------------------------------------------------
00249 
00250     public:
00251         /**
00252         * {@inheritDoc}
00253         */
00254         virtual Object::Holder get(Object::View vKey) const;
00255 
00256         /**
00257         * {@inheritDoc}
00258         */
00259         using Map::get;
00260 
00261         /**
00262         * {@inheritDoc}
00263         */
00264         virtual Object::Holder put(Object::View vKey, Object::Holder ohValue);
00265 
00266         /**
00267         * {@inheritDoc}
00268         */
00269         virtual Object::Holder remove(Object::View vKey);
00270 
00271         /**
00272         * {@inheritDoc}
00273         */
00274         virtual void putAll(Map::View vMap);
00275 
00276         /**
00277         * {@inheritDoc}
00278         */
00279         virtual void clear();
00280 
00281         /**
00282         * {@inheritDoc}
00283         */
00284         virtual bool containsKey(Object::View vKey) const;
00285 
00286         /**
00287         * {@inheritDoc}
00288         */
00289         virtual Set::View keySet() const;
00290 
00291         /**
00292         * {@inheritDoc}
00293         */
00294         virtual Set::Handle keySet();
00295 
00296         /**
00297         * {@inheritDoc}
00298         */
00299         virtual Set::View entrySet() const;
00300 
00301         /**
00302         * {@inheritDoc}
00303         */
00304         virtual Set::Handle entrySet();
00305 
00306         /**
00307         * {@inheritDoc}
00308         */
00309         virtual size32_t size() const;
00310 
00311 
00312     // ----- CacheMap interface ---------------------------------------------
00313 
00314     public:
00315         /**
00316         * {@inheritDoc}
00317         */
00318         virtual Map::View getAll(Collection::View vKeys) const;
00319 
00320         /**
00321         * {@inheritDoc}
00322         */
00323         virtual Object::Holder put(Object::View vKey,
00324                 Object::Holder ohValue, int64_t cMillis);
00325 
00326 
00327     // ----- ObservableMap interface ----------------------------------------
00328 
00329     public:
00330         /**
00331         * {@inheritDoc}
00332         */
00333         virtual void addKeyListener(MapListener::Handle hListener,
00334                 Object::View vKey, bool fLite);
00335 
00336         /**
00337         * {@inheritDoc}
00338         */
00339         virtual void removeKeyListener(MapListener::Handle hListener,
00340                 Object::View vKey);
00341 
00342         /**
00343         * {@inheritDoc}
00344         */
00345         virtual void addMapListener(MapListener::Handle hListener);
00346 
00347         /**
00348         * {@inheritDoc}
00349         */
00350         virtual void removeMapListener(MapListener::Handle hListener);
00351         
00352         /**
00353         * {@inheritDoc}
00354         */
00355         virtual void addFilterListener(MapListener::Handle hListener,
00356                 Filter::View vFilter = NULL, bool fLite = false);
00357 
00358         /**
00359         * {@inheritDoc}
00360         */
00361         virtual void removeFilterListener(MapListener::Handle hListener,
00362                 Filter::View vFilter = NULL);
00363 
00364 
00365     // ----- QueryMap interface ---------------------------------------------
00366 
00367     public:
00368         /**
00369         * {@inheritDoc}
00370         */
00371         virtual Set::View keySet(Filter::View vFilter) const;
00372 
00373         /**
00374         * {@inheritDoc}
00375         */
00376         virtual Set::View entrySet(Filter::View vFilter) const;
00377 
00378         /**
00379         * {@inheritDoc}
00380         */
00381         virtual Set::View entrySet(Filter::View vFilter,
00382                 Comparator::View vComparator) const;
00383 
00384         /**
00385         * {@inheritDoc}
00386         */
00387         virtual void addIndex(ValueExtractor::View vExtractor,
00388                 bool fOrdered, Comparator::View vComparator);
00389 
00390         /**
00391         * {@inheritDoc}
00392         */
00393         virtual void removeIndex(ValueExtractor::View vExtractor);
00394 
00395 
00396     // ----- InvocableMap interface -----------------------------------------
00397 
00398     public:
00399         /**
00400         * {@inheritDoc}
00401         */
00402         virtual Object::Holder invoke(Object::View vKey,
00403                 InvocableMap::EntryProcessor::Handle hAgent);
00404 
00405         /**
00406         * {@inheritDoc}
00407         */
00408         virtual Map::View invokeAll(Collection::View vCollKeys,
00409                 InvocableMap::EntryProcessor::Handle hAgent);
00410 
00411         /**
00412         * {@inheritDoc}
00413         */
00414         virtual Map::View invokeAll(Filter::View vFilter,
00415                 InvocableMap::EntryProcessor::Handle hAgent);
00416 
00417         /**
00418         * {@inheritDoc}
00419         */
00420         virtual Object::Holder aggregate(Collection::View vCollKeys,
00421                 InvocableMap::EntryAggregator::Handle hAgent) const;
00422 
00423         /**
00424         * {@inheritDoc}
00425         */
00426         virtual Object::Holder aggregate(Filter::View vFilter,
00427                 InvocableMap::EntryAggregator::Handle hAgent) const;
00428 
00429 
00430     // ----- ConcurrentMap interface ----------------------------------------
00431 
00432     public:
00433         /**
00434         * {@inheritDoc}
00435         */
00436         virtual bool lock(Object::View vKey, int64_t cWait) const;
00437 
00438         /**
00439         * {@inheritDoc}
00440         */
00441         virtual bool lock(Object::View vKey) const;
00442 
00443         /**
00444         * {@inheritDoc}
00445         */
00446         virtual bool unlock(Object::View vKey) const;
00447 
00448 
00449     // ----- NamedCache interface -------------------------------------------
00450 
00451     public:
00452         /**
00453         * {@inheritDoc}
00454         */
00455         virtual String::View getCacheName() const;
00456 
00457         /**
00458         * {@inheritDoc}
00459         */
00460         virtual CacheService::Handle getCacheService();
00461 
00462         /**
00463         * {@inheritDoc}
00464         */
00465         virtual CacheService::View getCacheService() const;
00466 
00467         /**
00468         * {@inheritDoc}
00469         */
00470         virtual bool isActive() const;
00471 
00472         /**
00473         * {@inheritDoc}
00474         */
00475         virtual void release();
00476 
00477         /**
00478         * {@inheritDoc}
00479         */
00480         virtual void destroy();
00481 
00482 
00483     // ----- inner class: AsynchronousEvent ---------------------------------
00484 
00485     public:
00486         /**
00487         * Encapsulates an event and a listener that are to be dispatched
00488         * asynchronously.
00489         */
00490         class AsynchronousEvent
00491                 : public class_spec<AsynchronousEvent>
00492             {
00493             friend class factory<AsynchronousEvent>;
00494 
00495             // ----- constructors/destructor ----------------------------
00496 
00497             protected:
00498                 /**
00499                 * @internal
00500                 */
00501                 AsynchronousEvent(MapEvent::Handle hEvent,
00502                         MapListener::Handle hListener);
00503 
00504             // ----- AsynchronousEvent interface -------------------------
00505 
00506             public:
00507                 /**
00508                 * Dispatch the event.
00509                 */
00510                 virtual void dispatch();
00511 
00512             // ----- data members ---------------------------------------
00513 
00514             protected:
00515                 /**
00516                 * The event to dispatch.
00517                 */
00518                 FinalHandle<MapEvent> f_hEvent;
00519 
00520                 /**
00521                 * The listener to receive the event.
00522                 */
00523                 FinalHandle<MapListener> f_hListener;
00524             };
00525 
00526 
00527     // ----- inner interface: EventQueueDaemon ------------------------------
00528 
00529     public:
00530         /**
00531         * Daemon thread used to dispatch messages asynchronously.
00532         */
00533         class COH_EXPORT TaskDaemon
00534                 : public interface_spec<TaskDaemon>
00535             {
00536             public:
00537                 /**
00538                 * Schedule an event for asynchronous processing
00539                 *
00540                 * @param hEvent  the event to dispatch
00541                 */
00542                 virtual void scheduleDispatch(
00543                         AsynchronousEvent::Handle hEvent) = 0;
00544 
00545                 /**
00546                 * Start the daemon thread.
00547                 */
00548                 virtual void start() = 0;
00549 
00550                 /**
00551                 * Stop the daemon thread.
00552                 */
00553                 virtual void stop() = 0;
00554             };
00555 
00556 
00557     // ----- internal -------------------------------------------------------
00558 
00559     protected:
00560         /**
00561         * Return a filter which merges the ContinousQueueCache's filter with
00562         * the supplied filter.
00563         *
00564         * @param vFilter  the filter to merge with this cache's filter
00565         *
00566         * @return the merged filter
00567         */
00568         virtual Filter::View mergeFilter(Filter::View vFilter) const;
00569 
00570         /**
00571         * Check the read-only setting to verify that the cache is NOT
00572         * read-only.
00573         *
00574         * @throws IllegalStateException if the ContinuousQueryCache is
00575         *         read-only
00576         */
00577         virtual void checkReadOnly() const;
00578 
00579         /**
00580         * Check the passed value to verify that it does belong in this
00581         * ContinuousQueryCache.
00582         *
00583         * @param vEntry  a key value pair to check.
00584         *
00585         * @throws IllegalArgumentException if the entry does not belong in
00586         *         this ContinuousQueryCache (based on the cache's filter)
00587         */
00588         virtual void checkEntry(Map::Entry::View vEntry);
00589 
00590         /**
00591         * Check the passed value to verify that it does belong in this
00592         * ContinuousQueryCache.
00593         *
00594         * @param vKey     the key for the entry
00595         * @param ohValue  the value for the entry
00596         *
00597         * @throws IllegalArgumentException if the entry does not belong in
00598         *         this ContinuousQueryCache (based on the cache's filter)
00599         */
00600         virtual void checkEntry(Object::View vKey, Object::Holder ohValue);
00601 
00602         /**
00603         * Set up the listeners that keep the ContinuousQueryCache up-to-date.
00604         *
00605         * @param fReload  pass true to force a data reload
00606         */
00607         virtual void configureSynchronization(bool fReload) const;
00608 
00609         /**
00610         * Wrap specified MapEventFilter with a MapEventTransformerFilter that
00611         * will either transform cache value using transformer defined for this
00612         * ContinuousQueryCache, or remove the old value from the event using
00613         * SemiLiteEventTransformer, if no transformer is defined for this CQC.
00614         *
00615         * @param filterAdd  add filter to wrap
00616         *
00617         * @return MapEventTransformerFilter that wraps specified add filter
00618         *
00619         * @since Coherence 12.1.2
00620         */
00621         virtual Filter::View createTransformerFilter(
00622             MapEventFilter::View vFilterAdd) const;
00623 
00624         /**
00625         * Ensure that the ContinousQueryCache listeners have been registered
00626         * and its content synchronized with the underlying NamedCache.
00627         *
00628         * @param fReload  the value to pass to the #configureSynchronization
00629         *                 method if the ContinousQueryCache needs to be
00630         *                 configured and synchronized
00631         */
00632         virtual void ensureSynchronized(bool fReload) const;
00633 
00634         /**
00635         * Called when an event has occurred. Allows the key to be logged as
00636         * requiring deferred synchronization if the event occurs during the
00637         * configuration or population of the ContinuousQueryCache.
00638         *
00639         * @param vKey  the key that the event is related to
00640         *
00641         * @return true if the event processing has been deferred
00642         */
00643         virtual bool isEventDeferred(Object::View vKey) const;
00644 
00645         /**
00646         * Removes the mapping for this key from this map if present. This
00647         * method exists to allow sub-classes to optmiize remove
00648         * functionalitly for situations in which the original value is not
00649         * required.
00650         *
00651         * @param vKey key whose mapping is to be removed from the map
00652         *
00653         * @return true iff the Map changed as the result of this operation
00654         */
00655         virtual bool removeBlind(Object::View vKey);
00656 
00657         /**
00658         * Obtain a set of keys that are represented by this Map.
00659         *
00660         * @return an internal Set of keys that are contained by this Map
00661         */
00662         virtual Set::View getInternalKeySet() const;
00663 
00664         /**
00665         * Return the underlying cache.
00666         *
00667         * @return the underlying cache
00668         */
00669         virtual NamedCache::Handle getCacheInternal() const;
00670 
00671         /**
00672         * Factory Method: Instantiate a MapListener for adding items to the
00673         * query, and (if there are listeners on the ContinuousQueryCache) for
00674         * dispatching inserts and updates.
00675         *
00676         * @return a new MapListener that will add items to and update items
00677         *         in the ContinuousQueryCache
00678         */
00679         virtual MapListener::Handle instantiateAddListener() const;
00680 
00681         /**
00682         * Factory Method: Instantiate a MapListener for evicting items from
00683         * the query.
00684         *
00685         * @return a new MapListener that will listen to all events that will
00686         *         remove items from the ContinuousQueryCache
00687         */
00688         virtual MapListener::Handle instantiateRemoveListener() const;
00689 
00690         /**
00691         * Instantiate and register a MemberListener with the underlying
00692         * caches's service.
00693         * <p>
00694         * The primary goal of that listener is invalidation of the front map
00695         * in case of the service [automatic] restart.
00696         */
00697         virtual void registerServiceListener() const;
00698 
00699         /**
00700         * Unregister underlying caches's service member listener.
00701         */
00702         virtual void unregisterServiceListener();
00703 
00704         /**
00705         * Factory Method: Instantiate a listener on the internal map that
00706         * will direct events to the passed listener, either synchronously or
00707         * asynchronously as appropriate.
00708         *
00709         * @param hListener  the listener to route to
00710         *
00711         * @return a new EventRouter specific to the passed listener
00712         */
00713         virtual MultiplexingMapListener::Handle instantiateEventRouter(
00714                 MapListener::Handle hListener);
00715 
00716         /**
00717         * Create a self-processing event queue.
00718         *
00719         * @return a QueueProcessor onto which events can be placed in order
00720         *         to be dispatched asynchronously
00721         */
00722         virtual TaskDaemon::Handle instantiateEventQueue();
00723 
00724         /**
00725         * Obtain this ContinuousQueryCache's event queue.
00726         *
00727         * @return the event queue that this ContinuousQueryCache uses to
00728         *         dispatch its events to its non-synchronous listeners
00729         */
00730         virtual TaskDaemon::Handle getEventQueue();
00731 
00732         /**
00733         * Obtain the existing event queue or create one if none exists.
00734         *
00735         * @return the event queue that this ContinuousQueryCache uses to
00736         *         dispatch its events to its non-synchronous listeners
00737         */
00738         virtual TaskDaemon::Handle ensureEventQueue();
00739 
00740         /**
00741         * Shut down running event queue.
00742         */
00743         virtual void shutdownEventQueue();
00744 
00745         /**
00746         * Create a new key set.
00747         *
00748         * @return the new key set
00749         */
00750         virtual Set::Handle instantiateKeySet();
00751 
00752         /**
00753         * Create a new EntrySet
00754         *
00755         * @return the new empty set
00756         */
00757         virtual Set::Handle instantiateEntrySet();
00758 
00759         /**
00760         * Ensure that the map of indexes maintained by this cache exists.
00761         *
00762         * @return the map of indexes.
00763         */
00764         virtual Map::Handle ensureIndexMap();
00765 
00766         /**
00767         * Get the map of indexes maintained by this cache.
00768         *
00769         * @return the map of indexes.
00770         */
00771         virtual Map::View getIndexMap() const;
00772 
00773         /**
00774         * Get the map of indexes maintained by this cache.
00775         *
00776         * @return the map of indexes.
00777         */
00778         virtual Map::Handle getIndexMap();
00779 
00780         /**
00781         * Release the the entire index map.
00782         */
00783         virtual void releaseIndexMap();
00784 
00785 
00786     // ----- Object interface -----------------------------------------------
00787 
00788     protected:
00789         /**
00790         * {@inheritDoc}
00791         */
00792         virtual void onInit();
00793 
00794 
00795     // ----- constants ------------------------------------------------------
00796 
00797     public:
00798         /**
00799         * State: Disconnected state. The content of the ContinousQueryCache is
00800         * not fully synchronized with the underlying [clustered] cache. If the
00801         * value of the ReconnectInterval property is zero, it must be
00802         * configured (synchronized) before it can be used.
00803         */
00804         static const int32_t state_disconnected  = 0;
00805 
00806         /**
00807         * State: The ContinuousQueryCache is configuring or re-configuring its
00808         * listeners and content.
00809         */
00810         static const int32_t state_configuring  = 1;
00811 
00812         /**
00813         * State: The ContinousQueryCache has been configured.
00814         */
00815         static const int32_t state_configured   = 2;
00816 
00817         /**
00818         * State: The ContinousQueryCache has been configured and fully
00819         * synchronized.
00820         */
00821         static const int32_t state_synchronized = 3;
00822 
00823 
00824     // ----- data members ---------------------------------------------------
00825 
00826     protected:
00827         /**
00828         * The underlying NamedCache object.
00829         */
00830         mutable MemberHandle<NamedCache> m_hCache;
00831 
00832         /**
00833         * The name of the underlying NamedCache. A copy is kept here because
00834         * the reference to the underlying NamedCache is discarded when this
00835         * cache is released.
00836         */
00837         FinalView<String> f_vsName;
00838 
00839         /**
00840         * The filter that represents the subset of information from the
00841         * underlying NamedCache that this ContinuousQueryCache represents.
00842         */
00843         FinalView<Filter> f_vFilter;
00844 
00845         /**
00846         * The option of whether or not to locally cache values.
00847         */
00848         bool m_fCacheValues;
00849 
00850         /**
00851         * The option to disallow modifications through this
00852         * ContinuousQueryCache interface.
00853         */
00854         bool m_fReadOnly;
00855 
00856         /**
00857         * The interval (in millisceonds) that indicates how often the
00858         * ContinuousQueryCache should attempt to synchronize its content with
00859         * the underlying cache in case the connection is severed.
00860         */
00861         int64_t m_cReconnectMillis;
00862 
00863         /**
00864         * The timestamp when the synchronization was last attempted.
00865         */
00866         mutable Volatile<int64_t> m_ldtConnectionTimestamp;
00867 
00868         /**
00869         * The keys that are in this ContinuousQueryCache, and (if
00870         * m_fCacheValues is true) the corresponding values as well.
00871         */
00872         mutable MemberHandle<ObservableMap> m_hMapLocal;
00873 
00874         /**
00875         * State of the ContinousQueryCache. One of the STATE_* enums.
00876         */
00877         mutable Volatile<int32_t> m_nState;
00878 
00879         /**
00880         * While the ContinuousQueryCache is configuring or re-configuring its
00881         * listeners and content, any events that are received must be logged
00882         * to ensure that the corresponding content is in sync.
00883         */
00884         mutable MemberHandle<Map> m_hMapSyncReq;
00885 
00886         /**
00887         * The event queue for this ContinuousQueryCache.
00888         */
00889         MemberHandle<TaskDaemon> m_hTaskQueue;
00890 
00891         /**
00892         * Keeps track of whether the ContinuousQueryCache has listeners that
00893         * require this cache to cache values.
00894         */
00895         bool m_fListeners;
00896 
00897         /**
00898         * The MapEventFilter that uses the ContinuousQueryCache's filter to
00899         * select events that would add elements to this cache's contents.
00900         */
00901         mutable MemberView<MapEventFilter> m_vFilterAdd;
00902 
00903         /**
00904         * The MapEventFilter that uses the ContinuousQueryCache's filter to
00905         * select events that would remove elements from this cache's contents.
00906         */
00907         mutable MemberView<MapEventFilter> m_vFilterRemove;
00908 
00909         /**
00910         * The listener that gets information about what should be in this
00911         * cache.
00912         */
00913         mutable WeakHandle<MapListener> m_whListenerAdd;
00914 
00915         /**
00916         * The listener that gets information about what should be thrown out
00917         * of this cache.
00918         */
00919         mutable WeakHandle<MapListener> m_whListenerRemove;
00920 
00921         /**
00922         * The cache service MemberListener for the underlying NamedCache.
00923         */
00924         mutable WeakHandle<MemberListener> m_whListenerService;
00925 
00926         /*
00927         * The initial MapListener that will receive all the events from the
00928         * ContinuousQueryCache, including those corresponding to its initial
00929         * population.
00930         */
00931         FinalHandle<MapListener> f_hListener;
00932 
00933         /**
00934         * The transformer that should be used to convert values from the
00935         * underlying cache.
00936         */
00937         FinalView<ValueExtractor> f_vTransformer;
00938 
00939         /**
00940         * The map of indexes maintained by this cache. The keys of the Map are
00941         * ValueExtractor objects, and for each key, the corresponding value
00942         * stored in the Map is a MapIndex object.
00943         */
00944         FinalHandle<Map> f_hMapIndex;
00945 
00946         /**
00947         * KeySet backed by this cache
00948         */
00949         FinalHandle<Set> f_hSetKeys;
00950 
00951         /**
00952         * EntrySet backed by this cache
00953         */
00954         FinalHandle<Set> f_hSetEntries;
00955 
00956 
00957     // ----- friends --------------------------------------------------------
00958 
00959     friend class AddListener;
00960     friend class RemoveListener;
00961     friend class ServiceListener;
00962     friend class EventRouter;
00963     friend class KeySet;
00964     friend class EntrySet;
00965     friend class KeySetMuterator;
00966     friend class EntrySetIterator;
00967     };
00968 
00969 COH_CLOSE_NAMESPACE3
00970 
00971 #endif // COH_CONTINUOUS_QUERY_CACHE_HPP
00972 
Copyright © 2000, 2014, Oracle and/or its affiliates. All rights reserved.