| Apache Ignite C++

thin-client/include/ignite/thin/cache/event/cache_entry_event.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_EVENT_CACHE_ENTRY_EVENT
24 #define _IGNITE_THIN_CACHE_EVENT_CACHE_ENTRY_EVENT
25
26 #include <ignite/binary/binary_raw_reader.h>
27 #include <ignite/thin/cache/cache_entry.h>
28
29 namespace ignite
30 {
31 namespace impl
32 {
33 namespace thin
34 {
35 namespace cache
36 {
37 namespace query
38 {
39 namespace continuous
40 {
41 template<typename K, typename V>
42 class ContinuousQueryClientHolder;
43 }
44 }
45 }
46 }
47 }
48 namespace thin
49 {
50 namespace cache
51 {
55 struct CacheEntryEventType
56 {
57 enum Type
58 {
60 CREATED = 0,
61
63 UPDATED = 1,
64
66 REMOVED = 2,
67
69 EXPIRED = 3
70 };
71
72 static Type FromInt8(int8_t val)
73 {
74 switch (val)
75 {
76 case CREATED:
77 case UPDATED:
78 case REMOVED:
79 case EXPIRED:
80 return static_cast<Type>(val);
81
82 default:
83 {
84 IGNITE_ERROR_FORMATTED_1(IgniteError::IGNITE_ERR_BINARY,
85 "Unsupported CacheEntryEventType", "val", val);
86 }
87 }
88 }
89 };
90
97 template<typename K, typename V>
98 class CacheEntryEvent : public CacheEntry<K, V>
99 {
100 friend class ignite::impl::thin::cache::query::continuous::ContinuousQueryClientHolder<K, V>;
101
102 public:
108 CacheEntryEvent() :
109 CacheEntry<K, V>(),
110 oldVal(),
111 hasOldValue(false),
112 eventType(CacheEntryEventType::CREATED)
113 {
114 // No-op.
115 }
116
122 CacheEntryEvent(const CacheEntryEvent<K, V>& other) :
123 CacheEntry<K, V>(other),
124 oldVal(other.oldVal),
125 hasOldValue(other.hasOldValue),
126 eventType(other.eventType)
127 {
128 // No-op.
129 }
130
134 virtual ~CacheEntryEvent()
135 {
136 // No-op.
137 }
138
145 CacheEntryEvent& operator=(const CacheEntryEvent<K, V>& other)
146 {
147 if (this != &other)
148 {
149 CacheEntry<K, V>::operator=(other);
150
151 oldVal = other.oldVal;
152 hasOldValue = other.hasOldValue;
153 eventType = other.eventType;
154 }
155
156 return *this;
157 }
158
166 CacheEntryEventType::Type GetEventType() const
167 {
168 return eventType;
169 };
170
176 const V& GetOldValue() const
177 {
178 return oldVal;
179 }
180
186 bool HasOldValue() const
187 {
188 return hasOldValue;
189 }
190
191 private:
197 void Read(binary::BinaryRawReader& reader)
198 {
199 this->key = reader.ReadObject<K>();
200
201 this->hasOldValue = reader.TryReadObject(this->oldVal);
202 this->hasValue = reader.TryReadObject(this->val);
203
204 int8_t eventTypeByte = reader.ReadInt8();
205 this->eventType = CacheEntryEventType::FromInt8(eventTypeByte);
206
207 if ((eventType == CacheEntryEventType::EXPIRED || eventType == CacheEntryEventType::REMOVED) && hasOldValue) {
208 this->hasValue = true;
209 this->val = oldVal;
210 }
211 }
212
214 V oldVal;
215
217 bool hasOldValue;
218
220 CacheEntryEventType::Type eventType;
221 };
222 }
223 }
224 }
225
226 #endif //_IGNITE_THIN_CACHE_EVENT_CACHE_ENTRY_EVENT
ignite::thin::cache::CacheEntryEvent
Cache entry event class template.
Definition: thin-client/include/ignite/thin/cache/event/cache_entry_event.h:98
ignite::thin::cache::CacheEntryEventType::CREATED
@ CREATED
An event type indicating that the cache entry was created.
Definition: thin-client/include/ignite/thin/cache/event/cache_entry_event.h:60
ignite::binary::BinaryRawReader
Binary raw reader.
Definition: binary_raw_reader.h:57
ignite
Apache Ignite API.
Definition: cache.h:48
ignite::thin::cache::CacheEntry::operator=
CacheEntry & operator=(const CacheEntry &other)
Assignment operator.
Definition: thin-client/include/ignite/thin/cache/cache_entry.h:121
ignite::thin::cache::CacheEntry
Cache entry class template.
Definition: thin-client/include/ignite/thin/cache/cache_entry.h:50
ignite::thin::cache::CacheEntry::hasValue
bool hasValue
Indicates whether value exists.
Definition: thin-client/include/ignite/thin/cache/cache_entry.h:171
ignite::thin::cache::CacheEntryEventType::EXPIRED
@ EXPIRED
An event type indicating that the cache entry was removed by expiration policy.
Definition: thin-client/include/ignite/thin/cache/event/cache_entry_event.h:69
ignite::thin::cache::CacheEntryEventType::REMOVED
@ REMOVED
An event type indicating that the cache entry was removed.
Definition: thin-client/include/ignite/thin/cache/event/cache_entry_event.h:66
ignite::impl::thin::cache::query::continuous::ContinuousQueryClientHolder
Definition: thin-client/include/ignite/thin/cache/event/cache_entry_event.h:42
ignite::thin::cache::CacheEntryEventType::UPDATED
@ UPDATED
An event type indicating that the cache entry was updated.
Definition: thin-client/include/ignite/thin/cache/event/cache_entry_event.h:63
ignite::thin::cache::CacheEntryEvent::~CacheEntryEvent
virtual ~CacheEntryEvent()
Destructor.
Definition: thin-client/include/ignite/thin/cache/event/cache_entry_event.h:134
ignite::thin::cache::CacheEntryEvent::CacheEntryEvent
CacheEntryEvent(const CacheEntryEvent< K, V > &other)
Copy constructor.
Definition: thin-client/include/ignite/thin/cache/event/cache_entry_event.h:122
ignite::binary::BinaryRawReader::TryReadObject
bool TryReadObject(T &res)
Try read object.
Definition: binary_raw_reader.h:486
ignite::thin::cache::CacheEntry::key
K key
Key.
Definition: thin-client/include/ignite/thin/cache/cache_entry.h:165
ignite::thin::cache::CacheEntry::val
V val
Value.
Definition: thin-client/include/ignite/thin/cache/cache_entry.h:168
ignite::binary::BinaryRawReader::ReadObject
T ReadObject()
Read object.
Definition: binary_raw_reader.h:458
binary_raw_reader.h
ignite::thin::cache::CacheEntryEventType::Type
Type
Definition: thin-client/include/ignite/thin/cache/event/cache_entry_event.h:57
ignite::thin::cache::CacheEntryEvent::CacheEntryEvent
CacheEntryEvent()
Default constructor.
Definition: thin-client/include/ignite/thin/cache/event/cache_entry_event.h:108
ignite::thin::cache::CacheEntryEventType
Cache event type.
Definition: thin-client/include/ignite/thin/cache/event/cache_entry_event.h:55
ignite::thin::cache::CacheEntryEvent::GetOldValue
const V & GetOldValue() const
Get old value.
Definition: thin-client/include/ignite/thin/cache/event/cache_entry_event.h:176
ignite::thin::cache::CacheEntryEvent::HasOldValue
bool HasOldValue() const
Check if the old value exists.
Definition: thin-client/include/ignite/thin/cache/event/cache_entry_event.h:186
ignite::binary::BinaryRawReader::ReadInt8
int8_t ReadInt8()
Read 8-byte signed integer.
Definition: binary_raw_reader.cpp:32
ignite::IgniteError::IGNITE_ERR_BINARY
static const int IGNITE_ERR_BINARY
Binary error.
Definition: ignite_error.h:125
ignite::thin::cache::CacheEntryEvent::GetEventType
CacheEntryEventType::Type GetEventType() const
Get event type.
Definition: thin-client/include/ignite/thin/cache/event/cache_entry_event.h:166
ignite::thin::cache::CacheEntryEvent::operator=
CacheEntryEvent & operator=(const CacheEntryEvent< K, V > &other)
Assignment operator.
Definition: thin-client/include/ignite/thin/cache/event/cache_entry_event.h:145
cache_entry.h