/builddir/build/BUILD/infinispan-hotrod-cpp-6.2.1.Final-Source/include/infinispan/hotrod/RemoteCacheManager.h

Go to the documentation of this file.
00001 #ifndef ISPN_HOTROD_REMOTECACHEMANAGER_H
00002 #define ISPN_HOTROD_REMOTECACHEMANAGER_H
00003 
00004 #include "infinispan/hotrod/BasicMarshaller.h"
00005 #include "infinispan/hotrod/portable.h"
00006 #include "infinispan/hotrod/ImportExport.h"
00007 #include "infinispan/hotrod/RemoteCache.h"
00008 #include "infinispan/hotrod/Configuration.h"
00009 
00010 #include <string>
00011 #include <map>
00012 
00013 namespace infinispan {
00014 namespace hotrod {
00015 
00036 class HR_EXTERN RemoteCacheManager
00037 {
00038 public:
00039 
00047     explicit RemoteCacheManager(bool start_ = true);
00048 
00049     explicit RemoteCacheManager(
00050             const std::map<std::string, std::string>& configuration,
00051             bool start_ = true) {
00052         init(portable::map<portable::string, portable::string>(
00053                 configuration, portable::string::convert(), portable::string::convert()), start_);
00054     }
00055 
00065     explicit RemoteCacheManager(
00066         const Configuration& configuration,
00067         bool start = true);
00068 
00069     ~RemoteCacheManager();
00070 
00075     void start();
00076 
00081     void stop();
00082 
00090     bool isStarted();
00091 
00099     const Configuration& getConfiguration();
00100 
00115     template <class K, class V> RemoteCache<K, V> getCache(
00116         bool forceReturnValue = false)
00117     {
00118         RemoteCache<K, V> rcache;
00119         initCache(rcache, forceReturnValue);
00120         rcache.keyMarshaller.reset(new BasicMarshaller<K>(), &Marshaller<K>::destroy);
00121         rcache.valueMarshaller.reset(new BasicMarshaller<V>(), &Marshaller<V>::destroy);
00122         return rcache;
00123     }
00124 
00140     template <class K, class V> RemoteCache<K, V> getCache(
00141         const std::string& name, bool forceReturnValue = false)
00142     {
00143         RemoteCache<K, V> rcache;
00144         initCache(rcache, name.c_str(), forceReturnValue);
00145         rcache.keyMarshaller.reset(new BasicMarshaller<K>(), &Marshaller<K>::destroy);
00146         rcache.valueMarshaller.reset(new BasicMarshaller<V>(), &Marshaller<V>::destroy);
00147         return rcache;
00148     }
00149 
00169     template <class K, class V> RemoteCache<K, V> getCache(
00170         Marshaller<K> *km, void (*kd)(Marshaller<K> *),
00171         Marshaller<V> *vm, void (*vd)(Marshaller<V> *),
00172         bool forceReturnValue = false)
00173     {
00174         RemoteCache<K, V> rcache;
00175         initCache(rcache, forceReturnValue);
00176         rcache.keyMarshaller.reset(km, kd);
00177         rcache.valueMarshaller.reset(vm, vd);
00178         return rcache;
00179     }
00180 
00201     template <class K, class V> RemoteCache<K, V> getCache(
00202         Marshaller<K> *km, void (*kd)(Marshaller<K> *),
00203         Marshaller<V> *vm, void (*vd)(Marshaller<V> *),
00204         const std::string& name, bool forceReturnValue = false)
00205     {
00206         RemoteCache<K, V> rcache;
00207         initCache(rcache, name.c_str(), forceReturnValue);
00208         rcache.keyMarshaller.reset(km, kd);
00209         rcache.valueMarshaller.reset(vm, vd);
00210         return rcache;
00211     }
00212 
00213     // DEPRECATED
00214     template <class K, class V> RemoteCache<K, V> getCache(
00215         HR_SHARED_PTR<Marshaller<K> > km, HR_SHARED_PTR<Marshaller<V> > vm,
00216         bool forceReturnValue = false)
00217     {
00218         RemoteCache<K, V> rcache;
00219         initCache(rcache, forceReturnValue);
00220         rcache.keyMarshallerPtr.reset(new portable::counted_wrapper<HR_SHARED_PTR<Marshaller<K> > >(km), &genericDelete);
00221         rcache.valueMarshallerPtr.reset(new portable::counted_wrapper<HR_SHARED_PTR<Marshaller<V> > >(vm), &genericDelete);
00222         rcache.keyMarshaller.reset(&*km, &genericNoDelete);
00223         rcache.valueMarshaller.reset(&*vm, &genericNoDelete);
00224         return rcache;
00225     }
00226 
00227     template <class K, class V> RemoteCache<K, V> getCache(
00228         HR_SHARED_PTR<Marshaller<K> > km, HR_SHARED_PTR<Marshaller<V> > vm,
00229         const std::string& name, bool forceReturnValue = false)
00230     {
00231         RemoteCache<K, V> rcache;
00232         initCache(rcache, name.c_str(), forceReturnValue);
00233         rcache.keyMarshallerPtr.reset(new portable::counted_wrapper<HR_SHARED_PTR<Marshaller<K> > >(km), &genericDelete);
00234         rcache.valueMarshallerPtr.reset(new portable::counted_wrapper<HR_SHARED_PTR<Marshaller<V> > >(vm), &genericDelete);
00235         rcache.keyMarshaller.reset(&*km, &genericNoDelete);
00236         rcache.valueMarshaller.reset(&*vm, &genericNoDelete);
00237         return rcache;
00238     }
00239 
00240 private:
00241     void *impl;
00242 
00243     void init(const portable::map<portable::string, portable::string>& configuration, bool start);
00244 
00245     void initCache(RemoteCacheBase& cache, bool forceReturnValue);
00246     void initCache(RemoteCacheBase& cache, const char *name, bool forceReturnValue);
00247 
00248     // not implemented
00249     RemoteCacheManager(const RemoteCacheManager&);
00250     RemoteCacheManager operator=(const RemoteCacheManager&);
00251 
00252     template<typename T> static void genericDelete(T *t) { delete t; }
00253     template<typename T> static void genericNoDelete(T *) { }
00254 };
00255 
00256 }} // namespace infinispan::hotrod
00257 
00258 #endif  /* ISPN_HOTROD_REMOTECACHEMANAGER_H */

Generated on 25 Mar 2015 for JBoss Data Grid HotRod C++ Client by  doxygen 1.4.7