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 
34 
35 #include <ignite/impl/thin/writable.h>
36 #include <ignite/impl/thin/writable_key.h>
37 
38 #include <ignite/impl/thin/readable.h>
39 #include <ignite/impl/thin/cache/cache_client_proxy.h>
40 #include <ignite/impl/thin/cache/continuous/continuous_query_client_holder.h>
41 
42 namespace ignite
43 {
44  namespace thin
45  {
46  namespace cache
47  {
63  template<typename K, typename V>
65  {
66  friend class impl::thin::cache::CacheClientProxy;
67 
68  public:
70  typedef K KeyType;
71 
73  typedef V ValueType;
74 
80  explicit CacheClient(const common::concurrent::SharedPointer<void>& impl) :
81  proxy(impl)
82  {
83  // No-op.
84  }
85 
90  {
91  // No-op.
92  }
93 
98  {
99  // No-op.
100  }
101 
108  void Put(const KeyType& key, const ValueType& value)
109  {
110  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
111  impl::thin::WritableImpl<ValueType> wrValue(value);
112 
113  proxy.Put(wrKey, wrValue);
114  }
115 
123  template<typename InIter>
124  void PutAll(InIter begin, InIter end)
125  {
126  impl::thin::WritableMapImpl<K, V, InIter> wrSeq(begin, end);
127 
128  proxy.PutAll(wrSeq);
129  }
130 
137  template<typename Map>
138  void PutAll(const Map& vals)
139  {
140  PutAll(vals.begin(), vals.end());
141  }
142 
149  void Get(const KeyType& key, ValueType& value)
150  {
151  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
153 
154  proxy.Get(wrKey, rdValue);
155  }
156 
163  ValueType Get(const KeyType& key)
164  {
165  ValueType value;
166 
167  Get(key, value);
168 
169  return value;
170  }
171 
182  template<typename InIter, typename OutIter>
183  void GetAll(InIter begin, InIter end, OutIter dst)
184  {
185  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
186  impl::thin::ReadableContainerImpl< std::pair<K, V>, OutIter> rdSeq(dst);
187 
188  proxy.GetAll(wrSeq, rdSeq);
189  }
190 
200  template<typename Set, typename Map>
201  void GetAll(const Set& keys, Map& res)
202  {
203  return GetAll(keys.begin(), keys.end(), std::inserter(res, res.end()));
204  }
205 
218  bool Replace(const K& key, const V& value)
219  {
220  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
221  impl::thin::WritableImpl<ValueType> wrValue(value);
222 
223  return proxy.Replace(wrKey, wrValue);
224  }
225 
235  bool Replace(const KeyType& key, const ValueType& oldVal, const ValueType& newVal)
236  {
237  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
238  impl::thin::WritableImpl<ValueType> wrOldVal(oldVal);
239  impl::thin::WritableImpl<ValueType> wrNewVal(newVal);
240 
241  return proxy.Replace(wrKey, wrOldVal, wrNewVal);
242  }
243 
250  bool ContainsKey(const KeyType& key)
251  {
252  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
253 
254  return proxy.ContainsKey(wrKey);
255  }
256 
263  template<typename Set>
264  bool ContainsKeys(const Set& keys)
265  {
266  return ContainsKeys(keys.begin(), keys.end());
267  }
268 
276  template<typename InIter>
277  bool ContainsKeys(InIter begin, InIter end)
278  {
279  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
280 
281  return proxy.ContainsKeys(wrSeq);
282  }
283 
293  int64_t GetSize(int32_t peekModes)
294  {
295  return proxy.GetSize(peekModes);
296  }
297 
310  bool Remove(const KeyType& key)
311  {
312  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
313 
314  return proxy.Remove(wrKey);
315  }
316 
325  bool Remove(const KeyType& key, const ValueType& val)
326  {
327  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
328  impl::thin::WritableImpl<ValueType> wrVal(val);
329 
330  return proxy.Remove(wrKey, wrVal);
331  }
332 
339  template<typename Set>
340  void RemoveAll(const Set& keys)
341  {
342  RemoveAll(keys.begin(), keys.end());
343  }
344 
352  template<typename InIter>
353  void RemoveAll(InIter begin, InIter end)
354  {
355  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
356 
357  proxy.RemoveAll(wrSeq);
358  }
359 
365  void RemoveAll()
366  {
367  proxy.RemoveAll();
368  }
369 
376  void Clear(const KeyType& key)
377  {
378  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
379 
380  proxy.Clear(wrKey);
381  }
382 
386  void Clear()
387  {
388  proxy.Clear();
389  }
390 
397  template<typename Set>
398  void ClearAll(const Set& keys)
399  {
400  ClearAll(keys.begin(), keys.end());
401  }
402 
410  template<typename InIter>
411  void ClearAll(InIter begin, InIter end)
412  {
413  impl::thin::WritableSetImpl<K, InIter> wrSeq(begin, end);
414 
415  proxy.ClearAll(wrSeq);
416  }
417 
427  void GetAndPut(const KeyType& key, const ValueType& valIn, ValueType& valOut)
428  {
429  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
430  impl::thin::WritableImpl<ValueType> wrValIn(valIn);
431  impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
432 
433  proxy.GetAndPut(wrKey, wrValIn, rdValOut);
434  }
435 
445  ValueType GetAndPut(const KeyType& key, const ValueType& valIn)
446  {
447  ValueType valOut;
448 
449  GetAndPut(key, valIn, valOut);
450 
451  return valOut;
452  }
453 
461  void GetAndRemove(const KeyType& key, ValueType& valOut)
462  {
463  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
464  impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
465 
466  proxy.GetAndRemove(wrKey, rdValOut);
467  }
468 
477  {
478  ValueType valOut;
479 
480  GetAndRemove(key, valOut);
481 
482  return valOut;
483  }
484 
494  void GetAndReplace(const KeyType& key, const ValueType& valIn, ValueType& valOut)
495  {
496  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
497  impl::thin::WritableImpl<ValueType> wrValIn(valIn);
498  impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
499 
500  proxy.GetAndReplace(wrKey, wrValIn, rdValOut);
501  }
502 
512  ValueType GetAndReplace(const KeyType& key, const ValueType& valIn)
513  {
514  ValueType valOut;
515 
516  GetAndReplace(key, valIn, valOut);
517 
518  return valOut;
519  }
520 
529  bool PutIfAbsent(const KeyType& key, const ValueType& val)
530  {
531  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
532  impl::thin::WritableImpl<ValueType> wrValIn(val);
533 
534  return proxy.PutIfAbsent(wrKey, wrValIn);
535  }
536 
556  void GetAndPutIfAbsent(const KeyType& key, const ValueType& valIn, ValueType& valOut)
557  {
558  impl::thin::WritableKeyImpl<KeyType> wrKey(key);
559  impl::thin::WritableImpl<ValueType> wrValIn(valIn);
560  impl::thin::ReadableImpl<ValueType> rdValOut(valOut);
561 
562  proxy.GetAndPutIfAbsent(wrKey, wrValIn, rdValOut);
563  }
564 
584  ValueType GetAndPutIfAbsent(const KeyType& key, const ValueType& valIn)
585  {
586  ValueType valOut;
587 
588  GetAndPutIfAbsent(key, valIn, valOut);
589 
590  return valOut;
591  }
592 
600  {
601  return proxy.Query(qry);
602  }
603 
611  {
612  return query::QueryCursor<KeyType, ValueType>(proxy.Query(qry));
613  }
614 
623  {
624  using namespace impl::thin::cache::query::continuous;
625 
626  SP_ContinuousQueryClientHolderBase holder(new ContinuousQueryClientHolder<K, V>(continuousQuery));
627 
628  return proxy.QueryContinuous(holder, continuousQuery.GetJavaFilter());
629  }
630 
643  {
644  // No-op.
645  }
646 
647  private:
649  impl::thin::cache::CacheClientProxy proxy;
650  };
651  }
652  }
653 }
654 
655 #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:124
ignite
Apache Ignite API.
Definition: cache.h:48
query_scan.h
continuous_query_client.h
ignite::thin::cache::CacheClient::RemoveAll
void RemoveAll()
Removes all mappings from cache.
Definition: cache_client.h:365
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:476
ignite::thin::cache::CacheClient::~CacheClient
~CacheClient()
Destructor.
Definition: cache_client.h:97
continuous_query_handle.h
ignite::thin::cache::CacheClient::Remove
bool Remove(const KeyType &key)
Removes given key mapping from cache.
Definition: cache_client.h:310
query_fields_cursor.h
ignite::thin::cache::query::continuous::ContinuousQueryClient
Continuous query client.
Definition: continuous_query_client.h:54
ignite::thin::cache::CacheClient::RemoveAll
void RemoveAll(InIter begin, InIter end)
Removes given key mappings from cache.
Definition: cache_client.h:353
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:512
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:264
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:293
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:80
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:584
ignite::thin::cache::CacheClient::RemoveAll
void RemoveAll(const Set &keys)
Removes given key mappings from cache.
Definition: cache_client.h:340
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:250
ignite::thin::cache::CacheClient::QueryContinuous
query::continuous::ContinuousQueryHandleClient QueryContinuous(query::continuous::ContinuousQueryClient< K, V > continuousQuery)
Starts the continuous query execution.
Definition: cache_client.h:621
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:445
ignite::thin::cache::CacheClient::KeyType
K KeyType
Key type.
Definition: cache_client.h:70
ignite::thin::cache::CacheClient
Cache client class template.
Definition: cache_client.h:64
ignite::thin::cache::CacheClient::Query
query::QueryFieldsCursor Query(const query::SqlFieldsQuery &qry)
Perform SQL fields query.
Definition: cache_client.h:599
ignite::thin::cache::CacheClient::ValueType
V ValueType
Value type.
Definition: cache_client.h:73
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:235
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:529
ignite::thin::cache::CacheClient::Get
void Get(const KeyType &key, ValueType &value)
Get value from the cache.
Definition: cache_client.h:149
ignite::thin::cache::CacheClient::CacheClient
CacheClient()
Default constructor.
Definition: cache_client.h:89
ignite::thin::cache::CacheClient::Query
query::QueryCursor< KeyType, ValueType > Query(const query::ScanQuery &qry)
Perform scan query.
Definition: cache_client.h:610
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:427
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:411
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:108
ignite::thin::cache::query::ScanQuery
Scan query.
Definition: thin-client/include/ignite/thin/cache/query/query_scan.h:52
query_sql_fields.h
ignite::thin::cache::query::QueryCursor
Query cursor class template.
Definition: thin-client/include/ignite/thin/cache/query/query_cursor.h:57
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:183
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:201
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:218
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:376
ignite::thin::cache::CacheClient::PutAll
void PutAll(const Map &vals)
Stores given key-value pairs in cache.
Definition: cache_client.h:138
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:461
ignite::thin::cache::query::continuous::ContinuousQueryClient::GetJavaFilter
event::JavaCacheEntryEventFilter & GetJavaFilter()
Get remote Java filter reference.
Definition: continuous_query_client.h:231
ignite::thin::cache::CacheClient::Clear
void Clear()
Clear cache.
Definition: cache_client.h:386
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:494
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:556
ignite::impl::thin::ReadableImpl
Definition: thin-client/include/ignite/thin/cache/cache_entry.h:36
ignite::thin::cache::CacheClient::RefreshAffinityMapping
void RefreshAffinityMapping()
Refresh affinity mapping.
Definition: cache_client.h:642
ignite::thin::cache::CacheClient::ContainsKeys
bool ContainsKeys(InIter begin, InIter end)
Check if cache contains mapping for these keys.
Definition: cache_client.h:277
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:325
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:398
ignite::thin::cache::CacheClient::Get
ValueType Get(const KeyType &key)
Get value from cache.
Definition: cache_client.h:163
query_cursor.h