JBoss Data Grid HotRod C++ Client  6.6.1
 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 
13 namespace infinispan {
14 namespace hotrod {
15 
37 {
38 public:
39 
47  explicit RemoteCacheManager(bool start_ = true);
48 
50  const std::map<std::string, std::string>& configuration,
51  bool start_ = true) {
53  configuration, portable::string::convert(), portable::string::convert()), start_);
54  }
55 
65  explicit RemoteCacheManager(
66  const Configuration& configuration,
67  bool start = true);
68 
70 
75  void start();
76 
81  void stop();
82 
90  bool isStarted();
91 
99  const Configuration& getConfiguration();
100 
115  template <class K, class V> RemoteCache<K, V> getCache(
116  bool forceReturnValue = false)
117  {
118  RemoteCache<K, V> rcache;
119  initCache(rcache, forceReturnValue);
120  rcache.keyMarshaller.reset(new BasicMarshaller<K>(), &Marshaller<K>::destroy);
121  rcache.valueMarshaller.reset(new BasicMarshaller<V>(), &Marshaller<V>::destroy);
122  return rcache;
123  }
124 
140  template <class K, class V> RemoteCache<K, V> getCache(
141  const std::string& name, bool forceReturnValue = false)
142  {
143  RemoteCache<K, V> rcache;
144  initCache(rcache, name.c_str(), forceReturnValue);
145  rcache.keyMarshaller.reset(new BasicMarshaller<K>(), &Marshaller<K>::destroy);
146  rcache.valueMarshaller.reset(new BasicMarshaller<V>(), &Marshaller<V>::destroy);
147  return rcache;
148  }
149 
169  template <class K, class V> RemoteCache<K, V> getCache(
170  Marshaller<K> *km, void (*kd)(Marshaller<K> *),
171  Marshaller<V> *vm, void (*vd)(Marshaller<V> *),
172  bool forceReturnValue = false)
173  {
174  RemoteCache<K, V> rcache;
175  initCache(rcache, forceReturnValue);
176  rcache.keyMarshaller.reset(km, kd);
177  rcache.valueMarshaller.reset(vm, vd);
178  return rcache;
179  }
180 
201  template <class K, class V> RemoteCache<K, V> getCache(
202  Marshaller<K> *km, void (*kd)(Marshaller<K> *),
203  Marshaller<V> *vm, void (*vd)(Marshaller<V> *),
204  const std::string& name, bool forceReturnValue = false)
205  {
206  RemoteCache<K, V> rcache;
207  initCache(rcache, name.c_str(), forceReturnValue);
208  rcache.keyMarshaller.reset(km, kd);
209  rcache.valueMarshaller.reset(vm, vd);
210  return rcache;
211  }
212 
213  // DEPRECATED
214  template <class K, class V> RemoteCache<K, V> getCache(
215  HR_SHARED_PTR<Marshaller<K> > km, HR_SHARED_PTR<Marshaller<V> > vm,
216  bool forceReturnValue = false)
217  {
218  RemoteCache<K, V> rcache;
219  initCache(rcache, forceReturnValue);
220  rcache.keyMarshallerPtr.reset(new portable::counted_wrapper<HR_SHARED_PTR<Marshaller<K> > >(km), &genericDelete);
221  rcache.valueMarshallerPtr.reset(new portable::counted_wrapper<HR_SHARED_PTR<Marshaller<V> > >(vm), &genericDelete);
222  rcache.keyMarshaller.reset(&*km, &genericNoDelete);
223  rcache.valueMarshaller.reset(&*vm, &genericNoDelete);
224  return rcache;
225  }
226 
227  template <class K, class V> RemoteCache<K, V> getCache(
228  HR_SHARED_PTR<Marshaller<K> > km, HR_SHARED_PTR<Marshaller<V> > vm,
229  const std::string& name, bool forceReturnValue = false)
230  {
231  RemoteCache<K, V> rcache;
232  initCache(rcache, name.c_str(), forceReturnValue);
233  rcache.keyMarshallerPtr.reset(new portable::counted_wrapper<HR_SHARED_PTR<Marshaller<K> > >(km), &genericDelete);
234  rcache.valueMarshallerPtr.reset(new portable::counted_wrapper<HR_SHARED_PTR<Marshaller<V> > >(vm), &genericDelete);
235  rcache.keyMarshaller.reset(&*km, &genericNoDelete);
236  rcache.valueMarshaller.reset(&*vm, &genericNoDelete);
237  return rcache;
238  }
239 
240 private:
241  void *impl;
242 
243  void init(const portable::map<portable::string, portable::string>& configuration, bool start);
244 
245  void initCache(RemoteCacheBase& cache, bool forceReturnValue);
246  void initCache(RemoteCacheBase& cache, const char *name, bool forceReturnValue);
247 
248  // not implemented
250  RemoteCacheManager operator=(const RemoteCacheManager&);
251 
252  template<typename T> static void genericDelete(T *t) { delete t; }
253  template<typename T> static void genericNoDelete(T *) { }
254 };
255 
256 }} // namespace infinispan::hotrod
257 
258 #endif /* ISPN_HOTROD_REMOTECACHEMANAGER_H */
RemoteCache< K, V > getCache(Marshaller< K > *km, void(*kd)(Marshaller< K > *), Marshaller< V > *vm, void(*vd)(Marshaller< V > *), bool forceReturnValue=false)
Definition: RemoteCacheManager.h:169
RemoteCache< K, V > getCache(HR_SHARED_PTR< Marshaller< K > > km, HR_SHARED_PTR< Marshaller< V > > vm, const std::string &name, bool forceReturnValue=false)
Definition: RemoteCacheManager.h:227
#define HR_EXTERN
Definition: ImportExport.h:35
RemoteCacheManager(const std::map< std::string, std::string > &configuration, bool start_=true)
Definition: RemoteCacheManager.h:49
RemoteCache< K, V > getCache(const std::string &name, bool forceReturnValue=false)
Definition: RemoteCacheManager.h:140
Definition: portable.h:274
RemoteCache< K, V > getCache(bool forceReturnValue=false)
Definition: RemoteCacheManager.h:115
Definition: RemoteCache.h:54
RemoteCache< K, V > getCache(HR_SHARED_PTR< Marshaller< K > > km, HR_SHARED_PTR< Marshaller< V > > vm, bool forceReturnValue=false)
Definition: RemoteCacheManager.h:214
Definition: Configuration.h:23
Definition: RemoteCacheManager.h:36
Definition: BasicMarshaller.h:17
Definition: RemoteCacheBase.h:27
Definition: Marshaller.h:14
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:201