GridGain C++
cache_client.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 GridGain Systems, Inc. and Contributors.
3  *
4  * Licensed under the GridGain Community Edition License (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
22 #ifndef _IGNITE_THIN_CACHE_CACHE_CLIENT
23 #define _IGNITE_THIN_CACHE_CACHE_CLIENT
24 
25 #include <ignite/common/concurrent.h>
26 
33 
34 #include <ignite/impl/thin/writable.h>
35 #include <ignite/impl/thin/writable_key.h>
36 
37 #include <ignite/impl/thin/readable.h>
38 #include <ignite/impl/thin/cache/cache_client_proxy.h>
39 #include <ignite/impl/thin/cache/continuous/continuous_query_client_holder.h>
40 
41 namespace ignite
42 {
43  namespace thin
44  {
45  namespace cache
46  {
62  template<typename K, typename V>
64  {
65  friend class impl::thin::cache::CacheClientProxy;
66 
67  public:
69  typedef K KeyType;
70 
72  typedef V ValueType;
73 
79  explicit CacheClient(const common::concurrent::SharedPointer<void>& impl) :
80  proxy(impl)
81  {
82  // No-op.
83  }
84 
89  {
90  // No-op.
91  }
92 
97  {
98  // No-op.
99  }
100 
107  void Put(const KeyType& key, const ValueType& value)
108  {
109  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
110  impl::thin::WritableImpl<ValueType> wrValue(value);
111 
112  proxy.Put(wrKey, wrValue);
113  }
114 
122  template<typename InIter>
123  void PutAll(InIter begin, InIter end)
124  {
125  impl::thin::WritableMapImpl<K, V, InIter> wrSeq(begin, end);
126 
127  proxy.PutAll(wrSeq);
128  }
129 
136  template<typename Map>
137  void PutAll(const Map& vals)
138  {
139  PutAll(vals.begin(), vals.end());
140  }
141 
149  bool Get(const KeyType& key, ValueType& value)
150  {
151  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
153 
154  proxy.Get(wrKey, rdValue);
155 
156  return !rdValue.IsNull();
157  }
158 
165  ValueType Get(const KeyType& key)
166  {
167  ValueType value;
168 
169  Get(key, value);
170 
171  return value;
172  }
173 
184  template<typename InIter, typename OutIter>
185  void GetAll(InIter begin, InIter end, OutIter dst)
186  {
187  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
188  impl::thin::ReadableContainerImpl< std::pair<K, V>, OutIter> rdSeq(dst);
189 
190  proxy.GetAll(wrSeq, rdSeq);
191  }
192 
202  template<typename Set, typename Map>
203  void GetAll(const Set& keys, Map& res)
204  {
205  return GetAll(keys.begin(), keys.end(), std::inserter(res, res.end()));
206  }
207 
220  bool Replace(const K& key, const V& value)
221  {
222  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
223  impl::thin::WritableImpl<ValueType> wrValue(value);
224 
225  return proxy.Replace(wrKey, wrValue);
226  }
227 
237  bool Replace(const KeyType& key, const ValueType& oldVal, const ValueType& newVal)
238  {
239  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
240  impl::thin::WritableImpl<ValueType> wrOldVal(oldVal);
241  impl::thin::WritableImpl<ValueType> wrNewVal(newVal);
242 
243  return proxy.Replace(wrKey, wrOldVal, wrNewVal);
244  }
245 
252  bool ContainsKey(const KeyType& key)
253  {
254  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
255 
256  return proxy.ContainsKey(wrKey);
257  }
258 
265  template<typename Set>
266  bool ContainsKeys(const Set& keys)
267  {
268  return ContainsKeys(keys.begin(), keys.end());
269  }
270 
278  template<typename InIter>
279  bool ContainsKeys(InIter begin, InIter end)
280  {
281  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
282 
283  return proxy.ContainsKeys(wrSeq);
284  }
285 
295  int64_t GetSize(int32_t peekModes)
296  {
297  return proxy.GetSize(peekModes);
298  }
299 
312  bool Remove(const KeyType& key)
313  {
314  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
315 
316  return proxy.Remove(wrKey);
317  }
318 
327  bool Remove(const KeyType& key, const ValueType& val)
328  {
329  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
330  impl::thin::WritableImpl<ValueType> wrVal(val);
331 
332  return proxy.Remove(wrKey, wrVal);
333  }
334 
341  template<typename Set>
342  void RemoveAll(const Set& keys)
343  {
344  RemoveAll(keys.begin(), keys.end());
345  }
346 
354  template<typename InIter>
355  void RemoveAll(InIter begin, InIter end)
356  {
357  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
358 
359  proxy.RemoveAll(wrSeq);
360  }
361 
367  void RemoveAll()
368  {
369  proxy.RemoveAll();
370  }
371 
378  void Clear(const KeyType& key)
379  {
380  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
381 
382  proxy.Clear(wrKey);
383  }
384 
388  void Clear()
389  {
390  proxy.Clear();
391  }
392 
399  template<typename Set>
400  void ClearAll(const Set& keys)
401  {
402  ClearAll(keys.begin(), keys.end());
403  }
404 
412  template<typename InIter>
413  void ClearAll(InIter begin, InIter end)
414  {
415  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
416 
417  proxy.ClearAll(wrSeq);
418  }
419 
429  void GetAndPut(const KeyType& key, const ValueType& valIn, ValueType& valOut)
430  {
431  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
432  impl::thin::WritableImpl<ValueType> wrValIn(valIn);
433  impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
434 
435  proxy.GetAndPut(wrKey, wrValIn, rdValOut);
436  }
437 
447  ValueType GetAndPut(const KeyType& key, const ValueType& valIn)
448  {
449  ValueType valOut;
450 
451  GetAndPut(key, valIn, valOut);
452 
453  return valOut;
454  }
455 
463  void GetAndRemove(const KeyType& key, ValueType& valOut)
464  {
465  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
466  impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
467 
468  proxy.GetAndRemove(wrKey, rdValOut);
469  }
470 
479  {
480  ValueType valOut;
481 
482  GetAndRemove(key, valOut);
483 
484  return valOut;
485  }
486 
496  void GetAndReplace(const KeyType& key, const ValueType& valIn, ValueType& valOut)
497  {
498  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
499  impl::thin::WritableImpl<ValueType> wrValIn(valIn);
500  impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
501 
502  proxy.GetAndReplace(wrKey, wrValIn, rdValOut);
503  }
504 
514  ValueType GetAndReplace(const KeyType& key, const ValueType& valIn)
515  {
516  ValueType valOut;
517 
518  GetAndReplace(key, valIn, valOut);
519 
520  return valOut;
521  }
522 
531  bool PutIfAbsent(const KeyType& key, const ValueType& val)
532  {
533  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
534  impl::thin::WritableImpl<ValueType> wrValIn(val);
535 
536  return proxy.PutIfAbsent(wrKey, wrValIn);
537  }
538 
558  void GetAndPutIfAbsent(const KeyType& key, const ValueType& valIn, ValueType& valOut)
559  {
560  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
561  impl::thin::WritableImpl<ValueType> wrValIn(valIn);
562  impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
563 
564  proxy.GetAndPutIfAbsent(wrKey, wrValIn, rdValOut);
565  }
566 
586  ValueType GetAndPutIfAbsent(const KeyType& key, const ValueType& valIn)
587  {
588  ValueType valOut;
589 
590  GetAndPutIfAbsent(key, valIn, valOut);
591 
592  return valOut;
593  }
594 
602  {
603  return proxy.Query(qry);
604  }
605 
613  {
614  return query::QueryCursor<KeyType, ValueType>(proxy.Query(qry));
615  }
616 
625  {
626  using namespace impl::thin::cache::query::continuous;
627 
628  SP_ContinuousQueryClientHolderBase holder(new ContinuousQueryClientHolder<K, V>(continuousQuery));
629 
630  return proxy.QueryContinuous(holder, continuousQuery.GetJavaFilter());
631  }
632 
645  {
646  // No-op.
647  }
648 
649  private:
651  impl::thin::cache::CacheClientProxy proxy;
652  };
653  }
654  }
655 }
656 
657 #endif // _IGNITE_THIN_CACHE_CACHE_CLIENT
ignite::thin::cache::CacheClient::PutAll
void PutAll(InIter begin, InIter end)
Stores given key-value pairs in cache.
Definition: cache_client.h:123
ignite
Ignite API.
Definition: cache.h:47
query_scan.h
continuous_query_client.h
ignite::thin::cache::CacheClient::RemoveAll
void RemoveAll()
Removes all mappings from cache.
Definition: cache_client.h:367
ignite::thin::cache::CacheClient::GetAndRemove
ValueType GetAndRemove(const KeyType &key)
Atomically removes the entry for a key only if currently mapped to some value.
Definition: cache_client.h:478
ignite::thin::cache::CacheClient::~CacheClient
~CacheClient()
Destructor.
Definition: cache_client.h:96
continuous_query_handle.h
ignite::thin::cache::CacheClient::Remove
bool Remove(const KeyType &key)
Removes given key mapping from cache.
Definition: cache_client.h:312
query_fields_cursor.h
ignite::thin::cache::query::continuous::ContinuousQueryClient
Continuous query client.
Definition: continuous_query_client.h:53
ignite::thin::cache::CacheClient::RemoveAll
void RemoveAll(InIter begin, InIter end)
Removes given key mappings from cache.
Definition: cache_client.h:355
ignite::thin::cache::CacheClient::GetAndReplace
ValueType GetAndReplace(const KeyType &key, const ValueType &valIn)
Atomically replaces the value for a given key if and only if there is a value currently mapped by the...
Definition: cache_client.h:514
ignite::thin::cache::query::QueryFieldsCursor
Query fields cursor.
Definition: thin-client/include/ignite/thin/cache/query/query_fields_cursor.h:47
ignite::thin::cache::CacheClient::ContainsKeys
bool ContainsKeys(const Set &keys)
Check if cache contains mapping for these keys.
Definition: cache_client.h:266
ignite::thin::cache::CacheClient::GetSize
int64_t GetSize(int32_t peekModes)
Gets the number of all entries cached across all nodes.
Definition: cache_client.h:295
ignite::thin::cache::query::continuous::ContinuousQueryHandleClient
Continuous query handle client.
Definition: thin-client/include/ignite/thin/cache/query/continuous/continuous_query_handle.h:42
ignite::thin::cache::query::SqlFieldsQuery
SQL fields query for thin client.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:51
ignite::thin::cache::CacheClient::CacheClient
CacheClient(const common::concurrent::SharedPointer< void > &impl)
Constructor.
Definition: cache_client.h:79
ignite::thin::cache::CacheClient::GetAndPutIfAbsent
ValueType GetAndPutIfAbsent(const KeyType &key, const ValueType &valIn)
Stores given key-value pair in cache only if cache had no previous mapping for it.
Definition: cache_client.h:586
ignite::thin::cache::CacheClient::RemoveAll
void RemoveAll(const Set &keys)
Removes given key mappings from cache.
Definition: cache_client.h:342
ignite::thin::cache::CacheClient::ContainsKey
bool ContainsKey(const KeyType &key)
Check if the cache contains a value for the specified key.
Definition: cache_client.h:252
ignite::thin::cache::CacheClient::QueryContinuous
query::continuous::ContinuousQueryHandleClient QueryContinuous(query::continuous::ContinuousQueryClient< K, V > continuousQuery)
Starts the continuous query execution.
Definition: cache_client.h:623
ignite::thin::cache::CacheClient::GetAndPut
ValueType GetAndPut(const KeyType &key, const ValueType &valIn)
Associates the specified value with the specified key in this cache, returning an existing value if o...
Definition: cache_client.h:447
ignite::thin::cache::CacheClient::KeyType
K KeyType
Key type.
Definition: cache_client.h:69
ignite::thin::cache::CacheClient
Cache client class template.
Definition: cache_client.h:63
ignite::thin::cache::CacheClient::Query
query::QueryFieldsCursor Query(const query::SqlFieldsQuery &qry)
Perform SQL fields query.
Definition: cache_client.h:601
ignite::thin::cache::CacheClient::ValueType
V ValueType
Value type.
Definition: cache_client.h:72
ignite::thin::cache::CacheClient::Replace
bool Replace(const KeyType &key, const ValueType &oldVal, const ValueType &newVal)
Stores given key-value pair in cache only if the previous value is equal to the old value passed as a...
Definition: cache_client.h:237
ignite::thin::cache::CacheClient::Get
bool Get(const KeyType &key, ValueType &value)
Get value from the cache.
Definition: cache_client.h:149
ignite::thin::cache::CacheClient::PutIfAbsent
bool PutIfAbsent(const KeyType &key, const ValueType &val)
Atomically associates the specified key with the given value if it is not already associated with a v...
Definition: cache_client.h:531
ignite::thin::cache::CacheClient::CacheClient
CacheClient()
Default constructor.
Definition: cache_client.h:88
ignite::thin::cache::CacheClient::Query
query::QueryCursor< KeyType, ValueType > Query(const query::ScanQuery &qry)
Perform scan query.
Definition: cache_client.h:612
ignite::thin::cache::CacheClient::GetAndPut
void GetAndPut(const KeyType &key, const ValueType &valIn, ValueType &valOut)
Associates the specified value with the specified key in this cache, returning an existing value if o...
Definition: cache_client.h:429
ignite::thin::cache::CacheClient::ClearAll
void ClearAll(InIter begin, InIter end)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache_client.h:413
ignite::thin::cache::CacheClient::Put
void Put(const KeyType &key, const ValueType &value)
Associate the specified value with the specified key in the cache.
Definition: cache_client.h:107
ignite::thin::cache::query::ScanQuery
Scan query.
Definition: thin-client/include/ignite/thin/cache/query/query_scan.h:51
query_sql_fields.h
ignite::thin::cache::query::QueryCursor
Query cursor class template.
Definition: thin-client/include/ignite/thin/cache/query/query_cursor.h:56
ignite::thin::cache::CacheClient::GetAll
void GetAll(InIter begin, InIter end, OutIter dst)
Retrieves values mapped to the specified keys from cache.
Definition: cache_client.h:185
ignite::thin::cache::CacheClient::GetAll
void GetAll(const Set &keys, Map &res)
Retrieves values mapped to the specified keys from cache.
Definition: cache_client.h:203
ignite::thin::cache::CacheClient::Replace
bool Replace(const K &key, const V &value)
Stores given key-value pair in cache only if there is a previous mapping for it.
Definition: cache_client.h:220
ignite::thin::cache::CacheClient::Clear
void Clear(const KeyType &key)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache_client.h:378
ignite::thin::cache::CacheClient::PutAll
void PutAll(const Map &vals)
Stores given key-value pairs in cache.
Definition: cache_client.h:137
ignite::thin::cache::CacheClient::GetAndRemove
void GetAndRemove(const KeyType &key, ValueType &valOut)
Atomically removes the entry for a key only if currently mapped to some value.
Definition: cache_client.h:463
ignite::thin::cache::query::continuous::ContinuousQueryClient::GetJavaFilter
event::JavaCacheEntryEventFilter & GetJavaFilter()
Get remote Java filter reference.
Definition: continuous_query_client.h:230
ignite::thin::cache::CacheClient::Clear
void Clear()
Clear cache.
Definition: cache_client.h:388
ignite::thin::cache::CacheClient::GetAndReplace
void GetAndReplace(const KeyType &key, const ValueType &valIn, ValueType &valOut)
Atomically replaces the value for a given key if and only if there is a value currently mapped by the...
Definition: cache_client.h:496
ignite::thin::cache::CacheClient::GetAndPutIfAbsent
void GetAndPutIfAbsent(const KeyType &key, const ValueType &valIn, ValueType &valOut)
Stores given key-value pair in cache only if cache had no previous mapping for it.
Definition: cache_client.h:558
ignite::impl::thin::ReadableImpl
Definition: thin-client/include/ignite/thin/cache/cache_entry.h:35
ignite::thin::cache::CacheClient::RefreshAffinityMapping
void RefreshAffinityMapping()
Refresh affinity mapping.
Definition: cache_client.h:644
ignite::thin::cache::CacheClient::ContainsKeys
bool ContainsKeys(InIter begin, InIter end)
Check if cache contains mapping for these keys.
Definition: cache_client.h:279
ignite::thin::cache::CacheClient::Remove
bool Remove(const KeyType &key, const ValueType &val)
Removes given key mapping from cache if one exists and value is equal to the passed in value.
Definition: cache_client.h:327
ignite::thin::cache::CacheClient::ClearAll
void ClearAll(const Set &keys)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache_client.h:400
ignite::thin::cache::CacheClient::Get
ValueType Get(const KeyType &key)
Get value from cache.
Definition: cache_client.h:165
query_cursor.h