1 #ifndef ISPN_HOTROD_REMOTECACHE_H
2 #define ISPN_HOTROD_REMOTECACHE_H
21 namespace infinispan {
91 V*
get(
const K& key) {
114 V*
put(
const K& key,
const V& val, uint64_t lifespan = 0, uint64_t maxIdle = 0) {
136 V*
put(
const K& key,
const V& val, uint64_t lifespan,
TimeUnit lifespanUnit) {
137 return put(key, val, lifespan, lifespanUnit, 0,
SECONDS);
161 V*
put(
const K& key,
const V& val, uint64_t lifespan,
TimeUnit lifespanUnit, uint64_t maxIdle,
TimeUnit maxIdleUnit) {
162 return (V *)
base_put(&key, &val, toSeconds(lifespan, lifespanUnit), toSeconds(maxIdle, maxIdleUnit));
175 V*
putIfAbsent(
const K& key,
const V& val, uint64_t lifespan = 0, uint64_t maxIdle = 0) {
205 return (V *)
base_putIfAbsent(&key, &val, toSeconds(lifespan, lifespanUnit), toSeconds(maxIdle, maxIdleUnit));
217 void putAll(
const std::map<K, V>& map, uint64_t lifespan = 0, uint64_t maxIdle = 0) {
230 void putAll(
const std::map<K, V>& map, uint64_t lifespan,
TimeUnit lifespanUnit) {
246 void putAll(
const std::map<K, V>& map, uint64_t lifespan,
TimeUnit lifespanUnit, uint64_t maxIdle,
TimeUnit maxIdleUnit) {
247 uint64_t lifespanMillis = toSeconds(lifespan, lifespanUnit);
248 uint64_t maxIdleMillis = toSeconds(maxIdle, maxIdleUnit);
250 for (
typename std::map<K, V>::const_iterator it = map.begin(); it != map.end(); ++it) {
251 put(it->first, it->second, lifespanMillis, maxIdleMillis);
265 V*
replace(
const K& key,
const V& val, uint64_t lifespan = 0, uint64_t maxIdle = 0) {
296 return (V *)
base_replace(&key, &val, toSeconds(lifespan, lifespanUnit), toSeconds(maxIdle, maxIdleUnit));
310 V*
replace(
const K& key,
const V& oldVal,
const V& val, uint64_t lifespan = 0, uint64_t maxIdle = 0) {
324 V*
replace(
const K& key,
const V& oldVal,
const V& val, uint64_t lifespan,
TimeUnit lifespanUnit) {
325 return replace(key, oldVal, val, lifespan, lifespanUnit, 0,
SECONDS);
340 V*
replace(
const K& key,
const V& oldVal,
const V& val, uint64_t lifespan,
TimeUnit lifespanUnit, uint64_t maxIdle,
TimeUnit maxIdleUnit) {
350 V*
remove(
const K& key) {
385 const K& key,
const V& val,
386 uint64_t version, uint64_t lifespan = 0, uint64_t maxIdle = 0) {
423 return std::make_pair(HR_SHARED_PTR<V>((V *) value), version);
438 return std::make_pair(HR_SHARED_PTR<V>((V *) value), metadata);
444 std::map<HR_SHARED_PTR<K>, HR_SHARED_PTR<V> >
getBulk() {
451 std::map<HR_SHARED_PTR<K>, HR_SHARED_PTR<V> >
getBulk(
int nrOfEntries) {
455 std::map<HR_SHARED_PTR<K>, HR_SHARED_PTR<V> > result;
457 for (
size_t i = 0; i < mbuf.
size(); i++) {
458 result.insert(std::make_pair(
459 HR_SHARED_PTR<K>((K*)data[i].key), HR_SHARED_PTR<V>((V*)data[i].value)));
481 std::set<HR_SHARED_PTR<K> > result;
482 for (
size_t i = 0; i < p.
size(); ++i) {
483 result.insert(HR_SHARED_PTR<K>((K*)p.
data()[i]));
516 std::map<std::string, std::string>
stats() {
520 (portable::string::convert(), portable::string::convert());
550 RemoteCacheBase(other), keyMarshaller(other.keyMarshaller), valueMarshaller(other.valueMarshaller)
552 setMarshallers(
this, &keyMarshall, &valueMarshall, &keyUnmarshall, &valueUnmarshall);
556 RemoteCacheBase::operator=(other);
557 keyMarshaller = other.keyMarshaller;
558 valueMarshaller = other.valueMarshaller;
559 setMarshallers(
this, &keyMarshall, &valueMarshall, &keyUnmarshall, &valueUnmarshall);
565 setMarshallers(
this, &keyMarshall, &valueMarshall, &keyUnmarshall, &valueUnmarshall);
568 uint64_t toSeconds(uint64_t time,
TimeUnit unit) {
572 result = (uint64_t) ceil(time / 1000000000.0);
575 result = (uint64_t) ceil(time / 1000000.0);
578 result = (uint64_t) ceil(time / 1000.0);
587 result = time * 3600;
590 result = time * 86400;
593 std::stringstream ss;
594 ss <<
"Unhandled TimeUnit specified: " << unit <<
".";
595 throw std::invalid_argument(ss.str());
601 static void keyMarshall(
void *thisp,
const void* key, ScopedBuffer &buf) {
602 ((RemoteCache<K, V> *) thisp)->keyMarshaller->marshall(*(
const K *) key, buf);
604 static void valueMarshall(
void* thisp,
const void* val, ScopedBuffer &buf) {
605 ((RemoteCache<K, V> *)thisp)->valueMarshaller->marshall(*(
const V *) val, buf);
607 static void* keyUnmarshall(
void *thisp,
const ScopedBuffer &buf) {
608 return ((RemoteCache<K, V> *) thisp)->keyMarshaller->unmarshall(buf);
610 static void* valueUnmarshall(
void* thisp,
const ScopedBuffer &buf) {
611 return ((RemoteCache<K, V> *)thisp)->valueMarshaller->unmarshall(buf);
614 portable::counting_ptr<Marshaller<K> > keyMarshaller;
615 portable::counting_ptr<Marshaller<V> > valueMarshaller;
618 portable::counting_ptr<portable::counted_wrapper<HR_SHARED_PTR<Marshaller<K> > > > keyMarshallerPtr;
619 portable::counting_ptr<portable::counted_wrapper<HR_SHARED_PTR<Marshaller<V> > > > valueMarshallerPtr;
void putAll(const std::map< K, V > &map, uint64_t lifespan, TimeUnit lifespanUnit, uint64_t maxIdle, TimeUnit maxIdleUnit)
Definition: RemoteCache.h:246
std::map< HR_SHARED_PTR< K >, HR_SHARED_PTR< V > > getBulk()
Definition: RemoteCache.h:444
V * putIfAbsent(const K &key, const V &val, uint64_t lifespan, TimeUnit lifespanUnit)
Definition: RemoteCache.h:188
HR_EXTERN void * base_replace(const void *key, const void *value, int64_t life, int64_t idle)
V * put(const K &key, const V &val, uint64_t lifespan, TimeUnit lifespanUnit, uint64_t maxIdle, TimeUnit maxIdleUnit)
Definition: RemoteCache.h:161
std::string getName()
Definition: RemoteCache.h:62
std::map< K, V > std_map() const
Definition: portable.h:354
std::set< std::pair< K, V > > entrySet()
Definition: RemoteCache.h:467
Definition: portable.h:128
HR_EXTERN bool base_replaceWithVersion(const void *key, const void *value, int64_t version, int64_t life, int64_t idle)
HR_EXTERN void base_ping()
HR_EXTERN bool base_containsKey(const void *key)
HR_EXTERN void base_withFlags(Flag flag)
HR_EXTERN void setMarshallers(void *rc, MarshallHelperFn kf, MarshallHelperFn vf, UnmarshallHelperFn ukf, UnmarshallHelperFn uvf)
static const char * getProtocolVersionCString()
Definition: Version.h:33
HR_EXTERN void base_getBulk(int size, portable::map< void *, void * > &mbuf)
size_t size() const
Definition: portable.h:262
bool containsKey(const K &key)
Definition: RemoteCache.h:359
HR_EXTERN void * base_remove(const void *key)
std::map< std::string, std::string > stats()
Definition: RemoteCache.h:516
HR_EXTERN void * base_put(const void *key, const void *value, int64_t life, int64_t idle)
V * replace(const K &key, const V &oldVal, const V &val, uint64_t lifespan=0, uint64_t maxIdle=0)
Definition: RemoteCache.h:310
void putAll(const std::map< K, V > &map, uint64_t lifespan=0, uint64_t maxIdle=0)
Definition: RemoteCache.h:217
RemoteCache< K, V > & withFlags(Flag flags)
Definition: RemoteCache.h:544
std::vector< V > values()
Definition: RemoteCache.h:507
HR_EXTERN bool base_removeWithVersion(const void *key, int64_t version)
V * putIfAbsent(const K &key, const V &val, uint64_t lifespan, TimeUnit lifespanUnit, uint64_t maxIdle, TimeUnit maxIdleUnit)
Definition: RemoteCache.h:204
Definition: portable.h:274
RemoteCache< K, V > & operator=(const RemoteCache &other)
Definition: RemoteCache.h:555
HR_EXTERN const char * base_getName()
Definition: RemoteCache.h:54
Definition: TimeUnit.h:17
Definition: TimeUnit.h:18
HR_EXTERN void base_keySet(int scope, portable::vector< void * > &sbuf)
V * putIfAbsent(const K &key, const V &val, uint64_t lifespan=0, uint64_t maxIdle=0)
Definition: RemoteCache.h:175
Definition: TimeUnit.h:16
V * replace(const K &key, const V &oldVal, const V &val, uint64_t lifespan, TimeUnit lifespanUnit)
Definition: RemoteCache.h:324
Definition: portable.h:151
uint64_t size()
Definition: RemoteCache.h:492
HR_EXTERN void base_clear()
void clear()
Definition: RemoteCache.h:527
size_t size() const
Definition: portable.h:388
bool isEmpty()
Definition: RemoteCache.h:500
V * put(const K &key, const V &val, uint64_t lifespan, TimeUnit lifespanUnit)
Definition: RemoteCache.h:136
RemoteCache(const RemoteCache &other)
Definition: RemoteCache.h:549
HR_EXTERN void * base_putIfAbsent(const void *key, const void *value, int64_t life, int64_t idle)
bool replaceWithVersion(const K &key, const V &val, uint64_t version, uint64_t lifespan=0, uint64_t maxIdle=0)
Definition: RemoteCache.h:384
std::string getVersion()
Definition: RemoteCache.h:71
Definition: RemoteCacheManager.h:36
Definition: TimeUnit.h:15
std::string getProtocolVersion()
Definition: RemoteCache.h:80
HR_EXTERN void * base_getWithVersion(const void *key, VersionedValue *version)
V * replace(const K &key, const V &oldVal, const V &val, uint64_t lifespan, TimeUnit lifespanUnit, uint64_t maxIdle, TimeUnit maxIdleUnit)
Definition: RemoteCache.h:340
std::map< HR_SHARED_PTR< K >, HR_SHARED_PTR< V > > getBulk(int nrOfEntries)
Definition: RemoteCache.h:451
V * replace(const K &key, const V &val, uint64_t lifespan, TimeUnit lifespanUnit, uint64_t maxIdle, TimeUnit maxIdleUnit)
Definition: RemoteCache.h:295
void ping()
Definition: RemoteCache.h:535
Definition: exceptions.h:117
const T * data() const
Definition: portable.h:257
HR_EXTERN void * base_getWithMetadata(const void *key, MetadataValue *metadata)
static const char * getVersionCString()
Definition: Version.h:42
TimeUnit
Definition: TimeUnit.h:12
Definition: RemoteCacheBase.h:27
std::pair< HR_SHARED_PTR< V >, MetadataValue > getWithMetadata(const K &key)
Definition: RemoteCache.h:435
Definition: portable.h:268
std::set< HR_SHARED_PTR< K > > keySet()
Definition: RemoteCache.h:477
bool containsValue(const V &val)
Definition: RemoteCache.h:367
V * replace(const K &key, const V &val, uint64_t lifespan, TimeUnit lifespanUnit)
Definition: RemoteCache.h:279
Definition: TimeUnit.h:14
Definition: TimeUnit.h:20
Definition: TimeUnit.h:19
V * replace(const K &key, const V &val, uint64_t lifespan=0, uint64_t maxIdle=0)
Definition: RemoteCache.h:265
std::pair< HR_SHARED_PTR< V >, VersionedValue > getWithVersion(const K &key)
Definition: RemoteCache.h:420
HR_EXTERN void base_stats(portable::map< portable::string, portable::string > &sbuf)
Definition: VersionedValue.h:9
V * put(const K &key, const V &val, uint64_t lifespan=0, uint64_t maxIdle=0)
Definition: RemoteCache.h:114
HR_EXTERN void * base_get(const void *key)
void putAll(const std::map< K, V > &map, uint64_t lifespan, TimeUnit lifespanUnit)
Definition: RemoteCache.h:230
const my_pair * data() const
Definition: portable.h:383
bool removeWithVersion(const K &key, uint64_t version)
Definition: RemoteCache.h:407