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 
148  void Get(const KeyType& key, ValueType& value)
149  {
150  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
152 
153  proxy.Get(wrKey, rdValue);
154  }
155 
162  ValueType Get(const KeyType& key)
163  {
164  ValueType value;
165 
166  Get(key, value);
167 
168  return value;
169  }
170 
181  template<typename InIter, typename OutIter>
182  void GetAll(InIter begin, InIter end, OutIter dst)
183  {
184  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
185  impl::thin::ReadableContainerImpl< std::pair<K, V>, OutIter> rdSeq(dst);
186 
187  proxy.GetAll(wrSeq, rdSeq);
188  }
189 
199  template<typename Set, typename Map>
200  void GetAll(const Set& keys, Map& res)
201  {
202  return GetAll(keys.begin(), keys.end(), std::inserter(res, res.end()));
203  }
204 
217  bool Replace(const K& key, const V& value)
218  {
219  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
220  impl::thin::WritableImpl<ValueType> wrValue(value);
221 
222  return proxy.Replace(wrKey, wrValue);
223  }
224 
234  bool Replace(const KeyType& key, const ValueType& oldVal, const ValueType& newVal)
235  {
236  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
237  impl::thin::WritableImpl<ValueType> wrOldVal(oldVal);
238  impl::thin::WritableImpl<ValueType> wrNewVal(newVal);
239 
240  return proxy.Replace(wrKey, wrOldVal, wrNewVal);
241  }
242 
249  bool ContainsKey(const KeyType& key)
250  {
251  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
252 
253  return proxy.ContainsKey(wrKey);
254  }
255 
262  template<typename Set>
263  bool ContainsKeys(const Set& keys)
264  {
265  return ContainsKeys(keys.begin(), keys.end());
266  }
267 
275  template<typename InIter>
276  bool ContainsKeys(InIter begin, InIter end)
277  {
278  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
279 
280  return proxy.ContainsKeys(wrSeq);
281  }
282 
292  int64_t GetSize(int32_t peekModes)
293  {
294  return proxy.GetSize(peekModes);
295  }
296 
309  bool Remove(const KeyType& key)
310  {
311  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
312 
313  return proxy.Remove(wrKey);
314  }
315 
324  bool Remove(const KeyType& key, const ValueType& val)
325  {
326  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
327  impl::thin::WritableImpl<ValueType> wrVal(val);
328 
329  return proxy.Remove(wrKey, wrVal);
330  }
331 
338  template<typename Set>
339  void RemoveAll(const Set& keys)
340  {
341  RemoveAll(keys.begin(), keys.end());
342  }
343 
351  template<typename InIter>
352  void RemoveAll(InIter begin, InIter end)
353  {
354  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
355 
356  proxy.RemoveAll(wrSeq);
357  }
358 
364  void RemoveAll()
365  {
366  proxy.RemoveAll();
367  }
368 
375  void Clear(const KeyType& key)
376  {
377  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
378 
379  proxy.Clear(wrKey);
380  }
381 
385  void Clear()
386  {
387  proxy.Clear();
388  }
389 
396  template<typename Set>
397  void ClearAll(const Set& keys)
398  {
399  ClearAll(keys.begin(), keys.end());
400  }
401 
409  template<typename InIter>
410  void ClearAll(InIter begin, InIter end)
411  {
412  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
413 
414  proxy.ClearAll(wrSeq);
415  }
416 
426  void GetAndPut(const KeyType& key, const ValueType& valIn, ValueType& valOut)
427  {
428  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
429  impl::thin::WritableImpl<ValueType> wrValIn(valIn);
430  impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
431 
432  proxy.GetAndPut(wrKey, wrValIn, rdValOut);
433  }
434 
444  ValueType GetAndPut(const KeyType& key, const ValueType& valIn)
445  {
446  ValueType valOut;
447 
448  GetAndPut(key, valIn, valOut);
449 
450  return valOut;
451  }
452 
460  void GetAndRemove(const KeyType& key, ValueType& valOut)
461  {
462  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
463  impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
464 
465  proxy.GetAndRemove(wrKey, rdValOut);
466  }
467 
476  {
477  ValueType valOut;
478 
479  GetAndRemove(key, valOut);
480 
481  return valOut;
482  }
483 
493  void GetAndReplace(const KeyType& key, const ValueType& valIn, ValueType& valOut)
494  {
495  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
496  impl::thin::WritableImpl<ValueType> wrValIn(valIn);
497  impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
498 
499  proxy.GetAndReplace(wrKey, wrValIn, rdValOut);
500  }
501 
511  ValueType GetAndReplace(const KeyType& key, const ValueType& valIn)
512  {
513  ValueType valOut;
514 
515  GetAndReplace(key, valIn, valOut);
516 
517  return valOut;
518  }
519 
528  bool PutIfAbsent(const KeyType& key, const ValueType& val)
529  {
530  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
531  impl::thin::WritableImpl<ValueType> wrValIn(val);
532 
533  return proxy.PutIfAbsent(wrKey, wrValIn);
534  }
535 
555  void GetAndPutIfAbsent(const KeyType& key, const ValueType& valIn, ValueType& valOut)
556  {
557  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
558  impl::thin::WritableImpl<ValueType> wrValIn(valIn);
559  impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
560 
561  proxy.GetAndPutIfAbsent(wrKey, wrValIn, rdValOut);
562  }
563 
583  ValueType GetAndPutIfAbsent(const KeyType& key, const ValueType& valIn)
584  {
585  ValueType valOut;
586 
587  GetAndPutIfAbsent(key, valIn, valOut);
588 
589  return valOut;
590  }
591 
599  {
600  return proxy.Query(qry);
601  }
602 
610  {
611  return query::QueryCursor<KeyType, ValueType>(proxy.Query(qry));
612  }
613 
622  {
623  using namespace impl::thin::cache::query::continuous;
624 
625  SP_ContinuousQueryClientHolderBase holder(new ContinuousQueryClientHolder<K, V>(continuousQuery));
626 
627  return proxy.QueryContinuous(holder, continuousQuery.GetJavaFilter());
628  }
629 
642  {
643  // No-op.
644  }
645 
646  private:
648  impl::thin::cache::CacheClientProxy proxy;
649  };
650  }
651  }
652 }
653 
654 #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:364
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:475
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:309
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:352
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:511
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:263
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:292
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:583
ignite::thin::cache::CacheClient::RemoveAll
void RemoveAll(const Set &keys)
Removes given key mappings from cache.
Definition: cache_client.h:339
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:249
ignite::thin::cache::CacheClient::QueryContinuous
query::continuous::ContinuousQueryHandleClient QueryContinuous(query::continuous::ContinuousQueryClient< K, V > continuousQuery)
Starts the continuous query execution.
Definition: cache_client.h:620
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:444
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:598
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:234
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:528
ignite::thin::cache::CacheClient::Get
void Get(const KeyType &key, ValueType &value)
Get value from the cache.
Definition: cache_client.h:148
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:609
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:426
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:410
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:182
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:200
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:217
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:375
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:460
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:385
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:493
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:555
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:641
ignite::thin::cache::CacheClient::ContainsKeys
bool ContainsKeys(InIter begin, InIter end)
Check if cache contains mapping for these keys.
Definition: cache_client.h:276
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:324
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:397
ignite::thin::cache::CacheClient::Get
ValueType Get(const KeyType &key)
Get value from cache.
Definition: cache_client.h:162
query_cursor.h