00001 /* 00002 * ContinuousQueryCache.hpp 00003 * 00004 * Copyright (c) 2000, 2013, 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 addFilterListener(MapListener::Handle hListener, 00346 Filter::View vFilter = NULL, bool fLite = false); 00347 00348 /** 00349 * {@inheritDoc} 00350 */ 00351 virtual void removeFilterListener(MapListener::Handle hListener, 00352 Filter::View vFilter = NULL); 00353 00354 00355 // ----- QueryMap interface --------------------------------------------- 00356 00357 public: 00358 /** 00359 * {@inheritDoc} 00360 */ 00361 virtual Set::View keySet(Filter::View vFilter) const; 00362 00363 /** 00364 * {@inheritDoc} 00365 */ 00366 virtual Set::View entrySet(Filter::View vFilter) const; 00367 00368 /** 00369 * {@inheritDoc} 00370 */ 00371 virtual Set::View entrySet(Filter::View vFilter, 00372 Comparator::View vComparator) const; 00373 00374 /** 00375 * {@inheritDoc} 00376 */ 00377 virtual void addIndex(ValueExtractor::View vExtractor, 00378 bool fOrdered, Comparator::View vComparator); 00379 00380 /** 00381 * {@inheritDoc} 00382 */ 00383 virtual void removeIndex(ValueExtractor::View vExtractor); 00384 00385 00386 // ----- InvocableMap interface ----------------------------------------- 00387 00388 public: 00389 /** 00390 * {@inheritDoc} 00391 */ 00392 virtual Object::Holder invoke(Object::View vKey, 00393 InvocableMap::EntryProcessor::Handle hAgent); 00394 00395 /** 00396 * {@inheritDoc} 00397 */ 00398 virtual Map::View invokeAll(Collection::View vCollKeys, 00399 InvocableMap::EntryProcessor::Handle hAgent); 00400 00401 /** 00402 * {@inheritDoc} 00403 */ 00404 virtual Map::View invokeAll(Filter::View vFilter, 00405 InvocableMap::EntryProcessor::Handle hAgent); 00406 00407 /** 00408 * {@inheritDoc} 00409 */ 00410 virtual Object::Holder aggregate(Collection::View vCollKeys, 00411 InvocableMap::EntryAggregator::Handle hAgent) const; 00412 00413 /** 00414 * {@inheritDoc} 00415 */ 00416 virtual Object::Holder aggregate(Filter::View vFilter, 00417 InvocableMap::EntryAggregator::Handle hAgent) const; 00418 00419 00420 // ----- ConcurrentMap interface ---------------------------------------- 00421 00422 public: 00423 /** 00424 * {@inheritDoc} 00425 */ 00426 virtual bool lock(Object::View vKey, int64_t cWait) const; 00427 00428 /** 00429 * {@inheritDoc} 00430 */ 00431 virtual bool lock(Object::View vKey) const; 00432 00433 /** 00434 * {@inheritDoc} 00435 */ 00436 virtual bool unlock(Object::View vKey) const; 00437 00438 00439 // ----- NamedCache interface ------------------------------------------- 00440 00441 public: 00442 /** 00443 * {@inheritDoc} 00444 */ 00445 virtual String::View getCacheName() const; 00446 00447 /** 00448 * {@inheritDoc} 00449 */ 00450 virtual CacheService::Handle getCacheService(); 00451 00452 /** 00453 * {@inheritDoc} 00454 */ 00455 virtual CacheService::View getCacheService() const; 00456 00457 /** 00458 * {@inheritDoc} 00459 */ 00460 virtual bool isActive() const; 00461 00462 /** 00463 * {@inheritDoc} 00464 */ 00465 virtual void release(); 00466 00467 /** 00468 * {@inheritDoc} 00469 */ 00470 virtual void destroy(); 00471 00472 00473 // ----- inner class: AsynchronousEvent --------------------------------- 00474 00475 public: 00476 /** 00477 * Encapsulates an event and a listener that are to be dispatched 00478 * asynchronously. 00479 */ 00480 class AsynchronousEvent 00481 : public class_spec<AsynchronousEvent> 00482 { 00483 friend class factory<AsynchronousEvent>; 00484 00485 // ----- constructors/destructor ---------------------------- 00486 00487 protected: 00488 /** 00489 * @internal 00490 */ 00491 AsynchronousEvent(MapEvent::Handle hEvent, 00492 MapListener::Handle hListener); 00493 00494 // ----- AsynchronousEvent interface ------------------------- 00495 00496 public: 00497 /** 00498 * Dispatch the event. 00499 */ 00500 virtual void dispatch(); 00501 00502 // ----- data members --------------------------------------- 00503 00504 protected: 00505 /** 00506 * The event to dispatch. 00507 */ 00508 FinalHandle<MapEvent> f_hEvent; 00509 00510 /** 00511 * The listener to receive the event. 00512 */ 00513 FinalHandle<MapListener> f_hListener; 00514 }; 00515 00516 00517 // ----- inner interface: EventQueueDaemon ------------------------------ 00518 00519 public: 00520 /** 00521 * Daemon thread used to dispatch messages asynchronously. 00522 */ 00523 class COH_EXPORT TaskDaemon 00524 : public interface_spec<TaskDaemon> 00525 { 00526 public: 00527 /** 00528 * Schedule an event for asynchronous processing 00529 * 00530 * @param hEvent the event to dispatch 00531 */ 00532 virtual void scheduleDispatch( 00533 AsynchronousEvent::Handle hEvent) = 0; 00534 00535 /** 00536 * Start the daemon thread. 00537 */ 00538 virtual void start() = 0; 00539 00540 /** 00541 * Stop the daemon thread. 00542 */ 00543 virtual void stop() = 0; 00544 }; 00545 00546 00547 // ----- internal ------------------------------------------------------- 00548 00549 protected: 00550 /** 00551 * Return a filter which merges the ContinousQueueCache's filter with 00552 * the supplied filter. 00553 * 00554 * @param vFilter the filter to merge with this cache's filter 00555 * 00556 * @return the merged filter 00557 */ 00558 virtual Filter::View mergeFilter(Filter::View vFilter) const; 00559 00560 /** 00561 * Check the read-only setting to verify that the cache is NOT 00562 * read-only. 00563 * 00564 * @throws IllegalStateException if the ContinuousQueryCache is 00565 * read-only 00566 */ 00567 virtual void checkReadOnly() const; 00568 00569 /** 00570 * Check the passed value to verify that it does belong in this 00571 * ContinuousQueryCache. 00572 * 00573 * @param vEntry a key value pair to check. 00574 * 00575 * @throws IllegalArgumentException if the entry does not belong in 00576 * this ContinuousQueryCache (based on the cache's filter) 00577 */ 00578 virtual void checkEntry(Map::Entry::View vEntry); 00579 00580 /** 00581 * Check the passed value to verify that it does belong in this 00582 * ContinuousQueryCache. 00583 * 00584 * @param vKey the key for the entry 00585 * @param ohValue the value for the entry 00586 * 00587 * @throws IllegalArgumentException if the entry does not belong in 00588 * this ContinuousQueryCache (based on the cache's filter) 00589 */ 00590 virtual void checkEntry(Object::View vKey, Object::Holder ohValue); 00591 00592 /** 00593 * Set up the listeners that keep the ContinuousQueryCache up-to-date. 00594 * 00595 * @param fReload pass true to force a data reload 00596 */ 00597 virtual void configureSynchronization(bool fReload) const; 00598 00599 /** 00600 * Wrap specified MapEventFilter with a MapEventTransformerFilter that 00601 * will either transform cache value using transformer defined for this 00602 * ContinuousQueryCache, or remove the old value from the event using 00603 * SemiLiteEventTransformer, if no transformer is defined for this CQC. 00604 * 00605 * @param filterAdd add filter to wrap 00606 * 00607 * @return MapEventTransformerFilter that wraps specified add filter 00608 * 00609 * @since Coherence 12.1.2 00610 */ 00611 virtual Filter::View createTransformerFilter( 00612 MapEventFilter::View vFilterAdd) const; 00613 00614 /** 00615 * Ensure that the ContinousQueryCache listeners have been registered 00616 * and its content synchronized with the underlying NamedCache. 00617 * 00618 * @param fReload the value to pass to the #configureSynchronization 00619 * method if the ContinousQueryCache needs to be 00620 * configured and synchronized 00621 */ 00622 virtual void ensureSynchronized(bool fReload) const; 00623 00624 /** 00625 * Called when an event has occurred. Allows the key to be logged as 00626 * requiring deferred synchronization if the event occurs during the 00627 * configuration or population of the ContinuousQueryCache. 00628 * 00629 * @param vKey the key that the event is related to 00630 * 00631 * @return true if the event processing has been deferred 00632 */ 00633 virtual bool isEventDeferred(Object::View vKey) const; 00634 00635 /** 00636 * Removes the mapping for this key from this map if present. This 00637 * method exists to allow sub-classes to optmiize remove 00638 * functionalitly for situations in which the original value is not 00639 * required. 00640 * 00641 * @param vKey key whose mapping is to be removed from the map 00642 * 00643 * @return true iff the Map changed as the result of this operation 00644 */ 00645 virtual bool removeBlind(Object::View vKey); 00646 00647 /** 00648 * Obtain a set of keys that are represented by this Map. 00649 * 00650 * @return an internal Set of keys that are contained by this Map 00651 */ 00652 virtual Set::View getInternalKeySet() const; 00653 00654 /** 00655 * Return the underlying cache. 00656 * 00657 * @return the underlying cache 00658 */ 00659 virtual NamedCache::Handle getCacheInternal() const; 00660 00661 /** 00662 * Factory Method: Instantiate a MapListener for adding items to the 00663 * query, and (if there are listeners on the ContinuousQueryCache) for 00664 * dispatching inserts and updates. 00665 * 00666 * @return a new MapListener that will add items to and update items 00667 * in the ContinuousQueryCache 00668 */ 00669 virtual MapListener::Handle instantiateAddListener() const; 00670 00671 /** 00672 * Factory Method: Instantiate a MapListener for evicting items from 00673 * the query. 00674 * 00675 * @return a new MapListener that will listen to all events that will 00676 * remove items from the ContinuousQueryCache 00677 */ 00678 virtual MapListener::Handle instantiateRemoveListener() const; 00679 00680 /** 00681 * Instantiate and register a MemberListener with the underlying 00682 * caches's service. 00683 * <p> 00684 * The primary goal of that listener is invalidation of the front map 00685 * in case of the service [automatic] restart. 00686 */ 00687 virtual void registerServiceListener() const; 00688 00689 /** 00690 * Unregister underlying caches's service member listener. 00691 */ 00692 virtual void unregisterServiceListener(); 00693 00694 /** 00695 * Factory Method: Instantiate a listener on the internal map that 00696 * will direct events to the passed listener, either synchronously or 00697 * asynchronously as appropriate. 00698 * 00699 * @param hListener the listener to route to 00700 * 00701 * @return a new EventRouter specific to the passed listener 00702 */ 00703 virtual MultiplexingMapListener::Handle instantiateEventRouter( 00704 MapListener::Handle hListener); 00705 00706 /** 00707 * Create a self-processing event queue. 00708 * 00709 * @return a QueueProcessor onto which events can be placed in order 00710 * to be dispatched asynchronously 00711 */ 00712 virtual TaskDaemon::Handle instantiateEventQueue(); 00713 00714 /** 00715 * Obtain this ContinuousQueryCache's event queue. 00716 * 00717 * @return the event queue that this ContinuousQueryCache uses to 00718 * dispatch its events to its non-synchronous listeners 00719 */ 00720 virtual TaskDaemon::Handle getEventQueue(); 00721 00722 /** 00723 * Obtain the existing event queue or create one if none exists. 00724 * 00725 * @return the event queue that this ContinuousQueryCache uses to 00726 * dispatch its events to its non-synchronous listeners 00727 */ 00728 virtual TaskDaemon::Handle ensureEventQueue(); 00729 00730 /** 00731 * Shut down running event queue. 00732 */ 00733 virtual void shutdownEventQueue(); 00734 00735 /** 00736 * Create a new key set. 00737 * 00738 * @return the new key set 00739 */ 00740 virtual Set::Handle instantiateKeySet(); 00741 00742 /** 00743 * Create a new EntrySet 00744 * 00745 * @return the new empty set 00746 */ 00747 virtual Set::Handle instantiateEntrySet(); 00748 00749 /** 00750 * Ensure that the map of indexes maintained by this cache exists. 00751 * 00752 * @return the map of indexes. 00753 */ 00754 virtual Map::Handle ensureIndexMap(); 00755 00756 /** 00757 * Get the map of indexes maintained by this cache. 00758 * 00759 * @return the map of indexes. 00760 */ 00761 virtual Map::View getIndexMap() const; 00762 00763 /** 00764 * Get the map of indexes maintained by this cache. 00765 * 00766 * @return the map of indexes. 00767 */ 00768 virtual Map::Handle getIndexMap(); 00769 00770 /** 00771 * Release the the entire index map. 00772 */ 00773 virtual void releaseIndexMap(); 00774 00775 00776 // ----- Object interface ----------------------------------------------- 00777 00778 protected: 00779 /** 00780 * {@inheritDoc} 00781 */ 00782 virtual void onInit(); 00783 00784 00785 // ----- constants ------------------------------------------------------ 00786 00787 public: 00788 /** 00789 * State: Disconnected state. The content of the ContinousQueryCache is 00790 * not fully synchronized with the underlying [clustered] cache. If the 00791 * value of the ReconnectInterval property is zero, it must be 00792 * configured (synchronized) before it can be used. 00793 */ 00794 static const int32_t state_disconnected = 0; 00795 00796 /** 00797 * State: The ContinuousQueryCache is configuring or re-configuring its 00798 * listeners and content. 00799 */ 00800 static const int32_t state_configuring = 1; 00801 00802 /** 00803 * State: The ContinousQueryCache has been configured. 00804 */ 00805 static const int32_t state_configured = 2; 00806 00807 /** 00808 * State: The ContinousQueryCache has been configured and fully 00809 * synchronized. 00810 */ 00811 static const int32_t state_synchronized = 3; 00812 00813 00814 // ----- data members --------------------------------------------------- 00815 00816 protected: 00817 /** 00818 * The underlying NamedCache object. 00819 */ 00820 mutable MemberHandle<NamedCache> m_hCache; 00821 00822 /** 00823 * The name of the underlying NamedCache. A copy is kept here because 00824 * the reference to the underlying NamedCache is discarded when this 00825 * cache is released. 00826 */ 00827 FinalView<String> f_vsName; 00828 00829 /** 00830 * The filter that represents the subset of information from the 00831 * underlying NamedCache that this ContinuousQueryCache represents. 00832 */ 00833 FinalView<Filter> f_vFilter; 00834 00835 /** 00836 * The option of whether or not to locally cache values. 00837 */ 00838 bool m_fCacheValues; 00839 00840 /** 00841 * The option to disallow modifications through this 00842 * ContinuousQueryCache interface. 00843 */ 00844 bool m_fReadOnly; 00845 00846 /** 00847 * The interval (in millisceonds) that indicates how often the 00848 * ContinuousQueryCache should attempt to synchronize its content with 00849 * the underlying cache in case the connection is severed. 00850 */ 00851 int64_t m_cReconnectMillis; 00852 00853 /** 00854 * The timestamp when the synchronization was last attempted. 00855 */ 00856 mutable Volatile<int64_t> m_ldtConnectionTimestamp; 00857 00858 /** 00859 * The keys that are in this ContinuousQueryCache, and (if 00860 * m_fCacheValues is true) the corresponding values as well. 00861 */ 00862 mutable MemberHandle<ObservableMap> m_hMapLocal; 00863 00864 /** 00865 * State of the ContinousQueryCache. One of the STATE_* enums. 00866 */ 00867 mutable Volatile<int32_t> m_nState; 00868 00869 /** 00870 * While the ContinuousQueryCache is configuring or re-configuring its 00871 * listeners and content, any events that are received must be logged 00872 * to ensure that the corresponding content is in sync. 00873 */ 00874 mutable MemberHandle<Map> m_hMapSyncReq; 00875 00876 /** 00877 * The event queue for this ContinuousQueryCache. 00878 */ 00879 MemberHandle<TaskDaemon> m_hTaskQueue; 00880 00881 /** 00882 * Keeps track of whether the ContinuousQueryCache has listeners that 00883 * require this cache to cache values. 00884 */ 00885 bool m_fListeners; 00886 00887 /** 00888 * The MapEventFilter that uses the ContinuousQueryCache's filter to 00889 * select events that would add elements to this cache's contents. 00890 */ 00891 mutable MemberView<MapEventFilter> m_vFilterAdd; 00892 00893 /** 00894 * The MapEventFilter that uses the ContinuousQueryCache's filter to 00895 * select events that would remove elements from this cache's contents. 00896 */ 00897 mutable MemberView<MapEventFilter> m_vFilterRemove; 00898 00899 /** 00900 * The listener that gets information about what should be in this 00901 * cache. 00902 */ 00903 mutable WeakHandle<MapListener> m_whListenerAdd; 00904 00905 /** 00906 * The listener that gets information about what should be thrown out 00907 * of this cache. 00908 */ 00909 mutable WeakHandle<MapListener> m_whListenerRemove; 00910 00911 /** 00912 * The cache service MemberListener for the underlying NamedCache. 00913 */ 00914 mutable WeakHandle<MemberListener> m_whListenerService; 00915 00916 /* 00917 * The initial MapListener that will receive all the events from the 00918 * ContinuousQueryCache, including those corresponding to its initial 00919 * population. 00920 */ 00921 FinalHandle<MapListener> f_hListener; 00922 00923 /** 00924 * The transformer that should be used to convert values from the 00925 * underlying cache. 00926 */ 00927 FinalView<ValueExtractor> f_vTransformer; 00928 00929 /** 00930 * The map of indexes maintained by this cache. The keys of the Map are 00931 * ValueExtractor objects, and for each key, the corresponding value 00932 * stored in the Map is a MapIndex object. 00933 */ 00934 FinalHandle<Map> f_hMapIndex; 00935 00936 /** 00937 * KeySet backed by this cache 00938 */ 00939 FinalHandle<Set> f_hSetKeys; 00940 00941 /** 00942 * EntrySet backed by this cache 00943 */ 00944 FinalHandle<Set> f_hSetEntries; 00945 00946 00947 // ----- friends -------------------------------------------------------- 00948 00949 friend class AddListener; 00950 friend class RemoveListener; 00951 friend class ServiceListener; 00952 friend class EventRouter; 00953 friend class KeySet; 00954 friend class EntrySet; 00955 friend class KeySetMuterator; 00956 friend class EntrySetIterator; 00957 }; 00958 00959 COH_CLOSE_NAMESPACE3 00960 00961 #endif // COH_CONTINUOUS_QUERY_CACHE_HPP 00962