| 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 #include <ignite/thin/cache/query/continuous/continuous_query_client.h>
31 #include <ignite/thin/cache/query/continuous/continuous_query_handle.h>
32
33 #include <ignite/impl/thin/writable.h>
34 #include <ignite/impl/thin/writable_key.h>
35
36 #include <ignite/impl/thin/readable.h>
37 #include <ignite/impl/thin/cache/cache_client_proxy.h>
38 #include <ignite/impl/thin/cache/continuous/continuous_query_client_holder.h>
39
40 namespace ignite
41 {
42 namespace thin
43 {
44 namespace cache
45 {
61 template<typename K, typename V>
62 class CacheClient
63 {
64 friend class impl::thin::cache::CacheClientProxy;
65
66 public:
68 typedef K KeyType;
69
71 typedef V ValueType;
72
78 explicit CacheClient(const common::concurrent::SharedPointer<void>& impl) :
79 proxy(impl)
80 {
81 // No-op.
82 }
83
87 CacheClient()
88 {
89 // No-op.
90 }
91
95 ~CacheClient()
96 {
97 // No-op.
98 }
99
106 void Put(const KeyType& key, const ValueType& value)
107 {
108 impl::thin::WritableKeyImpl<KeyType> wrKey(key);
109 impl::thin::WritableImpl<ValueType> wrValue(value);
110
111 proxy.Put(wrKey, wrValue);
112 }
113
121 template<typename InIter>
122 void PutAll(InIter begin, InIter end)
123 {
124 impl::thin::WritableMapImpl<K, V, InIter> wrSeq(begin, end);
125
126 proxy.PutAll(wrSeq);
127 }
128
135 template<typename Map>
136 void PutAll(const Map& vals)
137 {
138 PutAll(vals.begin(), vals.end());
139 }
140
147 void Get(const KeyType& key, ValueType& value)
148 {
149 impl::thin::WritableKeyImpl<KeyType> wrKey(key);
150 impl::thin::ReadableImpl<ValueType> rdValue(value);
151
152 proxy.Get(wrKey, rdValue);
153 }
154
161 ValueType Get(const KeyType& key)
162 {
163 ValueType value;
164
165 Get(key, value);
166
167 return value;
168 }
169
180 template<typename InIter, typename OutIter>
181 void GetAll(InIter begin, InIter end, OutIter dst)
182 {
183 impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
184 impl::thin::ReadableMapImpl<K, V, OutIter> rdSeq(dst);
185
186 proxy.GetAll(wrSeq, rdSeq);
187 }
188
198 template<typename Set, typename Map>
199 void GetAll(const Set& keys, Map& res)
200 {
201 return GetAll(keys.begin(), keys.end(), std::inserter(res, res.end()));
202 }
203
216 bool Replace(const K& key, const V& value)
217 {
218 impl::thin::WritableKeyImpl<KeyType> wrKey(key);
219 impl::thin::WritableImpl<ValueType> wrValue(value);
220
221 return proxy.Replace(wrKey, wrValue);
222 }
223
233 bool Replace(const KeyType& key, const ValueType& oldVal, const ValueType& newVal)
234 {
235 impl::thin::WritableKeyImpl<KeyType> wrKey(key);
236 impl::thin::WritableImpl<ValueType> wrOldVal(oldVal);
237 impl::thin::WritableImpl<ValueType> wrNewVal(newVal);
238
239 return proxy.Replace(wrKey, wrOldVal, wrNewVal);
240 }
241
248 bool ContainsKey(const KeyType& key)
249 {
250 impl::thin::WritableKeyImpl<KeyType> wrKey(key);
251
252 return proxy.ContainsKey(wrKey);
253 }
254
261 template<typename Set>
262 bool ContainsKeys(const Set& keys)
263 {
264 return ContainsKeys(keys.begin(), keys.end());
265 }
266
274 template<typename InIter>
275 bool ContainsKeys(InIter begin, InIter end)
276 {
277 impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
278
279 return proxy.ContainsKeys(wrSeq);
280 }
281
291 int64_t GetSize(int32_t peekModes)
292 {
293 return proxy.GetSize(peekModes);
294 }
295
308 bool Remove(const KeyType& key)
309 {
310 impl::thin::WritableKeyImpl<KeyType> wrKey(key);
311
312 return proxy.Remove(wrKey);
313 }
314
323 bool Remove(const KeyType& key, const ValueType& val)
324 {
325 impl::thin::WritableKeyImpl<KeyType> wrKey(key);
326 impl::thin::WritableImpl<ValueType> wrVal(val);
327
328 return proxy.Remove(wrKey, wrVal);
329 }
330
337 template<typename Set>
338 void RemoveAll(const Set& keys)
339 {
340 RemoveAll(keys.begin(), keys.end());
341 }
342
350 template<typename InIter>
351 void RemoveAll(InIter begin, InIter end)
352 {
353 impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
354
355 proxy.RemoveAll(wrSeq);
356 }
357
363 void RemoveAll()
364 {
365 proxy.RemoveAll();
366 }
367
374 void Clear(const KeyType& key)
375 {
376 impl::thin::WritableKeyImpl<KeyType> wrKey(key);
377
378 proxy.Clear(wrKey);
379 }
380
384 void Clear()
385 {
386 proxy.Clear();
387 }
388
395 template<typename Set>
396 void ClearAll(const Set& keys)
397 {
398 ClearAll(keys.begin(), keys.end());
399 }
400
408 template<typename InIter>
409 void ClearAll(InIter begin, InIter end)
410 {
411 impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
412
413 proxy.ClearAll(wrSeq);
414 }
415
425 void GetAndPut(const KeyType& key, const ValueType& valIn, ValueType& valOut)
426 {
427 impl::thin::WritableKeyImpl<KeyType> wrKey(key);
428 impl::thin::WritableImpl<ValueType> wrValIn(valIn);
429 impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
430
431 proxy.GetAndPut(wrKey, wrValIn, rdValOut);
432 }
433
443 ValueType GetAndPut(const KeyType& key, const ValueType& valIn)
444 {
445 ValueType valOut;
446
447 GetAndPut(key, valIn, valOut);
448
449 return valOut;
450 }
451
459 void GetAndRemove(const KeyType& key, ValueType& valOut)
460 {
461 impl::thin::WritableKeyImpl<KeyType> wrKey(key);
462 impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
463
464 proxy.GetAndRemove(wrKey, rdValOut);
465 }
466
474 ValueType GetAndRemove(const KeyType& key)
475 {
476 ValueType valOut;
477
478 GetAndRemove(key, valOut);
479
480 return valOut;
481 }
482
492 void GetAndReplace(const KeyType& key, const ValueType& valIn, ValueType& valOut)
493 {
494 impl::thin::WritableKeyImpl<KeyType> wrKey(key);
495 impl::thin::WritableImpl<ValueType> wrValIn(valIn);
496 impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
497
498 proxy.GetAndReplace(wrKey, wrValIn, rdValOut);
499 }
500
510 ValueType GetAndReplace(const KeyType& key, const ValueType& valIn)
511 {
512 ValueType valOut;
513
514 GetAndReplace(key, valIn, valOut);
515
516 return valOut;
517 }
518
527 bool PutIfAbsent(const KeyType& key, const ValueType& val)
528 {
529 impl::thin::WritableKeyImpl<KeyType> wrKey(key);
530 impl::thin::WritableImpl<ValueType> wrValIn(val);
531
532 return proxy.PutIfAbsent(wrKey, wrValIn);
533 }
534
554 void GetAndPutIfAbsent(const KeyType& key, const ValueType& valIn, ValueType& valOut)
555 {
556 impl::thin::WritableKeyImpl<KeyType> wrKey(key);
557 impl::thin::WritableImpl<ValueType> wrValIn(valIn);
558 impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
559
560 proxy.GetAndPutIfAbsent(wrKey, wrValIn, rdValOut);
561 }
562
582 ValueType GetAndPutIfAbsent(const KeyType& key, const ValueType& valIn)
583 {
584 ValueType valOut;
585
586 GetAndPutIfAbsent(key, valIn, valOut);
587
588 return valOut;
589 }
590
597 query::QueryFieldsCursor Query(const query::SqlFieldsQuery& qry)
598 {
599 return proxy.Query(qry);
600 }
601
608 query::continuous::ContinuousQueryHandleClient QueryContinuous(
609 query::continuous::ContinuousQueryClient<K, V> continuousQuery)
610 {
611 using namespace impl::thin::cache::query::continuous;
612
613 SP_ContinuousQueryClientHolderBase holder(new ContinuousQueryClientHolder<K, V>(continuousQuery));
614
615 return proxy.QueryContinuous(holder);
616 }
617
629 void RefreshAffinityMapping()
630 {
631 // No-op.
632 }
633
634 private:
636 impl::thin::cache::CacheClientProxy proxy;
637 };
638 }
639 }
640 }
641
642 #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:122
ignite
Apache Ignite API.
Definition: cache.h:48
continuous_query_client.h
ignite::thin::cache::CacheClient::RemoveAll
void RemoveAll()
Removes all mappings from cache.
Definition: cache_client.h:363
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:474
ignite::thin::cache::CacheClient::~CacheClient
~CacheClient()
Destructor.
Definition: cache_client.h:95
continuous_query_handle.h
ignite::thin::cache::CacheClient::Remove
bool Remove(const KeyType &key)
Removes given key mapping from cache.
Definition: cache_client.h:308
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:351
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:510
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::ContainsKeys
bool ContainsKeys(const Set &keys)
Check if cache contains mapping for these keys.
Definition: cache_client.h:262
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:291
ignite::thin::cache::query::continuous::ContinuousQueryHandleClient
Continuous query handle client.
Definition: thin-client/include/ignite/thin/cache/query/continuous/continuous_query_handle.h:43
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::thin::cache::CacheClient::CacheClient
CacheClient(const common::concurrent::SharedPointer< void > &impl)
Constructor.
Definition: cache_client.h:78
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:582
ignite::thin::cache::CacheClient::RemoveAll
void RemoveAll(const Set &keys)
Removes given key mappings from cache.
Definition: cache_client.h:338
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:248
ignite::thin::cache::CacheClient::QueryContinuous
query::continuous::ContinuousQueryHandleClient QueryContinuous(query::continuous::ContinuousQueryClient< K, V > continuousQuery)
Starts the continuous query execution.
Definition: cache_client.h:608
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:443
ignite::thin::cache::CacheClient::KeyType
K KeyType
Key type.
Definition: cache_client.h:68
ignite::thin::cache::CacheClient
Cache client class template.
Definition: cache_client.h:62
ignite::thin::cache::CacheClient::Query
query::QueryFieldsCursor Query(const query::SqlFieldsQuery &qry)
Perform SQL fields query.
Definition: cache_client.h:597
ignite::thin::cache::CacheClient::ValueType
V ValueType
Value type.
Definition: cache_client.h:71
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:233
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:527
ignite::thin::cache::CacheClient::Get
void Get(const KeyType &key, ValueType &value)
Get value from the cache.
Definition: cache_client.h:147
ignite::thin::cache::CacheClient::CacheClient
CacheClient()
Default constructor.
Definition: cache_client.h:87
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:425
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:409
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:106
query_sql_fields.h
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:181
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:199
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:216
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:374
ignite::thin::cache::CacheClient::PutAll
void PutAll(const Map &vals)
Stores given key-value pairs in cache.
Definition: cache_client.h:136
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:459
ignite::thin::cache::CacheClient::Clear
void Clear()
Clear cache.
Definition: cache_client.h:384
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:492
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:554
ignite::thin::cache::CacheClient::RefreshAffinityMapping
void RefreshAffinityMapping()
Refresh affinity mapping.
Definition: cache_client.h:629
ignite::thin::cache::CacheClient::ContainsKeys
bool ContainsKeys(InIter begin, InIter end)
Check if cache contains mapping for these keys.
Definition: cache_client.h:275
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:323
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:396
ignite::thin::cache::CacheClient::Get
ValueType Get(const KeyType &key)
Get value from cache.
Definition: cache_client.h:161