Infinispan HotRod C++ Client  8.2.1.Final
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
RemoteCacheManager.h
Go to the documentation of this file.
1 #ifndef ISPN_HOTROD_REMOTECACHEMANAGER_H
2 #define ISPN_HOTROD_REMOTECACHEMANAGER_H
3 
8 
9 #include <string>
10 #include <map>
11 #include <memory>
12 
13 namespace infinispan {
14 namespace hotrod {
15 
16 class RemoteCacheManagerImpl;
17 
39 {
40 public:
41 
49  explicit RemoteCacheManager(bool start_ = true);
50 
52  const std::map<std::string, std::string>& configuration,
53  bool start_ = true) {
54  init(configuration, start_);
55  }
56 
66  explicit RemoteCacheManager(
67  const Configuration& configuration,
68  bool start = true);
69 
71 
76  void start();
77 
82  void stop();
83 
91  bool isStarted();
92 
100  const Configuration& getConfiguration();
101 
109  template <class K, class V> RemoteCache<K, V> &getCache(
110  bool forceReturnValue) {
111  const std::string key = forceReturnValue ? "/true" : "/false";
112  if (remoteCacheMap.find(key)==remoteCacheMap.end())
113  {
114  RemoteCache<K,V> *pRc;
115  pRc= new RemoteCache<K,V>();
116  remoteCacheMap[key]= std::unique_ptr<RemoteCacheBase>(pRc);
117  RemoteCache<K, V> *rcache=(RemoteCache<K, V> *)remoteCacheMap[key].get();
118  rcache->keyMarshaller.reset(new BasicMarshaller<K>());
119  rcache->valueMarshaller.reset(new BasicMarshaller<V>());
120  initCache(*rcache, forceReturnValue, getConfiguration().getNearCacheConfiguration());
121  return *rcache;
122  }
123  return *(RemoteCache<K, V> *)remoteCacheMap[key].get();
124  }
125 
134  template <class K, class V> RemoteCache<K, V> &getCache() {
135  return getCache<K,V>(getConfiguration().isForceReturnValue());
136  }
137 
145  template <class K, class V> RemoteCache<K, V> &getCache(
146  const std::string& name, bool forceReturnValue) {
147  const std::string key = forceReturnValue ? name+"/true" : name+"/false";
148  if (remoteCacheMap.find(key)==remoteCacheMap.end())
149  {
151  remoteCacheMap[key]= std::unique_ptr<RemoteCacheBase>(pRc);
152  RemoteCache<K, V> *rcache=(RemoteCache<K, V> *)remoteCacheMap[key].get();
153  rcache->keyMarshaller.reset(new BasicMarshaller<K>());
154  rcache->valueMarshaller.reset(new BasicMarshaller<V>());
155  initCache(*rcache, name.c_str(), forceReturnValue);
156  return *rcache;
157  }
158  return *(RemoteCache<K, V> *)remoteCacheMap[key].get();
159  }
160 
169  template <class K, class V> RemoteCache<K, V> &getCache(
170  const std::string& name) {
171  return getCache<K,V>(name, getConfiguration().isForceReturnValue());
172  }
173 
184  template<class K, class V> RemoteCache<K, V> &getCache(
185  Marshaller<K> *km, void (*kd)(Marshaller<K> *),
186  Marshaller<V> *vm, void (*vd)(Marshaller<V> *), bool forceReturnValue) {
187  const std::string key = forceReturnValue ? "/true" : "/false";
188  if (remoteCacheMap.find(key) == remoteCacheMap.end()) {
190  remoteCacheMap[key] = std::unique_ptr < RemoteCacheBase > (pRc);
191  }
192  RemoteCache<K, V> *rcache =
193  (RemoteCache<K, V> *) remoteCacheMap[key].get();
194  rcache->keyMarshaller.reset(km);
195  rcache->valueMarshaller.reset(vm);
196  initCache(*rcache, forceReturnValue, getConfiguration().getNearCacheConfiguration());
197  return *rcache;
198  }
199 
213  template<class K, class V> RemoteCache<K, V> &getCache(
214  Marshaller<K> *km, void (*kd)(Marshaller<K> *),
215  Marshaller<V> *vm, void (*vd)(Marshaller<V> *)) {
216  return getCache<K,V>(km, kd, vm, vd, getConfiguration().isForceReturnValue());
217  }
229  template <class K, class V> RemoteCache<K, V> &getCache(
230  Marshaller<K> *km, void (*kd)(Marshaller<K> *),
231  Marshaller<V> *vm, void (*vd)(Marshaller<V> *),
232  const std::string& name, bool forceReturnValue) {
233  const std::string key = forceReturnValue ? name+"/true" : name+"/false";
234  if (remoteCacheMap.find(key) == remoteCacheMap.end()) {
236  remoteCacheMap[key] = std::unique_ptr < RemoteCacheBase > (pRc);
237  }
238  RemoteCache<K, V> *rcache =
239  (RemoteCache<K, V> *) remoteCacheMap[key].get();
240  rcache->keyMarshaller.reset(km);
241  rcache->valueMarshaller.reset(vm);
242  initCache(*rcache, name.c_str(), forceReturnValue, getConfiguration().getNearCacheConfiguration());
243  return *rcache;
244  }
245 
256  template <class K, class V> RemoteCache<K, V> &getCache(
257  Marshaller<K> *km, void (*kd)(Marshaller<K> *),
258  Marshaller<V> *vm, void (*vd)(Marshaller<V> *),
259  const std::string& name) {
260  return getCache(km, kd, vm, vd, name, getConfiguration().isForceReturnValue());
261  }
268  bool switchToDefaultCluster();
269 
276  bool switchToCluster(std::string clusterName);
277 
278 private:
279  void *impl;
280  std::map<std::string, std::unique_ptr<RemoteCacheBase> > remoteCacheMap;
281 
282  void init(const std::map<std::string, std::string>& configuration, bool start);
283 
284  void initCache(RemoteCacheBase& cache, bool forceReturnValue, NearCacheConfiguration nc = NearCacheConfiguration());
285  void initCache(RemoteCacheBase& cache, const char *name, bool forceReturnValue, NearCacheConfiguration nc = NearCacheConfiguration());
286 
287  // not implemented
289  RemoteCacheManager operator=(const RemoteCacheManager&);
290 
291  template<typename T> static void genericDelete(T *t) { delete t; }
292  template<typename T> static void genericNoDelete(T *) { }
293 };
294 
295 }} // namespace infinispan::hotrod
296 
297 #endif /* ISPN_HOTROD_REMOTECACHEMANAGER_H */
RemoteCache< K, V > & getCache(Marshaller< K > *km, void(*kd)(Marshaller< K > *), Marshaller< V > *vm, void(*vd)(Marshaller< V > *))
Definition: RemoteCacheManager.h:213
RemoteCache< K, V > & getCache(Marshaller< K > *km, void(*kd)(Marshaller< K > *), Marshaller< V > *vm, void(*vd)(Marshaller< V > *), bool forceReturnValue)
Definition: RemoteCacheManager.h:184
#define HR_EXTERN
Definition: ImportExport.h:35
RemoteCacheManager(const std::map< std::string, std::string > &configuration, bool start_=true)
Definition: RemoteCacheManager.h:51
RemoteCache< K, V > & getCache(Marshaller< K > *km, void(*kd)(Marshaller< K > *), Marshaller< V > *vm, void(*vd)(Marshaller< V > *), const std::string &name)
Definition: RemoteCacheManager.h:256
Definition: NearCacheConfiguration.h:32
RemoteCache< K, V > & getCache()
Definition: RemoteCacheManager.h:134
RemoteCache< K, V > & getCache(const std::string &name)
Definition: RemoteCacheManager.h:169
Definition: CacheClientListener.h:28
RemoteCache< K, V > & getCache(bool forceReturnValue)
Definition: RemoteCacheManager.h:109
RemoteCache< K, V > & getCache(Marshaller< K > *km, void(*kd)(Marshaller< K > *), Marshaller< V > *vm, void(*vd)(Marshaller< V > *), const std::string &name, bool forceReturnValue)
Definition: RemoteCacheManager.h:229
Definition: Configuration.h:28
Definition: RemoteCacheManager.h:38
Definition: BasicMarshaller.h:18
RemoteCache< K, V > & getCache(const std::string &name, bool forceReturnValue)
Definition: RemoteCacheManager.h:145
Definition: Marshaller.h:12