Hazelcast C++ Client
 All Classes Functions Variables Enumerations Pages
EntryEvent.h
1 /*
2  * Copyright (c) 2008-2015, 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  ALL = 0xFF
52  };
57 
62 
66  EntryEventType(Type value);
67 
71  operator int() const;
72 
76  void operator = (int i);
77  };
78 
87  template <typename K, typename V>
88  class EntryEvent {
89  public:
93  EntryEvent(const std::string &name, const Member &member, EntryEventType eventType,
94  std::auto_ptr<K> key, std::auto_ptr<V> value)
95  : name(name)
96  , member(member)
97  , eventType(eventType)
98  , key(key)
99  , value(value) {
100  }
101 
105  EntryEvent(const std::string &name, const Member &member, EntryEventType eventType,
106  std::auto_ptr<K> key, std::auto_ptr<V> value,
107  std::auto_ptr<V> oldValue, std::auto_ptr<V> mergingValue)
108  : name(name)
109  , member(member)
110  , eventType(eventType)
111  , key(key)
112  , value(value)
113  , oldValue(oldValue)
114  , mergingValue(mergingValue) {
115  }
116 
123  const K *getKeyObject() const {
124  return key.get();
125  }
126 
134  std::auto_ptr<K> releaseKey() {
135  return key;
136  }
137 
146  const K &getKey() const {
147  return *key;
148  }
149 
155  const V *getOldValueObject() const {
156  return oldValue.get();
157  }
158 
167  std::auto_ptr<V> releaseOldValue() {
168  return oldValue;
169  }
170 
179  const V &getOldValue() const {
180  return *oldValue;
181  }
182 
188  const V *getValueObject() const {
189  return value.get();
190  }
191 
200  std::auto_ptr<V> releaseValue() {
201  return value;
202  }
203 
212  const V &getValue() const {
213  return *value;
214  }
215 
221  const V *getMergingValueObject() const {
222  return mergingValue.get();
223  }
224 
233  std::auto_ptr<V> releaseMergingValue() const {
234  return mergingValue;
235  }
236 
245  const V &getMergingValue() const {
246  return *mergingValue;
247  }
248 
254  const Member &getMember() const {
255  return member;
256  };
257 
264  return eventType;
265  };
266 
272  std::string &getName() const {
273  return name;
274  };
275 
276  std::ostream &operator<< (std::ostream &out) const {
277  out << "EntryEvent{entryEventType=" << eventType.value << eventType <<
278  ", member=" << member << ", name='" << name << "', key=" << *key;
279  if (value.get()) {
280  out << ", value=" << *value;
281  }
282  if (oldValue.get()) {
283  out << ", oldValue=" << *oldValue;
284  }
285  if (mergingValue.get()) {
286  out << ", mergingValue=" << *mergingValue;
287  }
288  return out;
289  }
290  private:
291  std::string name;
292  Member member;
293  EntryEventType eventType;
294  std::auto_ptr<K> key;
295  std::auto_ptr<V> value;
296  std::auto_ptr<V> oldValue;
297  std::auto_ptr<V> mergingValue;
298 
299  };
300  }
301 }
302 
303 
304 template <typename K, typename V>
305 std::ostream &operator<<(std::ostream &out, const hazelcast::client::EntryEvent<K, V> &event) {
306  event.operator<<(out);
307  return out;
308 }
309 
310 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
311 #pragma warning(pop)
312 #endif
313 
314 #endif //__EntryEvent_H_
315 
const V * getOldValueObject() const
Returns the old value of the entry event.
Definition: EntryEvent.h:155
const Member & getMember() const
Returns the member fired this event.
Definition: EntryEvent.h:254
const V * getValueObject() const
Returns the value of the entry event.
Definition: EntryEvent.h:188
const K & getKey() const
Definition: EntryEvent.h:146
std::auto_ptr< V > releaseOldValue()
Releases the old value of the entry event.
Definition: EntryEvent.h:167
const K * getKeyObject() const
Returns the key of the entry event.
Definition: EntryEvent.h:123
const V & getMergingValue() const
Definition: EntryEvent.h:245
const V & getOldValue() const
Definition: EntryEvent.h:179
std::auto_ptr< K > releaseKey()
Releases the key of the entry event.
Definition: EntryEvent.h:134
Type
Type enum.
Definition: EntryEvent.h:41
std::string & getName() const
Returns the name of the map for this event.
Definition: EntryEvent.h:272
const V * getMergingValueObject() const
Returns the incoming merging value of the entry event.
Definition: EntryEvent.h:221
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:105
EntryEventType getEventType() const
Return the event type.
Definition: EntryEvent.h:263
EntryEvent(const std::string &name, const Member &member, EntryEventType eventType, std::auto_ptr< K > key, std::auto_ptr< V > value)
Constructor.
Definition: EntryEvent.h:93
Cluster member class.
Definition: Member.h:44
std::auto_ptr< V > releaseMergingValue() const
Releases the mergingValue of the entry event.
Definition: EntryEvent.h:233
Map Entry event.
Definition: EntryEvent.h:88
Type value
Type value.
Definition: EntryEvent.h:56
Type of entry event.
Definition: EntryEvent.h:36
const V & getValue() const
Definition: EntryEvent.h:212
std::auto_ptr< V > releaseValue()
Releases the value of the entry event.
Definition: EntryEvent.h:200