Apache Ignite C++
cache_client.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
23 #ifndef _IGNITE_THIN_CACHE_CACHE_CLIENT
24 #define _IGNITE_THIN_CACHE_CACHE_CLIENT
25 
26 #include <ignite/common/concurrent.h>
27 
30 
31 #include <ignite/impl/thin/writable.h>
32 #include <ignite/impl/thin/writable_key.h>
33 
34 #include <ignite/impl/thin/readable.h>
35 #include <ignite/impl/thin/cache/cache_client_proxy.h>
36 
37 namespace ignite
38 {
39  namespace thin
40  {
41  namespace cache
42  {
58  template<typename K, typename V>
60  {
61  friend class impl::thin::cache::CacheClientProxy;
62 
63  public:
65  typedef K KeyType;
66 
68  typedef V ValueType;
69 
75  CacheClient(common::concurrent::SharedPointer<void> impl) :
76  proxy(impl)
77  {
78  // No-op.
79  }
80 
85  {
86  // No-op.
87  }
88 
93  {
94  // No-op.
95  }
96 
103  void Put(const KeyType& key, const ValueType& value)
104  {
105  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
106  impl::thin::WritableImpl<ValueType> wrValue(value);
107 
108  proxy.Put(wrKey, wrValue);
109  }
110 
118  template<typename InIter>
119  void PutAll(InIter begin, InIter end)
120  {
121  impl::thin::WritableMapImpl<K, V, InIter> wrSeq(begin, end);
122 
123  proxy.PutAll(wrSeq);
124  }
125 
132  template<typename Map>
133  void PutAll(const Map& vals)
134  {
135  PutAll(vals.begin(), vals.end());
136  }
137 
144  void Get(const KeyType& key, ValueType& value)
145  {
146  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
147  impl::thin::ReadableImpl<ValueType> rdValue(value);
148 
149  proxy.Get(wrKey, rdValue);
150  }
151 
158  ValueType Get(const KeyType& key)
159  {
160  ValueType value;
161 
162  Get(key, value);
163 
164  return value;
165  }
166 
177  template<typename InIter, typename OutIter>
178  void GetAll(InIter begin, InIter end, OutIter dst)
179  {
180  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
181  impl::thin::ReadableMapImpl<K, V, OutIter> rdSeq(dst);
182 
183  proxy.GetAll(wrSeq, rdSeq);
184  }
185 
195  template<typename Set, typename Map>
196  void GetAll(const Set& keys, Map& res)
197  {
198  return GetAll(keys.begin(), keys.end(), std::inserter(res, res.end()));
199  }
200 
213  bool Replace(const K& key, const V& value)
214  {
215  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
216  impl::thin::WritableImpl<ValueType> wrValue(value);
217 
218  return proxy.Replace(wrKey, wrValue);
219  }
220 
230  bool Replace(const KeyType& key, const ValueType& oldVal, const ValueType& newVal)
231  {
232  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
233  impl::thin::WritableImpl<ValueType> wrOldVal(oldVal);
234  impl::thin::WritableImpl<ValueType> wrNewVal(newVal);
235 
236  return proxy.Replace(wrKey, wrOldVal, wrNewVal);
237  }
238 
245  bool ContainsKey(const KeyType& key)
246  {
247  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
248 
249  return proxy.ContainsKey(wrKey);
250  }
251 
258  template<typename Set>
259  bool ContainsKeys(const Set& keys)
260  {
261  return ContainsKeys(keys.begin(), keys.end());
262  }
263 
271  template<typename InIter>
272  bool ContainsKeys(InIter begin, InIter end)
273  {
274  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
275 
276  return proxy.ContainsKeys(wrSeq);
277  }
278 
288  int64_t GetSize(int32_t peekModes)
289  {
290  return proxy.GetSize(peekModes);
291  }
292 
305  bool Remove(const KeyType& key)
306  {
307  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
308 
309  return proxy.Remove(wrKey);
310  }
311 
320  bool Remove(const KeyType& key, const ValueType& val)
321  {
322  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
323  impl::thin::WritableImpl<ValueType> wrVal(val);
324 
325  return proxy.Remove(wrKey, wrVal);
326  }
327 
334  template<typename Set>
335  void RemoveAll(const Set& keys)
336  {
337  RemoveAll(keys.begin(), keys.end());
338  }
339 
347  template<typename InIter>
348  void RemoveAll(InIter begin, InIter end)
349  {
350  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
351 
352  proxy.RemoveAll(wrSeq);
353  }
354 
360  void RemoveAll()
361  {
362  proxy.RemoveAll();
363  }
364 
371  void Clear(const KeyType& key)
372  {
373  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
374 
375  proxy.Clear(wrKey);
376  }
377 
381  void Clear()
382  {
383  proxy.Clear();
384  }
385 
392  template<typename Set>
393  void ClearAll(const Set& keys)
394  {
395  ClearAll(keys.begin(), keys.end());
396  }
397 
405  template<typename InIter>
406  void ClearAll(InIter begin, InIter end)
407  {
408  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
409 
410  proxy.ClearAll(wrSeq);
411  }
412 
422  void GetAndPut(const KeyType& key, const ValueType& valIn, ValueType& valOut)
423  {
424  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
425  impl::thin::WritableImpl<ValueType> wrValIn(valIn);
426  impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
427 
428  proxy.GetAndPut(wrKey, wrValIn, rdValOut);
429  }
430 
440  ValueType GetAndPut(const KeyType& key, const ValueType& valIn)
441  {
442  ValueType valOut;
443 
444  GetAndPut(key, valIn, valOut);
445 
446  return valOut;
447  }
448 
456  void GetAndRemove(const KeyType& key, ValueType& valOut)
457  {
458  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
459  impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
460 
461  proxy.GetAndRemove(wrKey, rdValOut);
462  }
463 
471  ValueType GetAndRemove(const KeyType& key)
472  {
473  ValueType valOut;
474 
475  GetAndRemove(key, valOut);
476 
477  return valOut;
478  }
479 
489  void GetAndReplace(const KeyType& key, const ValueType& valIn, ValueType& valOut)
490  {
491  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
492  impl::thin::WritableImpl<ValueType> wrValIn(valIn);
493  impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
494 
495  proxy.GetAndReplace(wrKey, wrValIn, rdValOut);
496  }
497 
507  ValueType GetAndReplace(const KeyType& key, const ValueType& valIn)
508  {
509  ValueType valOut;
510 
511  GetAndReplace(key, valIn, valOut);
512 
513  return valOut;
514  }
515 
524  bool PutIfAbsent(const KeyType& key, const ValueType& val)
525  {
526  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
527  impl::thin::WritableImpl<ValueType> wrValIn(val);
528 
529  return proxy.PutIfAbsent(wrKey, wrValIn);
530  }
531 
551  void GetAndPutIfAbsent(const KeyType& key, const ValueType& valIn, ValueType& valOut)
552  {
553  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
554  impl::thin::WritableImpl<ValueType> wrValIn(valIn);
555  impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
556 
557  proxy.GetAndPutIfAbsent(wrKey, wrValIn, rdValOut);
558  }
559 
579  ValueType GetAndPutIfAbsent(const KeyType& key, const ValueType& valIn)
580  {
581  ValueType valOut;
582 
583  GetAndPutIfAbsent(key, valIn, valOut);
584 
585  return valOut;
586  }
587 
595  {
596  return proxy.Query(qry);
597  }
598 
611  {
612  // No-op.
613  }
614 
615  private:
617  impl::thin::cache::CacheClientProxy proxy;
618  };
619  }
620  }
621 }
622 
623 #endif // _IGNITE_THIN_CACHE_CACHE_CLIENT
V ValueType
Value type.
Definition: cache_client.h:68
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:456
void GetAll(InIter begin, InIter end, OutIter dst)
Retrieves values mapped to the specified keys from cache.
Definition: cache_client.h:178
void RemoveAll()
Removes all mappings from cache.
Definition: cache_client.h:360
Declares ignite::thin::cache::query::QueryFieldsCursor class.
CacheClient(common::concurrent::SharedPointer< void > impl)
Constructor.
Definition: cache_client.h:75
ValueType GetAndRemove(const KeyType &key)
Atomically removes the entry for a key only if currently mapped to some value.
Definition: cache_client.h:471
int64_t GetSize(int32_t peekModes)
Gets the number of all entries cached across all nodes.
Definition: cache_client.h:288
void RemoveAll(InIter begin, InIter end)
Removes given key mappings from cache.
Definition: cache_client.h:348
K KeyType
Key type.
Definition: cache_client.h:65
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:579
bool ContainsKeys(InIter begin, InIter end)
Check if cache contains mapping for these keys.
Definition: cache_client.h:272
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:507
~CacheClient()
Destructor.
Definition: cache_client.h:92
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:213
ValueType Get(const KeyType &key)
Get value from cache.
Definition: cache_client.h:158
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:320
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:551
void PutAll(const Map &vals)
Stores given key-value pairs in cache.
Definition: cache_client.h:133
void PutAll(InIter begin, InIter end)
Stores given key-value pairs in cache.
Definition: cache_client.h:119
CacheClient()
Default constructor.
Definition: cache_client.h:84
bool ContainsKeys(const Set &keys)
Check if cache contains mapping for these keys.
Definition: cache_client.h:259
void Clear(const KeyType &key)
Clear entry from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache_client.h:371
void Put(const KeyType &key, const ValueType &value)
Associate the specified value with the specified key in the cache.
Definition: cache_client.h:103
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:422
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:230
void RefreshAffinityMapping()
Refresh affinity mapping.
Definition: cache_client.h:610
void GetAll(const Set &keys, Map &res)
Retrieves values mapped to the specified keys from cache.
Definition: cache_client.h:196
Cache client class template.
Definition: cache_client.h:59
bool Remove(const KeyType &key)
Removes given key mapping from cache.
Definition: cache_client.h:305
void RemoveAll(const Set &keys)
Removes given key mappings from cache.
Definition: cache_client.h:335
void ClearAll(InIter begin, InIter end)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache_client.h:406
SQL fields query for thin client.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:52
Apache Ignite API.
Definition: cache.h:48
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:489
bool ContainsKey(const KeyType &key)
Check if the cache contains a value for the specified key.
Definition: cache_client.h:245
void ClearAll(const Set &keys)
Clear entries from the cache and swap storage, without notifying listeners or CacheWriters.
Definition: cache_client.h:393
Query fields cursor.
Definition: thin-client/include/ignite/thin/cache/query/query_fields_cursor.h:48
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:524
void Clear()
Clear cache.
Definition: cache_client.h:381
void Get(const KeyType &key, ValueType &value)
Get value from the cache.
Definition: cache_client.h:144
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:440
query::QueryFieldsCursor Query(const query::SqlFieldsQuery &qry)
Perform SQL fields query.
Definition: cache_client.h:594
Declares ignite::thin::cache::query::SqlFieldsQuery class.