Oracle Coherence for C++ API
Release 3.7.1.0

E22845-01

coherence/net/cache/ContinuousQueryCache.hpp

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