From 8113c4d82369e47d157a199c9993cbd0d277cf0a Mon Sep 17 00:00:00 2001 From: Vittorio Rigamonti Date: Thu, 23 Jun 2016 12:31:22 +0200 Subject: [PATCH 1/2] HRCPP-278 added missing method removeWithVersionAsync --- include/infinispan/hotrod/RemoteCache.h | 15 ++++++++++++++- jni/src/main/swig/java.i | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/infinispan/hotrod/RemoteCache.h b/include/infinispan/hotrod/RemoteCache.h index bd7cfa99..85c6e66c 100644 --- a/include/infinispan/hotrod/RemoteCache.h +++ b/include/infinispan/hotrod/RemoteCache.h @@ -521,7 +521,6 @@ template class RemoteCache : private RemoteCacheBase */ std::future replaceWithVersionAsync(const K& key, const V& val, uint64_t version, uint64_t lifespan, uint64_t maxIdle, std::function success=nullptr, std::function fail=nullptr) { - auto pMap = &pMap; auto f = [=] { this->replaceWithVersion(&key, &val, version, lifespan, maxIdle); }; return goAsync(f,success,fail); } @@ -547,6 +546,20 @@ template class RemoteCache : private RemoteCacheBase bool removeWithVersion(const K& key, uint64_t version) { return base_removeWithVersion(&key, version); } + + /** + * Asynchronous version of removeWithVersion() + * See the synchronous doc for parameters not explained here + * \param success function to be executed on success + * \param fail function to be executed if exceptions occur + * \return a future containing a bool. True if the entry has been removed + * + */ + std::future removeWithVersionAsync(const K& key, uint64_t version, std::function success=nullptr, std::function fail=nullptr) { + auto f = [=] { this->removeWithVersion(&key, version); }; + return goAsync(f,success,fail); + } + /** * Returns the std::pair with value and VersionedValue associated with * the supplied key parameter or a default initialized std::pair if it diff --git a/jni/src/main/swig/java.i b/jni/src/main/swig/java.i index 539b2aa8..da19edb8 100644 --- a/jni/src/main/swig/java.i +++ b/jni/src/main/swig/java.i @@ -144,6 +144,7 @@ using namespace infinispan::hotrod; %ignore goAsync; %ignore putAllAsync; %ignore replaceWithVersionAsync; +%ignore removeWithVersionAsync; //%shared_ptr(RelayShrPointer) From 6182f02faea7588e9d18d177452c7b0d0aa4ba8b Mon Sep 17 00:00:00 2001 From: Vittorio Rigamonti Date: Fri, 8 Jul 2016 11:04:49 +0200 Subject: [PATCH 2/2] Added the missing asynchronous methods --- include/infinispan/hotrod/RemoteCache.h | 141 ++++++++++++++++++++++++ jni/src/main/swig/java.i | 4 + 2 files changed, 145 insertions(+) diff --git a/include/infinispan/hotrod/RemoteCache.h b/include/infinispan/hotrod/RemoteCache.h index 85c6e66c..69048155 100644 --- a/include/infinispan/hotrod/RemoteCache.h +++ b/include/infinispan/hotrod/RemoteCache.h @@ -283,6 +283,47 @@ template class RemoteCache : private RemoteCacheBase V* putIfAbsent(const K& key, const V& val, uint64_t lifespan, TimeUnit lifespanUnit, uint64_t maxIdle, TimeUnit maxIdleUnit) { return (V *)base_putIfAbsent(&key, &val, toSeconds(lifespan, lifespanUnit), toSeconds(maxIdle, maxIdleUnit)); } + /** + * Asynchronous version of putIfAbsentAsync() + * See the synchronous doc for parameters not explained here + * \param success function to be executed on success + * \param fail function to be executed if exceptions occur + * \return a future containing a pointer to the previous value stored in the cache for the given key or null + * + */ + std::future putIfAbsentAsync(const K& key, const V& val, uint64_t lifespan = 0, uint64_t maxIdle = 0, std::function success=nullptr, std::function fail=nullptr) { + auto pKey=&key, pVal=&val; + auto f= [=] { this->putIfAbsent(*pKey,*pVal, lifespan, maxIdle); }; + return goAsync(f,success,fail); + } + /** + * Asynchronous version of putIfAbsentAsync() + * See the synchronous doc for parameters not explained here + * \param success function to be executed on success + * \param fail function to be executed if exceptions occur + * \return a future containing a pointer to the previous value stored in the cache for the given key or null + * + */ + std::future putIfAbsentAsync(const K& key, const V& val, uint64_t lifespan, TimeUnit lifespanUnit, std::function success=nullptr, std::function fail=nullptr) { + auto pKey=&key, pVal=&val; + auto f= [=] { this->putIfAbsent(*pKey,*pVal, lifespan, lifespanUnit, 0, SECONDS); }; + return goAsync(f,success,fail); + } + /** + * Asynchronous version of putIfAbsentAsync() + * See the synchronous doc for parameters not explained here + * \param success function to be executed on success + * \param fail function to be executed if exceptions occur + * \return a future containing a pointer to the previous value stored in the cache for the given key or null + * + */ + std::future putIfAbsentAsync(const K& key, const V& val, uint64_t lifespan, TimeUnit lifespanUnit, uint64_t maxIdle, TimeUnit maxIdleUnit, std::function success=nullptr, std::function fail=nullptr) { + auto pKey=&key, pVal=&val; + auto f= [=] { this->putIfAbsent(*pKey,*pVal, lifespan, lifespanUnit, maxIdle, maxIdleUnit); }; + return goAsync(f,success,fail); + } + + /** * Copies all of the mappings from the specified map to this cache. The effect of this call is equivalent to that of * calling put(k, v) on this cache once for each mapping from key k to value v in the specified map. @@ -465,6 +506,77 @@ template class RemoteCache : private RemoteCacheBase throw UnsupportedOperationException(); } + /** + * Asynchronous version of replace() + * See the synchronous doc for parameters not explained here + * \param success function to be executed on success + * \param fail function to be executed if exceptions occur + * \return a future containing a pointer to the previous value stored in the cache for the given key or null + * + */ + std::future replaceAsync(const K& key, const V& val, uint64_t lifespan = 0, uint64_t maxIdle = 0, std::function success=nullptr, std::function fail=nullptr) { + auto pKey=&key, pVal=&val; + auto f= [=] { this->replace(*pKey, *pVal, lifespan, SECONDS, maxIdle, SECONDS); }; + return goAsync(f,success,fail); + } + + /** + * Asynchronous version of replace() + * See the synchronous doc for parameters not explained here + * \param success function to be executed on success + * \param fail function to be executed if exceptions occur + * \return a future containing a pointer to the previous value stored in the cache for the given key or null + * + */ + std::future replaceAsync(const K& key, const V& val, uint64_t lifespan, TimeUnit lifespanUnit, std::function success=nullptr, std::function fail=nullptr) { + auto pKey=&key, pVal=&val; + auto f= [=] { this->replace(*pKey, *pVal, lifespan, lifespanUnit, 0, SECONDS); }; + return goAsync(f,success,fail); + } + + /** + * Asynchronous version of replace() + * See the synchronous doc for parameters not explained here + * \param success function to be executed on success + * \param fail function to be executed if exceptions occur + * \return a future containing a pointer to the previous value stored in the cache for the given key or null + * + */ + std::future replaceAsync(const K& key, const V& val, uint64_t lifespan, TimeUnit lifespanUnit, uint64_t maxIdle, TimeUnit maxIdleUnit, std::function success=nullptr, std::function fail=nullptr) { + auto pKey=&key, pVal=&val; + auto f= [=] { this->replace(*pKey, *pVal, lifespan, lifespanUnit, maxIdle, maxIdleUnit); }; + return goAsync(f,success,fail); + } + + /** + * Asynchronous version of replace() + * See the synchronous doc for parameters not explained here + * \param success function to be executed on success + * \param fail function to be executed if exceptions occur + * \return a future containing a pointer to the previous value stored in the cache for the given key or null + * + */ + std::future replaceAsync(const K& key, const V& oldVal, const V& val, uint64_t lifespan = 0, uint64_t maxIdle = 0, std::function success=nullptr, std::function fail=nullptr) { + auto pKey=&key, pVal=&val, pOldVal=&oldVal; + auto f= [=] { this->replace(*pKey, *oldVal, *pVal, lifespan, SECONDS, maxIdle, SECONDS); }; + return goAsync(f,success,fail); + } + + /** + * Asynchronous version of replace() + * See the synchronous doc for parameters not explained here + * \param success function to be executed on success + * \param fail function to be executed if exceptions occur + * \return a future containing a pointer to the previous value stored in the cache for the given key or null + * + */ + std::future replaceAsync(const K& key, const V& oldVal, const V& val, uint64_t lifespan, TimeUnit lifespanUnit, std::function success=nullptr, std::function fail=nullptr) { + auto pKey=&key, pVal=&val, pOldVal=&oldVal; + auto f= [=] { this->replace(*pKey, *oldVal, *pVal, lifespan, lifespanUnit, 0, SECONDS); }; + return goAsync(f,success,fail); + } + + /** * Removes key/value pair from the cache given a key. Optionally return a value stored * under the given key @@ -475,6 +587,20 @@ template class RemoteCache : private RemoteCacheBase return (V *) base_remove(&key); } + /** + * Asynchronous version of removeWithVersion() + * See the synchronous doc for parameters not explained here + * \param success function to be executed on success + * \param fail function to be executed if exceptions occur + * \return a future containing a bool. True if the entry has been removed + * + */ + std::future removeAsync(const K& key, std::function success=nullptr, std::function fail=nullptr) { + auto f = [=] { this->remove(&key); }; + return goAsync(f,success,fail); + } + + /** * Returns true if this cache contains a key/value pair where the key is equal to a specified key. * @@ -713,6 +839,21 @@ template class RemoteCache : private RemoteCacheBase void clear() { base_clear(); } + + + /** + * Asynchronous version of clear() + * See the synchronous doc for parameters not explained here + * \param success function to be executed on success + * \param fail function to be executed if exceptions occur + * \return a future containing a bool. True if the entry has been removed + * + */ + std::future clearAsync(std::function success=nullptr, std::function fail=nullptr) { + auto f = [=] { this->clear(); }; + return goAsync(f,success,fail); + } + /** * Pings remote cache on a Hot Rod server * diff --git a/jni/src/main/swig/java.i b/jni/src/main/swig/java.i index da19edb8..f9b50b2d 100644 --- a/jni/src/main/swig/java.i +++ b/jni/src/main/swig/java.i @@ -145,6 +145,10 @@ using namespace infinispan::hotrod; %ignore putAllAsync; %ignore replaceWithVersionAsync; %ignore removeWithVersionAsync; +%ignore putIfAbsentAsync; +%ignore clearAsync; +%ignore removeAsync; +%ignore replaceAsync; //%shared_ptr(RelayShrPointer)