| Apache Ignite C++

core/include/ignite/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_CACHE_EVENT_CACHE_ENTRY_EVENT
24 #define _IGNITE_CACHE_EVENT_CACHE_ENTRY_EVENT
25
26 #include <ignite/binary/binary_raw_reader.h>
27 #include <ignite/cache/cache_entry.h>
28
29 namespace ignite
30 {
31 namespace cache
32 {
36 struct CacheEntryEventType
37 {
38 enum T
39 {
41 CREATE = 0,
42
44 UPDATE = 1,
45
47 REMOVE = 2,
48
50 EXPIRE = 3
51 };
52
53 static T FromInt8(int8_t val)
54 {
55 switch (val)
56 {
57 case CREATE:
58 case UPDATE:
59 case REMOVE:
60 case EXPIRE:
61 return static_cast<T>(val);
62
63 default:
64 {
65 IGNITE_ERROR_FORMATTED_1(IgniteError::IGNITE_ERR_BINARY,
66 "Unsupported CacheEntryEventType", "val", val);
67 }
68 }
69 }
70 };
71
78 template<typename K, typename V>
79 class CacheEntryEvent : public CacheEntry<K, V>
80 {
81 public:
87 CacheEntryEvent() :
88 CacheEntry<K, V>(),
89 oldVal(),
90 hasOldValue(false),
91 eventType(CacheEntryEventType::CREATE)
92 {
93 // No-op.
94 }
95
101 CacheEntryEvent(const CacheEntryEvent<K, V>& other) :
102 CacheEntry<K, V>(other),
103 oldVal(other.oldVal),
104 hasOldValue(other.hasOldValue),
105 eventType(other.eventType)
106 {
107 // No-op.
108 }
109
113 virtual ~CacheEntryEvent()
114 {
115 // No-op.
116 }
117
124 CacheEntryEvent& operator=(const CacheEntryEvent<K, V>& other)
125 {
126 if (this != &other)
127 {
128 CacheEntry<K, V>::operator=(other);
129
130 oldVal = other.oldVal;
131 hasOldValue = other.hasOldValue;
132 eventType = other.eventType;
133 }
134
135 return *this;
136 }
137
143 const V& GetOldValue() const
144 {
145 return oldVal;
146 }
147
153 bool HasOldValue() const
154 {
155 return hasOldValue;
156 }
157
165 CacheEntryEventType::T GetEventType() const
166 {
167 return eventType;
168 }
169
175 void Read(binary::BinaryRawReader& reader)
176 {
177 this->key = reader.ReadObject<K>();
178
179 this->hasOldValue = reader.TryReadObject(this->oldVal);
180 this->hasValue = reader.TryReadObject(this->val);
181
182 int8_t eventTypeByte = reader.ReadInt8();
183 this->eventType = CacheEntryEventType::FromInt8(eventTypeByte);
184 }
185
186 private:
188 V oldVal;
189
191 bool hasOldValue;
192
194 CacheEntryEventType::T eventType;
195 };
196 }
197 }
198
199 #endif //_IGNITE_CACHE_EVENT_CACHE_ENTRY_EVENT
ignite::cache::CacheEntryEventType::REMOVE
@ REMOVE
An event type indicating that the cache entry was removed.
Definition: core/include/ignite/cache/event/cache_entry_event.h:47
ignite::binary::BinaryRawReader
Binary raw reader.
Definition: binary_raw_reader.h:57
ignite
Apache Ignite API.
Definition: cache.h:48
ignite::cache::CacheEntryEventType::CREATE
@ CREATE
An event type indicating that the cache entry was created.
Definition: core/include/ignite/cache/event/cache_entry_event.h:41
ignite::cache::CacheEntryEventType
Cache entry event type.
Definition: core/include/ignite/cache/event/cache_entry_event.h:36
ignite::cache::CacheEntryEvent::operator=
CacheEntryEvent & operator=(const CacheEntryEvent< K, V > &other)
Assignment operator.
Definition: core/include/ignite/cache/event/cache_entry_event.h:124
ignite::cache::CacheEntryEvent::GetEventType
CacheEntryEventType::T GetEventType() const
Get event type.
Definition: core/include/ignite/cache/event/cache_entry_event.h:165
ignite::cache::CacheEntry
Cache entry class template.
Definition: core/include/ignite/cache/cache_entry.h:40
ignite::cache::CacheEntry::key
K key
Key.
Definition: core/include/ignite/cache/cache_entry.h:154
ignite::cache::CacheEntryEventType::EXPIRE
@ EXPIRE
An event type indicating that the cache entry was removed by expiration policy.
Definition: core/include/ignite/cache/event/cache_entry_event.h:50
ignite::binary::BinaryRawReader::TryReadObject
bool TryReadObject(T &res)
Try read object.
Definition: binary_raw_reader.h:486
ignite::binary::BinaryRawReader::ReadObject
T ReadObject()
Read object.
Definition: binary_raw_reader.h:458
binary_raw_reader.h
ignite::cache::CacheEntryEvent
Cache entry event class template.
Definition: core/include/ignite/cache/event/cache_entry_event.h:79
ignite::cache::CacheEntryEvent::CacheEntryEvent
CacheEntryEvent()
Default constructor.
Definition: core/include/ignite/cache/event/cache_entry_event.h:87
ignite::cache::CacheEntryEvent::GetOldValue
const V & GetOldValue() const
Get old value.
Definition: core/include/ignite/cache/event/cache_entry_event.h:143
ignite::cache::CacheEntry::operator=
CacheEntry & operator=(const CacheEntry &other)
Assignment operator.
Definition: core/include/ignite/cache/cache_entry.h:110
ignite::cache::CacheEntryEventType::T
T
Definition: core/include/ignite/cache/event/cache_entry_event.h:38
cache_entry.h
ignite::cache::CacheEntryEvent::CacheEntryEvent
CacheEntryEvent(const CacheEntryEvent< K, V > &other)
Copy constructor.
Definition: core/include/ignite/cache/event/cache_entry_event.h:101
ignite::cache::CacheEntry::val
V val
Value.
Definition: core/include/ignite/cache/cache_entry.h:157
ignite::cache::CacheEntryEvent::Read
void Read(binary::BinaryRawReader &reader)
Reads cache event using provided raw reader.
Definition: core/include/ignite/cache/event/cache_entry_event.h:175
ignite::cache::CacheEntry::hasValue
bool hasValue
Indicates whether value exists.
Definition: core/include/ignite/cache/cache_entry.h:160
ignite::cache::CacheEntryEvent::~CacheEntryEvent
virtual ~CacheEntryEvent()
Destructor.
Definition: core/include/ignite/cache/event/cache_entry_event.h:113
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::cache::CacheEntryEvent::HasOldValue
bool HasOldValue() const
Check if the old value exists.
Definition: core/include/ignite/cache/event/cache_entry_event.h:153
ignite::cache::CacheEntryEventType::UPDATE
@ UPDATE
An event type indicating that the cache entry was updated.
Definition: core/include/ignite/cache/event/cache_entry_event.h:44