Hazelcast C++ Client
 All Classes Functions Variables Enumerations Enumerator Pages
EntryEvent.h
1 /*
2  * Copyright (c) 2008-2017, 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 
26 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
27 #pragma warning(push)
28 #pragma warning(disable: 4251) //for dll export
29 #endif
30 
31 namespace hazelcast {
32  namespace client {
36  class HAZELCAST_API EntryEventType {
37  public:
41  enum Type {
42  UNDEFINED = 0 ,
43  ADDED = 1,
44  REMOVED = 1 << 1,
45  UPDATED = 1 << 2,
46  EVICTED = 1 << 3 ,
47  EVICT_ALL = 1 << 4 ,
48  CLEAR_ALL = 1 << 5 ,
49  MERGED = 1 << 6 ,
50  EXPIRED = 1 << 7,
51  INVALIDATION = 1 << 8,
52  ALL = 0xFF
53  };
58 
63 
67  EntryEventType(Type value);
68 
72  operator int() const;
73 
77  void operator = (int i);
78  };
79 
88  template <typename K, typename V>
89  class EntryEvent {
90  public:
94  EntryEvent(const std::string &name, const Member &member, EntryEventType eventType,
95  std::auto_ptr<K> key, std::auto_ptr<V> value)
96  : name(name)
97  , member(member)
98  , eventType(eventType)
99  , key(key)
100  , value(value) {
101  }
102 
106  EntryEvent(const std::string &name, const Member &member, EntryEventType eventType,
107  std::auto_ptr<K> key, std::auto_ptr<V> value,
108  std::auto_ptr<V> oldValue, std::auto_ptr<V> mergingValue)
109  : name(name)
110  , member(member)
111  , eventType(eventType)
112  , key(key)
113  , value(value)
114  , oldValue(oldValue)
115  , mergingValue(mergingValue) {
116  }
117 
124  const K *getKeyObject() const {
125  return key.get();
126  }
127 
135  std::auto_ptr<K> releaseKey() {
136  return key;
137  }
138 
147  const K &getKey() const {
148  return *key;
149  }
150 
156  const V *getOldValueObject() const {
157  return oldValue.get();
158  }
159 
168  std::auto_ptr<V> releaseOldValue() {
169  return oldValue;
170  }
171 
180  const V &getOldValue() const {
181  return *oldValue;
182  }
183 
189  const V *getValueObject() const {
190  return value.get();
191  }
192 
201  std::auto_ptr<V> releaseValue() {
202  return value;
203  }
204 
213  const V &getValue() const {
214  return *value;
215  }
216 
222  const V *getMergingValueObject() const {
223  return mergingValue.get();
224  }
225 
234  std::auto_ptr<V> releaseMergingValue() const {
235  return mergingValue;
236  }
237 
246  const V &getMergingValue() const {
247  return *mergingValue;
248  }
249 
255  const Member &getMember() const {
256  return member;
257  };
258 
265  return eventType;
266  };
267 
273  std::string &getName() const {
274  return name;
275  };
276 
277  std::ostream &operator<< (std::ostream &out) const {
278  out << "EntryEvent{entryEventType=" << eventType.value << eventType <<
279  ", member=" << member << ", name='" << name << "', key=" << *key;
280  if (value.get()) {
281  out << ", value=" << *value;
282  }
283  if (oldValue.get()) {
284  out << ", oldValue=" << *oldValue;
285  }
286  if (mergingValue.get()) {
287  out << ", mergingValue=" << *mergingValue;
288  }
289  return out;
290  }
291  private:
292  std::string name;
293  Member member;
294  EntryEventType eventType;
295  std::auto_ptr<K> key;
296  std::auto_ptr<V> value;
297  std::auto_ptr<V> oldValue;
298  std::auto_ptr<V> mergingValue;
299 
300  };
301  }
302 }
303 
304 
305 template <typename K, typename V>
306 std::ostream &operator<<(std::ostream &out, const hazelcast::client::EntryEvent<K, V> &event) {
307  event.operator<<(out);
308  return out;
309 }
310 
311 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
312 #pragma warning(pop)
313 #endif
314 
315 #endif //__EntryEvent_H_
316 
const V * getOldValueObject() const
Returns the old value of the entry event.
Definition: EntryEvent.h:156
const Member & getMember() const
Returns the member fired this event.
Definition: EntryEvent.h:255
const V * getValueObject() const
Returns the value of the entry event.
Definition: EntryEvent.h:189
const K & getKey() const
Definition: EntryEvent.h:147
std::auto_ptr< V > releaseOldValue()
Releases the old value of the entry event.
Definition: EntryEvent.h:168
const K * getKeyObject() const
Returns the key of the entry event.
Definition: EntryEvent.h:124
const V & getMergingValue() const
Definition: EntryEvent.h:246
const V & getOldValue() const
Definition: EntryEvent.h:180
std::auto_ptr< K > releaseKey()
Releases the key of the entry event.
Definition: EntryEvent.h:135
Type
Type enum.
Definition: EntryEvent.h:41
std::string & getName() const
Returns the name of the map for this event.
Definition: EntryEvent.h:273
const V * getMergingValueObject() const
Returns the incoming merging value of the entry event.
Definition: EntryEvent.h:222
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:106
EntryEventType getEventType() const
Return the event type.
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:94
Cluster member class.
Definition: Member.h:44
std::auto_ptr< V > releaseMergingValue() const
Releases the mergingValue of the entry event.
Definition: EntryEvent.h:234
Map Entry event.
Definition: EntryEvent.h:89
Type value
Type value.
Definition: EntryEvent.h:57
Type of entry event.
Definition: EntryEvent.h:36
const V & getValue() const
Definition: EntryEvent.h:213
std::auto_ptr< V > releaseValue()
Releases the value of the entry event.
Definition: EntryEvent.h:201