16 #ifndef HAZELCAST_CLIENT_INTERNAL_NEARCACHE_NEARCACHEMANAGER_H_
17 #define HAZELCAST_CLIENT_INTERNAL_NEARCACHE_NEARCACHEMANAGER_H_
22 #include "hazelcast/util/HazelcastDll.h"
23 #include "hazelcast/client/internal/nearcache/NearCache.h"
24 #include "hazelcast/client/internal/nearcache/impl/DefaultNearCache.h"
25 #include "hazelcast/client/internal/adapter/DataStructureAdapter.h"
26 #include "hazelcast/client/serialization/pimpl/SerializationService.h"
28 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
30 #pragma warning(disable: 4251) //for dll export
43 : serializationService(ss) {
55 template<
typename K,
typename V,
typename KS>
56 boost::shared_ptr<NearCache<KS, V> >
getNearCache(
const std::string &name) {
57 return boost::static_pointer_cast<
NearCache<KS, V> >(nearCacheMap.get(name));
74 template<
typename K,
typename V,
typename KS>
78 boost::shared_ptr<BaseNearCache> nearCache = nearCacheMap.get(name);
79 if (NULL == nearCache.get()) {
81 util::LockGuard guard(mutex);
82 nearCache = nearCacheMap.get(name);
83 if (NULL == nearCache.get()) {
84 nearCache = createNearCache<K, V, KS>(name, nearCacheConfig);
85 nearCache->initialize();
87 nearCacheMap.put(name, nearCache);
111 boost::shared_ptr<BaseNearCache> nearCache = nearCacheMap.get(name);
112 if (nearCache.get() != NULL) {
115 return nearCache.get() != NULL;
122 std::vector<boost::shared_ptr<BaseNearCache> > caches = nearCacheMap.values();
123 for (std::vector<boost::shared_ptr<BaseNearCache> >::iterator it = caches.begin();
124 it != caches.end(); ++it) {
136 boost::shared_ptr<BaseNearCache> nearCache = nearCacheMap.remove(name);
137 if (nearCache.get() != NULL) {
138 nearCache->destroy();
140 return nearCache.get() != NULL;
147 std::vector<boost::shared_ptr<BaseNearCache> > caches = nearCacheMap.values();
148 for (std::vector<boost::shared_ptr<BaseNearCache> >::iterator it = caches.begin();
149 it != caches.end(); ++it) {
154 template<
typename K,
typename V,
typename KS>
155 std::auto_ptr<NearCache<KS, V> > createNearCache(
157 return std::auto_ptr<NearCache<KS, V> >(
158 new impl::DefaultNearCache<K, V, KS>(
159 name, nearCacheConfig, serializationService));
162 serialization::pimpl::SerializationService &serializationService;
163 util::SynchronizedMap<std::string, BaseNearCache> nearCacheMap;
171 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
void destroyAllNearCaches()
Destroys all defined NearCache instances.
Definition: NearCacheManager.h:146
Contains the configuration for a Near Cache.
Definition: NearCacheConfig.h:42
Abstracts the Hazelcast data structures with Near Cache support for the Near Cache usage...
Definition: DataStructureAdapter.h:37
bool destroyNearCache(const std::string &name)
Destroys NearCache instance associated with given.
Definition: NearCacheManager.h:135
NearCache is the contract point to store keys and values in underlying com.hazelcast.cache.impl.nearcache.NearCacheRecordStore.
Definition: NearCache.h:68
boost::shared_ptr< NearCache< KS, V > > getNearCache(const std::string &name)
Gets the NearCache instance associated with given.
Definition: NearCacheManager.h:56
NearCacheManager is the contract point to manage all existing NearCache instances.
Definition: NearCacheManager.h:40
void clearAllNearCaches()
Clears all defined NearCache instances.
Definition: NearCacheManager.h:121
boost::shared_ptr< NearCache< KS, V > > getOrCreateNearCache(const std::string &name, const config::NearCacheConfig< K, V > &nearCacheConfig, std::auto_ptr< adapter::DataStructureAdapter< K, V > > &dataStructureAdapter)
Creates a new NearCache with given configurations or returns existing one.
Definition: NearCacheManager.h:75
bool clearNearCache(const std::string &name)
Lists all existing NearCache instances.
Definition: NearCacheManager.h:110