| 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
28 #include <ignite/thin/cache/query/query_fields_cursor.h>
29 #include <ignite/thin/cache/query/query_sql_fields.h>
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>
59 class CacheClient
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
84 CacheClient()
85 {
86 // No-op.
87 }
88
92 ~CacheClient()
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
594 query::QueryFieldsCursor Query(const query::SqlFieldsQuery& qry)
595 {
596 return proxy.Query(qry);
597 }
598
610 void RefreshAffinityMapping()
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
ignite::thin::cache::CacheClient::ValueType
V ValueType
Value type.
Definition: cache_client.h:68
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:456
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:178
ignite::thin::cache::CacheClient::RemoveAll
void RemoveAll()
Removes all mappings from cache.
Definition: cache_client.h:360
query_fields_cursor.h
Declares ignite::thin::cache::query::QueryFieldsCursor class.
ignite::thin::cache::CacheClient::CacheClient
CacheClient(common::concurrent::SharedPointer< void > impl)
Constructor.
Definition: cache_client.h:75
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:471
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:288
ignite::thin::cache::CacheClient::RemoveAll
void RemoveAll(InIter begin, InIter end)
Removes given key mappings from cache.
Definition: cache_client.h:348
ignite::thin::cache::CacheClient::KeyType
K KeyType
Key type.
Definition: cache_client.h:65
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:579
ignite::thin::cache::CacheClient::ContainsKeys
bool ContainsKeys(InIter begin, InIter end)
Check if cache contains mapping for these keys.
Definition: cache_client.h:272
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:507
ignite::thin::cache::CacheClient::~CacheClient
~CacheClient()
Destructor.
Definition: cache_client.h:92
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:213
ignite::thin::cache::CacheClient::Get
ValueType Get(const KeyType &key)
Get value from cache.
Definition: cache_client.h:158
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:320
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:551
ignite::thin::cache::CacheClient::PutAll
void PutAll(const Map &vals)
Stores given key-value pairs in cache.
Definition: cache_client.h:133
ignite::thin::cache::CacheClient::PutAll
void PutAll(InIter begin, InIter end)
Stores given key-value pairs in cache.
Definition: cache_client.h:119
ignite::thin::cache::CacheClient::CacheClient
CacheClient()
Default constructor.
Definition: cache_client.h:84
ignite::thin::cache::CacheClient::ContainsKeys
bool ContainsKeys(const Set &keys)
Check if cache contains mapping for these keys.
Definition: cache_client.h:259
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:371
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:103
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:422
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:230
ignite::thin::cache::CacheClient::RefreshAffinityMapping
void RefreshAffinityMapping()
Refresh affinity mapping.
Definition: cache_client.h:610
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:196
ignite::thin::cache::CacheClient
Cache client class template.
Definition: cache_client.h:59
ignite::thin::cache::CacheClient::Remove
bool Remove(const KeyType &key)
Removes given key mapping from cache.
Definition: cache_client.h:305
ignite::thin::cache::CacheClient::RemoveAll
void RemoveAll(const Set &keys)
Removes given key mappings from cache.
Definition: cache_client.h:335
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:406
ignite::thin::cache::query::SqlFieldsQuery
SQL fields query for thin client.
Definition: thin-client/include/ignite/thin/cache/query/query_sql_fields.h:52
ignite
Apache Ignite API.
Definition: cache.h:48
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:489
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:245
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:393
ignite::thin::cache::query::QueryFieldsCursor
Query fields cursor.
Definition: thin-client/include/ignite/thin/cache/query/query_fields_cursor.h:48
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:524
ignite::thin::cache::CacheClient::Clear
void Clear()
Clear cache.
Definition: cache_client.h:381
ignite::thin::cache::CacheClient::Get
void Get(const KeyType &key, ValueType &value)
Get value from the cache.
Definition: cache_client.h:144
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:440
ignite::thin::cache::CacheClient::Query
query::QueryFieldsCursor Query(const query::SqlFieldsQuery &qry)
Perform SQL fields query.
Definition: cache_client.h:594
query_sql_fields.h
Declares ignite::thin::cache::query::SqlFieldsQuery class.