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

E69640-01

coherence/net/cache/NearCache.hpp

00001 /*
00002 * NearCache.hpp
00003 *
00004 * Copyright (c) 2000, 2016, 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_NEAR_CACHE_HPP
00017 #define COH_NEAR_CACHE_HPP
00018 
00019 #include "coherence/lang.ns"
00020 
00021 #include "coherence/net/CacheService.hpp"
00022 #include "coherence/net/MemberListener.hpp"
00023 #include "coherence/net/NamedCache.hpp"
00024 
00025 #include "coherence/net/cache/CacheMap.hpp"
00026 #include "coherence/net/cache/CachingMap.hpp"
00027 
00028 #include "coherence/util/Comparator.hpp"
00029 #include "coherence/util/ValueExtractor.hpp"
00030 
00031 COH_OPEN_NAMESPACE3(coherence,net,cache)
00032 
00033 using coherence::net::CacheService;
00034 using coherence::net::MemberListener;
00035 using coherence::net::NamedCache;
00036 using coherence::util::Comparator;
00037 using coherence::util::ValueExtractor;
00038 
00039 
00040 /**
00041 * A "near cache" is a CachingMap whose front map is a size-limited and/or
00042 * auto-expiring local cache, and whose back map is a distributed cache.
00043 *
00044 * (A CachingMap is a map that has a "front" map and a "back" map; the front
00045 * map is assumed to be low latency but incomplete, and the back map is
00046 * assumed to be complete but high latency.)
00047 *
00048 * @author tb  2008.07.02
00049 */
00050 class COH_EXPORT NearCache
00051     : public class_spec<NearCache,
00052         extends<CachingMap>,
00053         implements<NamedCache> >
00054     {
00055     friend class factory<NearCache>;
00056 
00057     // ----- constructors ---------------------------------------------------
00058 
00059     protected:
00060         /**
00061         * Construct a NearCache, using a <i>mapBack</i> NamedCache as the
00062         * complete (back) storage and <i>mapFront</i> Map as a near (front)
00063         * storage using the listen_auto invalidation strategy.
00064         *
00065         * @param hMapFront    map to put in front of the back cache
00066         * @param hMapBack     NamedCache to put behind the front cache
00067         * @param strategy     specifies the strategy used for the front map
00068         *                     invalidation
00069         * @param hMapControl  map to keep track of front map updates
00070         */
00071         NearCache(CacheMap::Handle hMapFront, CacheMap::Handle hMapBack,
00072                 CachingMap::InvalidationStrategy strategy = listen_auto,
00073                 ConcurrentMap::Handle hMapControl = NULL);
00074 
00075 
00076     // ----- accessors ------------------------------------------------------
00077 
00078     public:
00079         /**
00080         * Obtain the NamedCache object that sits behind this NearCache.
00081         *
00082         * @return the NamedCache object, which is the back map of this
00083         *         NearCache
00084         *
00085         * @throws IllegalStateException if this NamedCache has been released
00086         */
00087         virtual NamedCache::Handle getBackCache();
00088 
00089         /**
00090         * Obtain the NamedCache object that sits behind this NearCache.
00091         *
00092         * @return the NamedCache object, which is the back map of this
00093         *         NearCache
00094         *
00095         * @throws IllegalStateException if this NamedCache has been released
00096         */
00097         virtual NamedCache::View getBackCache() const;
00098 
00099 
00100     // ----- CachingMap interface -------------------------------------------
00101 
00102     public:
00103         /**
00104         * {@inheritDoc}
00105         */
00106         using CachingMap::put;
00107 
00108         /**
00109         * {@inheritDoc}
00110         */
00111         using CachingMap::keySet;
00112 
00113         /**
00114         * {@inheritDoc}
00115         */
00116         using CachingMap::entrySet;
00117 
00118 
00119     // ----- NamedCache interface -------------------------------------------
00120 
00121     public:
00122         /**
00123         * {@inheritDoc}
00124         */
00125         virtual String::View getCacheName() const;
00126 
00127         /**
00128         * {@inheritDoc}
00129         */
00130         virtual NamedCache::CacheServiceHandle getCacheService();
00131 
00132         /**
00133         * {@inheritDoc}
00134         */
00135         virtual NamedCache::CacheServiceView getCacheService() const;
00136 
00137         /**
00138         * {@inheritDoc}
00139         */
00140         virtual bool isActive() const;
00141 
00142         /**
00143         * {@inheritDoc}
00144         */
00145         virtual void release();
00146 
00147         /**
00148         * {@inheritDoc}
00149         */
00150         virtual void destroy();
00151 
00152         /**
00153         * {@inheritDoc}
00154         */
00155         virtual void truncate();
00156 
00157 
00158     // ----- ObservableMap interface ----------------------------------------
00159 
00160     public:
00161         /**
00162         * {@inheritDoc}
00163         */
00164         virtual void addKeyListener(MapListener::Handle hListener,
00165                 Object::View vKey, bool fLite);
00166 
00167         /**
00168         * {@inheritDoc}
00169         */
00170         virtual void removeKeyListener(MapListener::Handle hListener,
00171                 Object::View vKey);
00172 
00173         /**
00174         * {@inheritDoc}
00175         */
00176         virtual void addMapListener(MapListener::Handle hListener);
00177         
00178         /**
00179         * {@inheritDoc}
00180         */
00181         virtual void removeMapListener(MapListener::Handle hListener);
00182         
00183         /**
00184         * {@inheritDoc}
00185         */
00186         virtual void addFilterListener(MapListener::Handle hListener,
00187                 Filter::View vFilter = NULL, bool fLite = false);
00188 
00189         /**
00190         * {@inheritDoc}
00191         */
00192         virtual void removeFilterListener(MapListener::Handle hListener,
00193                 Filter::View vFilter = NULL);
00194 
00195 
00196     // ----- CacheMap interface ---------------------------------------------
00197 
00198     public:
00199         /**
00200         * {@inheritDoc}
00201         */
00202         virtual Map::View getAll(Collection::View vColKeys) const;
00203 
00204         /**
00205         * {@inheritDoc}
00206         */
00207         virtual Object::Holder put(Object::View vKey,
00208                 Object::Holder ohValue, int64_t cMillis);
00209 
00210 
00211     // ----- ConcurrentMap interface ----------------------------------------
00212 
00213     public:
00214         /**
00215         * {@inheritDoc}
00216         */
00217         virtual bool lock(Object::View vKey, int64_t cWait) const;
00218 
00219         /**
00220         * {@inheritDoc}
00221         */
00222         virtual bool lock(Object::View vKey) const;
00223 
00224         /**
00225         * {@inheritDoc}
00226         */
00227         virtual bool unlock(Object::View vKey) const;
00228 
00229 
00230     // ----- QueryMap interface ---------------------------------------------
00231 
00232     public:
00233         /**
00234         * {@inheritDoc}
00235         */
00236         virtual Set::View keySet(Filter::View vFilter) const;
00237 
00238         /**
00239         * {@inheritDoc}
00240         */
00241         virtual Set::View entrySet(Filter::View vFilter) const;
00242 
00243         /**
00244         * {@inheritDoc}
00245         */
00246         virtual Set::View entrySet(Filter::View vFilter,
00247                 Comparator::View vComparator) const;
00248 
00249         /**
00250         * {@inheritDoc}
00251         */
00252         virtual void addIndex(ValueExtractor::View vExtractor, bool fOrdered,
00253                 Comparator::View vComparator);
00254 
00255         /**
00256         * {@inheritDoc}
00257         */
00258         virtual void removeIndex(ValueExtractor::View vExtractor);
00259 
00260 
00261     // ----- InvocableMap interface -----------------------------------------
00262 
00263     public:
00264         /**
00265         * {@inheritDoc}
00266         */
00267         virtual Object::Holder invoke(Object::View vKey,
00268                 EntryProcessor::Handle hAgent);
00269 
00270         /**
00271         * {@inheritDoc}
00272         */
00273         virtual Map::View invokeAll(Collection::View vCollKeys,
00274                 EntryProcessor::Handle hAgent);
00275 
00276         /**
00277         * {@inheritDoc}
00278         */
00279         virtual Map::View invokeAll(Filter::View vFilter,
00280                 EntryProcessor::Handle hAgent);
00281 
00282         /**
00283         * {@inheritDoc}
00284         */
00285         virtual Object::Holder aggregate(Collection::View vCollKeys,
00286                 EntryAggregator::Handle hAgent) const;
00287 
00288         /**
00289         * {@inheritDoc}
00290         */
00291         virtual Object::Holder aggregate(Filter::View vFilter,
00292                 EntryAggregator::Handle hAgent) const;
00293 
00294 
00295     // ----- Object interface -----------------------------------------------
00296 
00297     protected:
00298         /**
00299         * {@inheritDoc}
00300         */
00301         virtual void onInit();
00302 
00303 
00304     // ----- internal helpers -----------------------------------------------
00305 
00306     protected:
00307         /**
00308         * Release this cache, optionally destroying it.
00309         *
00310         * @param fDestroy  true to destroy the cache as well
00311         */
00312         virtual void release(bool fDestroy);
00313 
00314         /**
00315         * Instantiate and register a MemberListener with the back cache's
00316         * service.
00317         *
00318         * The primary goal of that listener is invalidation of the front map
00319         * in case of the service [automatic] restart.
00320         *
00321         * @return the instantiated and registered MemberListener object
00322         */
00323         virtual MemberListener::Handle registerBackServiceListener();
00324 
00325         /**
00326         * Unregister back caches's service member listener.
00327         */
00328         virtual void unregisterBackServiceListener();
00329 
00330 
00331     // ----- data fields ----------------------------------------------------
00332 
00333     protected:
00334         /**
00335         * Cache name
00336         */
00337         FinalView<String> f_vsName;
00338 
00339         /**
00340         * The back cache service.
00341         */
00342         FinalHandle<CacheService> f_hService;
00343 
00344         /**
00345         * The back cache service MemberListener.
00346         */
00347         FinalHandle<MemberListener> f_hListenerBackService;
00348     };
00349 
00350 COH_CLOSE_NAMESPACE3
00351 
00352 #endif // COH_NEAR_CACHE_HPP
Copyright © 2000, 2016, Oracle and/or its affiliates. All rights reserved.