Hazelcast C++ Client
EntryEvent.h
1 /*
2  * Copyright (c) 2008-2018, 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 
125  const K *getKeyObject() const {
126  return key.get();
127  }
128 
136  std::auto_ptr<K> releaseKey() {
137  return key;
138  }
139 
148  const K &getKey() const {
149  return *key;
150  }
151 
157  const V *getOldValueObject() const {
158  return oldValue.get();
159  }
160 
169  std::auto_ptr<V> releaseOldValue() {
170  return oldValue;
171  }
172 
181  const V &getOldValue() const {
182  return *oldValue;
183  }
184 
190  const V *getValueObject() const {
191  return value.get();
192  }
193 
202  std::auto_ptr<V> releaseValue() {
203  return value;
204  }
205 
214  const V &getValue() const {
215  return *value;
216  }
217 
223  const V *getMergingValueObject() const {
224  return mergingValue.get();
225  }
226 
235  std::auto_ptr<V> releaseMergingValue() const {
236  return mergingValue;
237  }
238 
247  const V &getMergingValue() const {
248  return *mergingValue;
249  }
250 
256  const Member &getMember() const {
257  return member;
258  };
259 
266  return eventType;
267  };
268 
274  const std::string &getName() const {
275  return name;
276  };
277 
278  std::ostream &operator<< (std::ostream &out) const {
279  out << "EntryEvent{entryEventType=" << eventType.value << eventType <<
280  ", member=" << member << ", name='" << name << "', key=" << *key;
281  if (value.get()) {
282  out << ", value=" << *value;
283  }
284  if (oldValue.get()) {
285  out << ", oldValue=" << *oldValue;
286  }
287  if (mergingValue.get()) {
288  out << ", mergingValue=" << *mergingValue;
289  }
290  return out;
291  }
292  private:
293  std::string name;
294  Member member;
295  EntryEventType eventType;
296  std::auto_ptr<K> key;
297  std::auto_ptr<V> value;
298  std::auto_ptr<V> oldValue;
299  std::auto_ptr<V> mergingValue;
300 
301  };
302 
303  namespace mixedtype {
304  class HAZELCAST_API MixedEntryEvent {
305  public:
309  MixedEntryEvent(const std::string &name, const Member &member, EntryEventType eventType,
310  TypedData key, TypedData value)
311  : name(name)
312  , member(member)
313  , eventType(eventType)
314  , key(key)
315  , value(value) {
316  }
317 
321  MixedEntryEvent(const std::string &name, const Member &member, EntryEventType eventType,
322  TypedData key, TypedData value,
323  TypedData oldValue, TypedData mergingValue)
324  : name(name)
325  , member(member)
326  , eventType(eventType)
327  , key(key)
328  , value(value)
329  , oldValue(new TypedData(oldValue))
330  , mergingValue(new TypedData(mergingValue)) {
331  }
332 
339  const TypedData &getKey() const {
340  return key;
341  }
342 
349  const TypedData *getOldValue() const {
350  return oldValue.get();
351  }
352 
359  const TypedData &getValue() const {
360  return value;
361  }
362 
368  const TypedData *getMergingValue() const {
369  return mergingValue.get();
370  }
371 
377  const Member &getMember() const {
378  return member;
379  };
380 
387  return eventType;
388  };
389 
395  const std::string &getName() const {
396  return name;
397  };
398 
399  std::ostream &operator<< (std::ostream &out) const {
400  out << "EntryEvent{entryEventType=" << eventType.value << eventType <<
401  ", member=" << member << ", name='" << name;
402  return out;
403  }
404  private:
405  std::string name;
406  Member member;
407  EntryEventType eventType;
408  TypedData key;
409  TypedData value;
410  std::auto_ptr<TypedData> oldValue;
411  std::auto_ptr<TypedData> mergingValue;
412  };
413  }
414  }
415 }
416 
417 
418 template <typename K, typename V>
419 std::ostream &operator<<(std::ostream &out, const hazelcast::client::EntryEvent<K, V> &event) {
420  event.operator<<(out);
421  return out;
422 }
423 
424 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
425 #pragma warning(pop)
426 #endif
427 
428 #endif //__EntryEvent_H_
429 
EntryEventType getEventType() const
Return the event type.
Definition: EntryEvent.h:386
MixedEntryEvent(const std::string &name, const Member &member, EntryEventType eventType, TypedData key, TypedData value, TypedData oldValue, TypedData mergingValue)
Constructor.
Definition: EntryEvent.h:321
const Member & getMember() const
Returns the member fired this event.
Definition: EntryEvent.h:377
std::auto_ptr< V > releaseOldValue()
Releases the old value of the entry event.
Definition: EntryEvent.h:169
const V & getValue() const
Definition: EntryEvent.h:214
std::auto_ptr< V > releaseMergingValue() const
Releases the mergingValue of the entry event.
Definition: EntryEvent.h:235
const V & getMergingValue() const
Definition: EntryEvent.h:247
const V * getOldValueObject() const
Returns the old value of the entry event.
Definition: EntryEvent.h:157
const std::string & getName() const
Returns the name of the map for this event.
Definition: EntryEvent.h:395
const TypedData & getKey() const
Returns the key of the entry event.
Definition: EntryEvent.h:339
std::auto_ptr< K > releaseKey()
Releases the key of the entry event.
Definition: EntryEvent.h:136
Type
Type enum.
Definition: EntryEvent.h:42
const TypedData * getMergingValue() const
Returns the incoming merging value of the entry event.
Definition: EntryEvent.h:368
const V & getOldValue() const
Definition: EntryEvent.h:181
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:274
const TypedData & getValue() const
Returns the value of the entry event.
Definition: EntryEvent.h:359
Definition: EntryEvent.h:304
const Member & getMember() const
Returns the member fired this event.
Definition: EntryEvent.h:256
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 V * getMergingValueObject() const
Returns the incoming merging value of the entry event.
Definition: EntryEvent.h:223
const TypedData * getOldValue() const
Returns the old value of the entry event.
Definition: EntryEvent.h:349
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:309
Map Entry event.
Definition: EntryEvent.h:90
Definition: MapEntryView.h:32
Type value
Type value.
Definition: EntryEvent.h:58
Type of entry event.
Definition: EntryEvent.h:37
const V * getValueObject() const
Returns the value of the entry event.
Definition: EntryEvent.h:190
std::auto_ptr< V > releaseValue()
Releases the value of the entry event.
Definition: EntryEvent.h:202
EntryEventType getEventType() const
Return the event type.
Definition: EntryEvent.h:265
const K * getKeyObject() const
Returns the key of the entry event.
Definition: EntryEvent.h:125
TypedData class is a wrapper class for the serialized binary data.
Definition: TypedData.h:40
const K & getKey() const
Definition: EntryEvent.h:148
std::auto_ptr< T > get() const
Deserializes the underlying binary data and produces the object of type T.
Definition: TypedData.h:68