GridGain C++
core/include/ignite/cache/event/cache_entry_event.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 GridGain Systems, Inc. and Contributors.
3  *
4  * Licensed under the GridGain Community Edition License (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
22 #ifndef _IGNITE_CACHE_EVENT_CACHE_ENTRY_EVENT
23 #define _IGNITE_CACHE_EVENT_CACHE_ENTRY_EVENT
24 
27 
28 namespace ignite
29 {
30  namespace cache
31  {
36  {
37  enum T
38  {
40  CREATE = 0,
41 
43  UPDATE = 1,
44 
46  REMOVE = 2,
47  };
48 
49  static T FromInt8(int8_t val)
50  {
51  switch (val)
52  {
53  case CREATE:
54  case UPDATE:
55  case REMOVE:
56  return static_cast<T>(val);
57 
58  default:
59  {
60  IGNITE_ERROR_FORMATTED_1(IgniteError::IGNITE_ERR_BINARY,
61  "Unsupported CacheEntryEventType", "val", val);
62  }
63  }
64  }
65  };
66 
73  template<typename K, typename V>
74  class CacheEntryEvent : public CacheEntry<K, V>
75  {
76  public:
83  CacheEntry<K, V>(),
84  oldVal(),
85  hasOldValue(false),
86  eventType(CacheEntryEventType::CREATE)
87  {
88  // No-op.
89  }
90 
97  CacheEntry<K, V>(other),
98  oldVal(other.oldVal),
99  hasOldValue(other.hasOldValue),
100  eventType(other.eventType)
101  {
102  // No-op.
103  }
104 
109  {
110  // No-op.
111  }
112 
120  {
121  if (this != &other)
122  {
124 
125  oldVal = other.oldVal;
126  hasOldValue = other.hasOldValue;
127  eventType = other.eventType;
128  }
129 
130  return *this;
131  }
132 
138  const V& GetOldValue() const
139  {
140  return oldVal;
141  }
142 
148  bool HasOldValue() const
149  {
150  return hasOldValue;
151  }
152 
161  {
162  return eventType;
163  }
164 
171  {
172  this->key = reader.ReadObject<K>();
173 
174  this->hasOldValue = reader.TryReadObject(this->oldVal);
175  this->hasValue = reader.TryReadObject(this->val);
176 
177  int8_t eventTypeByte = reader.ReadInt8();
178  this->eventType = CacheEntryEventType::FromInt8(eventTypeByte);
179  }
180 
181  private:
183  V oldVal;
184 
186  bool hasOldValue;
187 
189  CacheEntryEventType::T eventType;
190  };
191  }
192 }
193 
194 #endif //_IGNITE_CACHE_EVENT_CACHE_ENTRY_EVENT
ignite::cache::CacheEntryEventType::REMOVE
@ REMOVE
Event type - Remove.
Definition: core/include/ignite/cache/event/cache_entry_event.h:46
ignite::binary::BinaryRawReader
Binary raw reader.
Definition: binary_raw_reader.h:56
ignite
Ignite API.
Definition: cache.h:47
ignite::cache::CacheEntryEventType::CREATE
@ CREATE
Event type - Create.
Definition: core/include/ignite/cache/event/cache_entry_event.h:40
ignite::cache::CacheEntryEventType
Cache entry event type.
Definition: core/include/ignite/cache/event/cache_entry_event.h:35
ignite::cache::CacheEntryEvent::operator=
CacheEntryEvent & operator=(const CacheEntryEvent< K, V > &other)
Assignment operator.
Definition: core/include/ignite/cache/event/cache_entry_event.h:119
ignite::cache::CacheEntryEvent::GetEventType
CacheEntryEventType::T GetEventType() const
Get event type.
Definition: core/include/ignite/cache/event/cache_entry_event.h:160
ignite::cache::CacheEntry
Cache entry class template.
Definition: core/include/ignite/cache/cache_entry.h:39
ignite::cache::CacheEntry::key
K key
Key.
Definition: core/include/ignite/cache/cache_entry.h:153
ignite::binary::BinaryRawReader::TryReadObject
bool TryReadObject(T &res)
Try read object.
Definition: binary_raw_reader.h:492
ignite::binary::BinaryRawReader::ReadObject
T ReadObject()
Read object.
Definition: binary_raw_reader.h:464
binary_raw_reader.h
ignite::cache::CacheEntryEvent
Cache entry event class template.
Definition: core/include/ignite/cache/event/cache_entry_event.h:74
ignite::cache::CacheEntryEvent::CacheEntryEvent
CacheEntryEvent()
Default constructor.
Definition: core/include/ignite/cache/event/cache_entry_event.h:82
ignite::cache::CacheEntryEvent::GetOldValue
const V & GetOldValue() const
Get old value.
Definition: core/include/ignite/cache/event/cache_entry_event.h:138
ignite::cache::CacheEntry::operator=
CacheEntry & operator=(const CacheEntry &other)
Assignment operator.
Definition: core/include/ignite/cache/cache_entry.h:109
ignite::cache::CacheEntryEventType::T
T
Definition: core/include/ignite/cache/event/cache_entry_event.h:37
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:96
ignite::cache::CacheEntry::val
V val
Value.
Definition: core/include/ignite/cache/cache_entry.h:156
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:170
ignite::cache::CacheEntry::hasValue
bool hasValue
Indicates whether value exists.
Definition: core/include/ignite/cache/cache_entry.h:159
ignite::cache::CacheEntryEvent::~CacheEntryEvent
virtual ~CacheEntryEvent()
Destructor.
Definition: core/include/ignite/cache/event/cache_entry_event.h:108
ignite::binary::BinaryRawReader::ReadInt8
int8_t ReadInt8()
Read 8-byte signed integer.
Definition: binary_raw_reader.cpp:36
ignite::IgniteError::IGNITE_ERR_BINARY
static const int IGNITE_ERR_BINARY
Binary error.
Definition: ignite_error.h:124
ignite::cache::CacheEntryEvent::HasOldValue
bool HasOldValue() const
Check if the old value exists.
Definition: core/include/ignite/cache/event/cache_entry_event.h:148
ignite::cache::CacheEntryEventType::UPDATE
@ UPDATE
Event type - Update.
Definition: core/include/ignite/cache/event/cache_entry_event.h:43