Hazelcast C++ Client
NearCacheManager.h
1 /*
2  * Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef HAZELCAST_CLIENT_INTERNAL_NEARCACHE_NEARCACHEMANAGER_H_
17 #define HAZELCAST_CLIENT_INTERNAL_NEARCACHE_NEARCACHEMANAGER_H_
18 
19 #include <string>
20 #include <vector>
21 
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/serialization/pimpl/SerializationService.h"
26 
27 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
28 #pragma warning(push)
29 #pragma warning(disable: 4251) //for dll export
30 #endif
31 
32 namespace hazelcast {
33  namespace client {
34  namespace internal {
35  namespace nearcache {
39  class HAZELCAST_API NearCacheManager {
40  public:
41  NearCacheManager(serialization::pimpl::SerializationService &ss, util::ILogger &logger);
42 
52  template<typename K, typename V, typename KS>
53  boost::shared_ptr<NearCache<KS, V> > getNearCache(const std::string &name) {
54  return boost::static_pointer_cast<NearCache<KS, V> >(nearCacheMap.get(name));
55  };
56 
69  template<typename K, typename V, typename KS>
70  boost::shared_ptr<NearCache<KS, V> > getOrCreateNearCache(
71  const std::string &name, const client::config::NearCacheConfig<K, V> &nearCacheConfig) {
72  boost::shared_ptr<BaseNearCache> nearCache = nearCacheMap.get(name);
73  if (NULL == nearCache.get()) {
74  {
75  util::LockGuard guard(mutex);
76  nearCache = nearCacheMap.get(name);
77  if (NULL == nearCache.get()) {
78  nearCache = createNearCache<K, V, KS>(name, nearCacheConfig);
79  nearCache->initialize();
80 
81  nearCacheMap.put(name, nearCache);
82  }
83 
84  }
85  }
86  return boost::static_pointer_cast<NearCache<KS, V> >(nearCache);
87  }
88 
95  bool clearNearCache(const std::string &name);
96 
100  void clearAllNearCaches();
101 
108  bool destroyNearCache(const std::string &name);
109 
113  void destroyAllNearCaches();
114 
120  std::vector<boost::shared_ptr<BaseNearCache> > listAllNearCaches();
121  protected:
122  template<typename K, typename V, typename KS>
123  std::auto_ptr<NearCache<KS, V> > createNearCache(
124  const std::string &name, const client::config::NearCacheConfig<K, V> &nearCacheConfig) {
125  return std::auto_ptr<NearCache<KS, V> >(
126  new impl::DefaultNearCache<K, V, KS>(
127  name, nearCacheConfig, serializationService, logger));
128  }
129  private:
130  serialization::pimpl::SerializationService &serializationService;
131  util::ILogger &logger;
132  util::SynchronizedMap<std::string, BaseNearCache> nearCacheMap;
133  util::Mutex mutex;
134  };
135  }
136  }
137  }
138 };
139 
140 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
141 #pragma warning(pop)
142 #endif
143 
144 #endif /* HAZELCAST_CLIENT_INTERNAL_NEARCACHE_NEARCACHEMANAGER_H_ */
Contains the configuration for a Near Cache.
Definition: NearCacheConfig.h:44
NearCache is the contract point to store keys and values in underlying com.hazelcast.cache.impl.nearcache.NearCacheRecordStore.
Definition: NearCache.h:82
boost::shared_ptr< NearCache< KS, V > > getNearCache(const std::string &name)
Gets the NearCache instance associated with given.
Definition: NearCacheManager.h:53
NearCacheManager is the contract point to manage all existing NearCache instances.
Definition: NearCacheManager.h:39
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32
boost::shared_ptr< NearCache< KS, V > > getOrCreateNearCache(const std::string &name, const client::config::NearCacheConfig< K, V > &nearCacheConfig)
Creates a new NearCache with given configurations or returns existing one.
Definition: NearCacheManager.h:70