JBoss Data Grid HotRod C++ Client  7.0.0
 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 
9 
10 #include <string>
11 #include <map>
12 #include <memory>
13 
14 namespace infinispan {
15 namespace hotrod {
16 
17 class RemoteCacheManagerImpl;
18 
40 {
41 public:
42 
50  explicit RemoteCacheManager(bool start_ = true);
51 
53  const std::map<std::string, std::string>& configuration,
54  bool start_ = true) {
56  configuration, portable::string::convert(), portable::string::convert()), start_);
57  }
58 
68  explicit RemoteCacheManager(
69  const Configuration& configuration,
70  bool start = true);
71 
73 
78  void start();
79 
84  void stop();
85 
93  bool isStarted();
94 
102  const Configuration& getConfiguration();
103 
118  template <class K, class V> RemoteCache<K, V> &getCache(
119  bool forceReturnValue = false)
120  {
121  const std::string key = forceReturnValue ? "/true" : "/false";
122  if (remoteCacheMap.find(key)==remoteCacheMap.end())
123  {
125  remoteCacheMap[key]= std::unique_ptr<RemoteCacheBase>(pRc);
126  RemoteCache<K, V> *rcache=(RemoteCache<K, V> *)remoteCacheMap[key].get();
127  initCache(*rcache, forceReturnValue);
128  rcache->keyMarshaller.reset(new BasicMarshaller<K>(), &Marshaller<K>::destroy);
129  rcache->valueMarshaller.reset(new BasicMarshaller<V>(), &Marshaller<V>::destroy);
130  return *rcache;
131  }
132  return *(RemoteCache<K, V> *)remoteCacheMap[key].get();
133  }
134 
150  template <class K, class V> RemoteCache<K, V> &getCache(
151  const std::string& name, bool forceReturnValue = false)
152  {
153  const std::string key = forceReturnValue ? name+"/true" : name+"/false";
154  if (remoteCacheMap.find(key)==remoteCacheMap.end())
155  {
157  remoteCacheMap[key]= std::unique_ptr<RemoteCacheBase>(pRc);
158  RemoteCache<K, V> *rcache=(RemoteCache<K, V> *)remoteCacheMap[key].get();
159  initCache(*rcache, name.c_str(), forceReturnValue);
160  rcache->keyMarshaller.reset(new BasicMarshaller<K>(), &Marshaller<K>::destroy);
161  rcache->valueMarshaller.reset(new BasicMarshaller<V>(), &Marshaller<V>::destroy);
162  return *rcache;
163  }
164  return *(RemoteCache<K, V> *)remoteCacheMap[key].get();
165  }
166 
186  template<class K, class V> RemoteCache<K, V> &getCache(Marshaller<K> *km,
187  void (*kd)(Marshaller<K> *), Marshaller<V> *vm,
188  void (*vd)(Marshaller<V> *), bool forceReturnValue = false) {
189  const std::string key = forceReturnValue ? "/true" : "/false";
190  if (remoteCacheMap.find(key) == remoteCacheMap.end()) {
192  remoteCacheMap[key] = std::unique_ptr < RemoteCacheBase > (pRc);
193  RemoteCache<K, V> *rcache =
194  (RemoteCache<K, V> *) remoteCacheMap[key].get();
195  initCache(*rcache, forceReturnValue);
196  rcache->keyMarshaller.reset(km, kd);
197  rcache->valueMarshaller.reset(km, kd);
198  return *rcache;
199  }
200  RemoteCache<K, V> *rcache =
201  (RemoteCache<K, V> *) remoteCacheMap[key].get();
202  initCache(*rcache, forceReturnValue);
203  rcache->keyMarshaller.reset(km, kd);
204  rcache->valueMarshaller.reset(vm, vd);
205  return *rcache;
206  }
207 
228  template <class K, class V> RemoteCache<K, V> &getCache(
229  Marshaller<K> *km, void (*kd)(Marshaller<K> *),
230  Marshaller<V> *vm, void (*vd)(Marshaller<V> *),
231  const std::string& name, bool forceReturnValue = false)
232  {
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  RemoteCache<K, V> *rcache =
238  (RemoteCache<K, V> *) remoteCacheMap[key].get();
239  initCache(*rcache, name.c_str(), forceReturnValue);
240  rcache->keyMarshaller.reset(km, kd);
241  rcache->valueMarshaller.reset(vm, vd);
242  return *rcache;
243  }
244  RemoteCache<K, V> *rcache =
245  (RemoteCache<K, V> *) remoteCacheMap[key].get();
246  initCache(*rcache, name.c_str(), forceReturnValue);
247  rcache->keyMarshaller.reset(km, kd);
248  rcache->valueMarshaller.reset(vm, vd);
249  return *rcache;
250  }
251 
252 
253 private:
254  void *impl;
255  std::map<std::string, std::unique_ptr<RemoteCacheBase> > remoteCacheMap;
256 
257  void init(const portable::map<portable::string, portable::string>& configuration, bool start);
258 
259  void initCache(RemoteCacheBase& cache, bool forceReturnValue);
260  void initCache(RemoteCacheBase& cache, const char *name, bool forceReturnValue);
261 
262  // not implemented
264  RemoteCacheManager operator=(const RemoteCacheManager&);
265 
266  template<typename T> static void genericDelete(T *t) { delete t; }
267  template<typename T> static void genericNoDelete(T *) { }
268 };
269 
270 }} // namespace infinispan::hotrod
271 
272 #endif /* ISPN_HOTROD_REMOTECACHEMANAGER_H */
#define HR_EXTERN
Definition: ImportExport.h:35
RemoteCacheManager(const std::map< std::string, std::string > &configuration, bool start_=true)
Definition: RemoteCacheManager.h:52
RemoteCache< K, V > & getCache(const std::string &name, bool forceReturnValue=false)
Definition: RemoteCacheManager.h:150
Definition: portable.h:275
RemoteCache< K, V > & getCache(bool forceReturnValue=false)
Definition: RemoteCacheManager.h:118
Definition: RemoteCache.h:58
Definition: Configuration.h:24
Definition: RemoteCacheManager.h:39
Definition: BasicMarshaller.h:17
RemoteCache< K, V > & getCache(Marshaller< K > *km, void(*kd)(Marshaller< K > *), Marshaller< V > *vm, void(*vd)(Marshaller< V > *), bool forceReturnValue=false)
Definition: RemoteCacheManager.h:186
Definition: RemoteCacheBase.h:32
RemoteCache< K, V > & getCache(Marshaller< K > *km, void(*kd)(Marshaller< K > *), Marshaller< V > *vm, void(*vd)(Marshaller< V > *), const std::string &name, bool forceReturnValue=false)
Definition: RemoteCacheManager.h:228
Definition: Marshaller.h:13