Hazelcast C++ Client
EntryEvent.h
1 /*
2  * Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (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  * http://www.apache.org/licenses/LICENSE-2.0
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 //
17 // Created by ihsan demir on 9/9/15.
18 // Copyright (c) 2015 hazelcast. All rights reserved.
19 
20 #ifndef HAZELCAST_ENTRY_EVENT
21 #define HAZELCAST_ENTRY_EVENT
22 
23 #include <memory>
24 #include "hazelcast/client/Member.h"
25 #include "hazelcast/client/TypedData.h"
26 
27 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
28 #pragma warning(push)
29 #pragma warning(disable: 4251) //for dll export
30 #endif
31 
32 namespace hazelcast {
33  namespace client {
37  class HAZELCAST_API EntryEventType {
38  public:
42  enum Type {
43  UNDEFINED = 0 ,
44  ADDED = 1,
45  REMOVED = 1 << 1,
46  UPDATED = 1 << 2,
47  EVICTED = 1 << 3 ,
48  EVICT_ALL = 1 << 4 ,
49  CLEAR_ALL = 1 << 5 ,
50  MERGED = 1 << 6 ,
51  EXPIRED = 1 << 7,
52  INVALIDATION = 1 << 8,
53  ALL = 0xFF
54  };
59 
64 
68  EntryEventType(Type value);
69 
73  operator int() const;
74 
78  void operator = (int i);
79  };
80 
89  template <typename K, typename V>
90  class EntryEvent {
91  public:
95  EntryEvent(const std::string &name, const Member &member, EntryEventType eventType,
96  std::auto_ptr<K> key, std::auto_ptr<V> value)
97  : name(name)
98  , member(member)
99  , eventType(eventType)
100  , key(key)
101  , value(value) {
102  }
103 
107  EntryEvent(const std::string &name, const Member &member, EntryEventType eventType,
108  std::auto_ptr<K> key, std::auto_ptr<V> value,
109  std::auto_ptr<V> oldValue, std::auto_ptr<V> mergingValue)
110  : name(name)
111  , member(member)
112  , eventType(eventType)
113  , key(key)
114  , value(value)
115  , oldValue(oldValue)
116  , mergingValue(mergingValue) {
117  }
118 
119  EntryEvent(const std::string &name, const Member &member, EntryEventType eventType)
120  : name(name)
121  , member(member)
122  , eventType(eventType) {
123  }
124 
125  virtual ~EntryEvent() {}
126 
133  virtual const K *getKeyObject() const {
134  return key.get();
135  }
136 
144  std::auto_ptr<K> releaseKey() {
145  return key;
146  }
147 
156  const K &getKey() const {
157  return *getKeyObject();
158  }
159 
165  virtual const V *getOldValueObject() const {
166  return oldValue.get();
167  }
168 
177  std::auto_ptr<V> releaseOldValue() {
178  return oldValue;
179  }
180 
189  const V &getOldValue() const {
190  return *getOldValueObject();
191  }
192 
198  virtual const V *getValueObject() const {
199  return value.get();
200  }
201 
210  std::auto_ptr<V> releaseValue() {
211  return value;
212  }
213 
222  const V &getValue() const {
223  return *getValueObject();
224  }
225 
231  virtual const V *getMergingValueObject() const {
232  return mergingValue.get();
233  }
234 
243  std::auto_ptr<V> releaseMergingValue() const {
244  return mergingValue;
245  }
246 
255  const V &getMergingValue() const {
256  return *getMergingValueObject();
257  }
258 
264  const Member &getMember() const {
265  return member;
266  };
267 
274  return eventType;
275  };
276 
282  const std::string &getName() const {
283  return name;
284  };
285 
286  std::ostream &operator<< (std::ostream &out) const {
287  out << "EntryEvent{entryEventType=" << eventType <<
288  ", member=" << member << ", name='" << name << "', key=" << *key;
289  if (value.get()) {
290  out << ", value=" << *value;
291  }
292  if (oldValue.get()) {
293  out << ", oldValue=" << *oldValue;
294  }
295  if (mergingValue.get()) {
296  out << ", mergingValue=" << *mergingValue;
297  }
298  return out;
299  }
300  protected:
301  std::string name;
302  Member member;
303  EntryEventType eventType;
304  std::auto_ptr<K> key;
305  std::auto_ptr<V> value;
306  std::auto_ptr<V> oldValue;
307  std::auto_ptr<V> mergingValue;
308 
309  };
310 
311  namespace mixedtype {
312  class HAZELCAST_API MixedEntryEvent {
313  public:
317  MixedEntryEvent(const std::string &name, const Member &member, EntryEventType eventType,
318  TypedData key, TypedData value)
319  : name(name)
320  , member(member)
321  , eventType(eventType)
322  , key(key)
323  , value(value) {
324  }
325 
329  MixedEntryEvent(const std::string &name, const Member &member, EntryEventType eventType,
330  TypedData key, TypedData value,
331  TypedData oldValue, TypedData mergingValue)
332  : name(name)
333  , member(member)
334  , eventType(eventType)
335  , key(key)
336  , value(value)
337  , oldValue(new TypedData(oldValue))
338  , mergingValue(new TypedData(mergingValue)) {
339  }
340 
347  const TypedData &getKey() const {
348  return key;
349  }
350 
357  const TypedData *getOldValue() const {
358  return oldValue.get();
359  }
360 
367  const TypedData &getValue() const {
368  return value;
369  }
370 
376  const TypedData *getMergingValue() const {
377  return mergingValue.get();
378  }
379 
385  const Member &getMember() const {
386  return member;
387  };
388 
395  return eventType;
396  };
397 
403  const std::string &getName() const {
404  return name;
405  };
406 
407  std::ostream &operator<< (std::ostream &out) const {
408  out << "EntryEvent{entryEventType=" << eventType.value << eventType <<
409  ", member=" << member << ", name='" << name;
410  return out;
411  }
412  private:
413  std::string name;
414  Member member;
415  EntryEventType eventType;
416  TypedData key;
417  TypedData value;
418  std::auto_ptr<TypedData> oldValue;
419  std::auto_ptr<TypedData> mergingValue;
420  };
421  }
422  }
423 }
424 
425 
426 template <typename K, typename V>
427 std::ostream &operator<<(std::ostream &out, const hazelcast::client::EntryEvent<K, V> &event) {
428  event.operator<<(out);
429  return out;
430 }
431 
432 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
433 #pragma warning(pop)
434 #endif
435 
436 #endif //__EntryEvent_H_
437 
EntryEventType getEventType() const
Return the event type.
Definition: EntryEvent.h:394
MixedEntryEvent(const std::string &name, const Member &member, EntryEventType eventType, TypedData key, TypedData value, TypedData oldValue, TypedData mergingValue)
Constructor.
Definition: EntryEvent.h:329
const Member & getMember() const
Returns the member fired this event.
Definition: EntryEvent.h:385
std::auto_ptr< V > releaseOldValue()
Releases the old value of the entry event.
Definition: EntryEvent.h:177
const V & getValue() const
Definition: EntryEvent.h:222
virtual const K * getKeyObject() const
Returns the key of the entry event.
Definition: EntryEvent.h:133
std::auto_ptr< V > releaseMergingValue() const
Releases the mergingValue of the entry event.
Definition: EntryEvent.h:243
const V & getMergingValue() const
Definition: EntryEvent.h:255
const std::string & getName() const
Returns the name of the map for this event.
Definition: EntryEvent.h:403
const TypedData & getKey() const
Returns the key of the entry event.
Definition: EntryEvent.h:347
std::auto_ptr< K > releaseKey()
Releases the key of the entry event.
Definition: EntryEvent.h:144
Type
Type enum.
Definition: EntryEvent.h:42
const TypedData * getMergingValue() const
Returns the incoming merging value of the entry event.
Definition: EntryEvent.h:376
const V & getOldValue() const
Definition: EntryEvent.h:189
EntryEvent(const std::string &name, const Member &member, EntryEventType eventType, std::auto_ptr< K > key, std::auto_ptr< V > value, std::auto_ptr< V > oldValue, std::auto_ptr< V > mergingValue)
Constructor.
Definition: EntryEvent.h:107
const std::string & getName() const
Returns the name of the map for this event.
Definition: EntryEvent.h:282
const TypedData & getValue() const
Returns the value of the entry event.
Definition: EntryEvent.h:367
Definition: EntryEvent.h:312
const Member & getMember() const
Returns the member fired this event.
Definition: EntryEvent.h:264
EntryEvent(const std::string &name, const Member &member, EntryEventType eventType, std::auto_ptr< K > key, std::auto_ptr< V > value)
Constructor.
Definition: EntryEvent.h:95
const TypedData * getOldValue() const
Returns the old value of the entry event.
Definition: EntryEvent.h:357
Cluster member class.
Definition: Member.h:43
MixedEntryEvent(const std::string &name, const Member &member, EntryEventType eventType, TypedData key, TypedData value)
Constructor.
Definition: EntryEvent.h:317
virtual const V * getMergingValueObject() const
Returns the incoming merging value of the entry event.
Definition: EntryEvent.h:231
Map Entry event.
Definition: EntryEvent.h:90
PN (Positive-Negative) CRDT counter.
Definition: MapEntryView.h:32
Type value
Type value.
Definition: EntryEvent.h:58
virtual const V * getValueObject() const
Returns the value of the entry event.
Definition: EntryEvent.h:198
Type of entry event.
Definition: EntryEvent.h:37
std::auto_ptr< V > releaseValue()
Releases the value of the entry event.
Definition: EntryEvent.h:210
EntryEventType getEventType() const
Return the event type.
Definition: EntryEvent.h:273
TypedData class is a wrapper class for the serialized binary data.
Definition: TypedData.h:40
const K & getKey() const
Definition: EntryEvent.h:156
std::auto_ptr< T > get() const
Deserializes the underlying binary data and produces the object of type T.
Definition: TypedData.h:68
virtual const V * getOldValueObject() const
Returns the old value of the entry event.
Definition: EntryEvent.h:165