Infinispan HotRod C++ Client  8.3.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 
10 
11 
12 
13 #include <string>
14 #include <map>
15 #include <memory>
16 
17 namespace infinispan {
18 namespace hotrod {
19 
20 class RemoteCacheManagerImpl;
22 
44 {
45 public:
46 
54  explicit RemoteCacheManager(bool start_ = true);
55 
57  const std::map<std::string, std::string>& configuration,
58  bool start_ = true) : transactionManager(TransactionManagerLookup::lookup()) {
59  init(configuration, start_);
60  }
61 
71  explicit RemoteCacheManager(
72  const Configuration& configuration,
73  bool start = true);
74 
76 
81  void start();
82 
87  void stop();
88 
96  bool isStarted();
97 
105  const Configuration& getConfiguration();
106 
114  template <class K, class V> RemoteCache<K, V> &getCache(
115  bool forceReturnValue) {
116  const std::string key = forceReturnValue ? "/true" : "/false";
117  if (remoteCacheMap.find(key)==remoteCacheMap.end())
118  {
119  RemoteCache<K,V> *pRc;
120  pRc= new RemoteCache<K,V>(transactionManager, transactionTable, forceReturnValue, getConfiguration().isTransactional());
121  remoteCacheMap[key]= std::unique_ptr<RemoteCacheBase>(pRc);
122  RemoteCache<K, V> *rcache=(RemoteCache<K, V> *)remoteCacheMap[key].get();
123  rcache->keyMarshaller.reset(new BasicMarshaller<K>());
124  rcache->valueMarshaller.reset(new BasicMarshaller<V>());
125  initCache(*rcache, forceReturnValue, getConfiguration().getNearCacheConfiguration());
126  return *rcache;
127  }
128  return *(RemoteCache<K, V> *)remoteCacheMap[key].get();
129  }
130 
139  template <class K, class V> RemoteCache<K, V> &getCache() {
140  return getCache<K,V>(getConfiguration().isForceReturnValue());
141  }
142 
150  template <class K, class V> RemoteCache<K, V> &getCache(
151  const std::string& name, bool forceReturnValue) {
152  const std::string key = forceReturnValue ? name+"/true" : name+"/false";
153  if (remoteCacheMap.find(key)==remoteCacheMap.end())
154  {
155  RemoteCache<K,V> *pRc= new RemoteCache<K,V>(transactionManager, transactionTable, forceReturnValue, getConfiguration().isTransactional());
156  remoteCacheMap[key]= std::unique_ptr<RemoteCacheBase>(pRc);
157  RemoteCache<K, V> *rcache=(RemoteCache<K, V> *)remoteCacheMap[key].get();
158  rcache->keyMarshaller.reset(new BasicMarshaller<K>());
159  rcache->valueMarshaller.reset(new BasicMarshaller<V>());
160  initCache(*rcache, name.c_str(), forceReturnValue);
161  return *rcache;
162  }
163  return *(RemoteCache<K, V> *)remoteCacheMap[key].get();
164  }
165 
174  template <class K, class V> RemoteCache<K, V> &getCache(
175  const std::string& name) {
176  return getCache<K,V>(name, getConfiguration().isForceReturnValue());
177  }
178 
189  template<class K, class V> RemoteCache<K, V> &getCache(
190  Marshaller<K> *km, void (*kd)(Marshaller<K> *),
191  Marshaller<V> *vm, void (*vd)(Marshaller<V> *), bool forceReturnValue) {
192  const std::string key = forceReturnValue ? "/true" : "/false";
193  if (remoteCacheMap.find(key) == remoteCacheMap.end()) {
194  RemoteCache<K, V> *pRc = new RemoteCache<K, V>(transactionManager, transactionTable, forceReturnValue, getConfiguration().isTransactional());
195  remoteCacheMap[key] = std::unique_ptr < RemoteCacheBase > (pRc);
196  }
197  RemoteCache<K, V> *rcache =
198  (RemoteCache<K, V> *) remoteCacheMap[key].get();
199  rcache->keyMarshaller.reset(km);
200  rcache->valueMarshaller.reset(vm);
201  initCache(*rcache, forceReturnValue, getConfiguration().getNearCacheConfiguration());
202  return *rcache;
203  }
204 
218  template<class K, class V> RemoteCache<K, V> &getCache(
219  Marshaller<K> *km, void (*kd)(Marshaller<K> *),
220  Marshaller<V> *vm, void (*vd)(Marshaller<V> *)) {
221  return getCache<K,V>(km, kd, vm, vd, getConfiguration().isForceReturnValue());
222  }
234  template <class K, class V> RemoteCache<K, V> &getCache(
235  Marshaller<K> *km, void (*kd)(Marshaller<K> *),
236  Marshaller<V> *vm, void (*vd)(Marshaller<V> *),
237  const std::string& name, bool forceReturnValue) {
238  const std::string key = forceReturnValue ? name+"/true" : name+"/false";
239  if (remoteCacheMap.find(key) == remoteCacheMap.end()) {
240  RemoteCache<K, V> *pRc = new RemoteCache<K, V>(transactionManager, transactionTable, forceReturnValue, getConfiguration().isTransactional());
241  remoteCacheMap[key] = std::unique_ptr < RemoteCacheBase > (pRc);
242  }
243  RemoteCache<K, V> *rcache =
244  (RemoteCache<K, V> *) remoteCacheMap[key].get();
245  rcache->keyMarshaller.reset(km);
246  rcache->valueMarshaller.reset(vm);
247  initCache(*rcache, name.c_str(), forceReturnValue, getConfiguration().getNearCacheConfiguration());
248  return *rcache;
249  }
250 
261  template <class K, class V> RemoteCache<K, V> &getCache(
262  Marshaller<K> *km, void (*kd)(Marshaller<K> *),
263  Marshaller<V> *vm, void (*vd)(Marshaller<V> *),
264  const std::string& name) {
265  return getCache(km, kd, vm, vd, name, getConfiguration().isForceReturnValue());
266  }
273  bool switchToDefaultCluster();
274 
281  bool switchToCluster(std::string clusterName);
282 
283  RemoteCounterManager& getCounterManager();
290  std::shared_ptr<RemoteCacheManagerAdmin> administration() {
291  return newRemoteCacheManagerAdmin();
292  }
293 
294  std::set<std::string> getCacheNames();
296  {
297  return transactionManager;
298  }
299 
300 private:
301  void *impl;
302  std::map<std::string, std::unique_ptr<RemoteCacheBase> > remoteCacheMap;
303  std::function<void(std::string&)> cacheRemover;
304  TransactionManager& transactionManager;
305  TransactionTable transactionTable;
306 
307  void init(const std::map<std::string, std::string>& configuration, bool start);
308 
309  void initCache(RemoteCacheBase& cache, bool forceReturnValue, NearCacheConfiguration nc = NearCacheConfiguration());
310  void initCache(RemoteCacheBase& cache, const char *name, bool forceReturnValue, NearCacheConfiguration nc = NearCacheConfiguration());
311 
312  // not implemented
314  RemoteCacheManager operator=(const RemoteCacheManager&);
315 
316  std::shared_ptr<RemoteCacheManagerAdmin> newRemoteCacheManagerAdmin();
317 
318  template<typename T> static void genericDelete(T *t) { delete t; }
319  template<typename T> static void genericNoDelete(T *) { }
320 };
321 
322 }} // namespace infinispan::hotrod
323 
324 #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:218
RemoteCache< K, V > & getCache(Marshaller< K > *km, void(*kd)(Marshaller< K > *), Marshaller< V > *vm, void(*vd)(Marshaller< V > *), bool forceReturnValue)
Definition: RemoteCacheManager.h:189
Definition: Transactions.h:174
Definition: RemoteCounterManager.h:20
#define HR_EXTERN
Definition: ImportExport.h:35
RemoteCacheManager(const std::map< std::string, std::string > &configuration, bool start_=true)
Definition: RemoteCacheManager.h:56
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:261
Definition: NearCacheConfiguration.h:32
RemoteCache< K, V > & getCache()
Definition: RemoteCacheManager.h:139
RemoteCache< K, V > & getCache(const std::string &name)
Definition: RemoteCacheManager.h:174
Definition: TransactionManager.h:24
Definition: CacheClientListener.h:28
RemoteCache< K, V > & getCache(bool forceReturnValue)
Definition: RemoteCacheManager.h:114
std::shared_ptr< RemoteCacheManagerAdmin > administration()
Definition: RemoteCacheManager.h:290
TransactionManager & getTransactionManager() const
Definition: RemoteCacheManager.h:295
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:234
Definition: Configuration.h:28
Definition: RemoteCacheManager.h:43
Definition: BasicMarshaller.h:18
RemoteCache< K, V > & getCache(const std::string &name, bool forceReturnValue)
Definition: RemoteCacheManager.h:150
Definition: RemoteCacheManagerAdmin.h:39
Definition: Marshaller.h:12
Definition: TransactionManager.h:69