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 "hazelcast/client/Member.h"
24 #include <boost/shared_ptr.hpp>
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  boost::shared_ptr<K> key, boost::shared_ptr<V> value)
95  : name(name)
96  , member(member)
97  , eventType(eventType)
98  , key(key)
99  , value(value) {
100 
101  };
102 
106  EntryEvent(const std::string &name, const Member &member, EntryEventType eventType,
107  boost::shared_ptr<K> key, boost::shared_ptr<V> value,
108  boost::shared_ptr<V> oldValue, boost::shared_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  };
118 
124  const K &getKey() const {
125  return *key;
126  };
127 
133  const V &getOldValue() const {
134  return *oldValue;
135  };
136 
142  const V &getValue() const {
143  return *value;
144  };
145 
151  const V &getMergingValue() const {
152  return *mergingValue;
153  };
154 
160  Member getMember() const {
161  return member;
162  };
163 
170  return eventType;
171  };
172 
178  std::string getName() const {
179  return name;
180  };
181 
182  std::ostream &operator<< (std::ostream &out) const {
183  out << "EntryEvent{entryEventType=" << eventType.value << eventType <<
184  ", member=" << member << ", name='" << name << "', key=" << *key;
185  if (value.get()) {
186  out << ", value=" << *value;
187  }
188  if (oldValue.get()) {
189  out << ", oldValue=" << *oldValue;
190  }
191  if (mergingValue.get()) {
192  out << ", mergingValue=" << *mergingValue;
193  }
194  return out;
195  }
196  private:
197  std::string name;
198  Member member;
199  EntryEventType eventType;
200  boost::shared_ptr<K> key;
201  boost::shared_ptr<V> value;
202  boost::shared_ptr<V> oldValue;
203  boost::shared_ptr<V> mergingValue;
204 
205  };
206  }
207 }
208 
209 template <typename K, typename V>
210 std::ostream &operator<<(std::ostream &out, const hazelcast::client::EntryEvent<K, V> &event) {
211  event.operator<<(out);
212  return out;
213 }
214 
215 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
216 #pragma warning(pop)
217 #endif
218 
219 #endif //__EntryEvent_H_
220 
EntryEvent(const std::string &name, const Member &member, EntryEventType eventType, boost::shared_ptr< K > key, boost::shared_ptr< V > value, boost::shared_ptr< V > oldValue, boost::shared_ptr< V > mergingValue)
Constructor.
Definition: EntryEvent.h:106
const K & getKey() const
Returns the key of the entry event.
Definition: EntryEvent.h:124
const V & getMergingValue() const
Returns the incoming merging value of the entry event.
Definition: EntryEvent.h:151
const V & getOldValue() const
Returns the old value of the entry event.
Definition: EntryEvent.h:133
Type
Type enum.
Definition: EntryEvent.h:41
EntryEventType getEventType() const
Return the event type.
Definition: EntryEvent.h:169
Member getMember() const
Returns the member fired this event.
Definition: EntryEvent.h:160
Cluster member class.
Definition: Member.h:44
Map Entry event.
Definition: EntryEvent.h:88
Type value
Type value.
Definition: EntryEvent.h:56
EntryEvent(const std::string &name, const Member &member, EntryEventType eventType, boost::shared_ptr< K > key, boost::shared_ptr< V > value)
Constructor.
Definition: EntryEvent.h:93
Type of entry event.
Definition: EntryEvent.h:36
std::string getName() const
Returns the name of the map for this event.
Definition: EntryEvent.h:178
const V & getValue() const
Returns the value of the entry event.
Definition: EntryEvent.h:142