InfinispanHotRodC++Client  8.2.0.Alpha1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CacheClientListener.h
Go to the documentation of this file.
1 /*
2  * ClientListener.h
3  *
4  * Created on: Aug 3, 2016
5  * Author: rigazilla
6  */
7 
8 #ifndef INCLUDE_INFINISPAN_HOTROD_CACHECLIENTLISTENER_H_
9 #define INCLUDE_INFINISPAN_HOTROD_CACHECLIENTLISTENER_H_
10 
15 #include <vector>
16 #include <list>
17 #include <functional>
18 
19 using namespace infinispan::hotrod;
20 
21 namespace infinispan {
22 namespace hotrod {
23 
24 namespace protocol {
25 class Codec20;
26 }
27 template <class K, class V>
29 
30 namespace event {
31 
32 template <class K, class V>
34 {
35 public:
37 
39  void add_listener(std::function<void(ClientCacheEntryCreatedEvent<K>)> callback) {
40  createdCallbacks.push_back(callback);
41  }
42  void add_listener(std::function<void(ClientCacheEntryExpiredEvent<K>)> callback) {
43  expiredCallbacks.push_back(callback);
44  }
45  void add_listener(std::function<void(ClientCacheEntryModifiedEvent<K>)> callback) {
46  modifiedCallbacks.push_back(callback);
47  }
48  void add_listener(std::function<void(ClientCacheEntryRemovedEvent<K>)> callback) {
49  removedCallbacks.push_back(callback);
50  }
51  void add_listener(std::function<void(ClientCacheEntryCustomEvent)> callback) {
52  customCallbacks.push_back(callback);
53  }
54 
55  virtual void processEvent(ClientCacheEntryCreatedEvent<std::vector<char>> marshEv, std::vector<char >listId, uint8_t isCustom) const
56  {
57  K* key= (K*)cache.baseKeyUnmarshall(marshEv.getKey());
58  ClientCacheEntryCreatedEvent<K> typedEvent(*key, marshEv.getVersion(), marshEv.isCommandRetried());
59  delete key;
60  for (auto callable: createdCallbacks)
61  {
62  callable(typedEvent);
63  }
64  }
65 
66  virtual void processEvent(ClientCacheEntryModifiedEvent<std::vector<char>> marshEv, std::vector<char >listId, uint8_t isCustom) const
67  {
68  K* key= (K*)cache.baseKeyUnmarshall(marshEv.getKey());
69  ClientCacheEntryModifiedEvent<K> typedEvent(*key, marshEv.getVersion(), marshEv.isCommandRetried());
70  delete key;
71  for (auto callable: modifiedCallbacks)
72  {
73  callable(typedEvent);
74  }
75  }
76 
77  virtual void processEvent(ClientCacheEntryRemovedEvent<std::vector<char>> marshEv, std::vector<char >listId, uint8_t isCustom) const
78  {
79  K* key= (K*)cache.baseKeyUnmarshall(marshEv.getKey());
80  ClientCacheEntryRemovedEvent<K> typedEvent(*key, marshEv.isCommandRetried());
81  delete key;
82  for (auto callable: removedCallbacks)
83  {
84  callable(typedEvent);
85  }
86  }
87 
88  virtual void processEvent(ClientCacheEntryExpiredEvent<std::vector<char>> marshEv, std::vector<char >listId, uint8_t isCustom) const
89  {
90  K* key= (K*)cache.baseKeyUnmarshall(marshEv.getKey());
91  ClientCacheEntryExpiredEvent<K> typedEvent(*key);
92  delete key;
93  for (auto callable: expiredCallbacks)
94  {
95  callable(typedEvent);
96  }
97  }
98 
99  virtual void processEvent(ClientCacheEntryCustomEvent ev, std::vector<char >listId, uint8_t isCustom) const
100  {
101  for (auto callable: customCallbacks)
102  {
103  callable(ev);
104  }
105  }
106 private:
107  std::list<std::function<void(ClientCacheEntryCreatedEvent<K>)>> createdCallbacks;
108  std::list<std::function<void(ClientCacheEntryExpiredEvent<K>)>> expiredCallbacks;
109  std::list<std::function<void(ClientCacheEntryModifiedEvent<K>)>> modifiedCallbacks;
110  std::list<std::function<void(ClientCacheEntryRemovedEvent<K>)>> removedCallbacks;
111  std::list<std::function<void(ClientCacheEntryCustomEvent)>> customCallbacks;
112 };
113 
114 }}}
115 
116 
117 #endif /* INCLUDE_INFINISPAN_HOTROD_CACHECLIENTLISTENER_H_ */
virtual void processEvent(ClientCacheEntryExpiredEvent< std::vector< char >> marshEv, std::vector< char >listId, uint8_t isCustom) const
Definition: CacheClientListener.h:88
virtual void processEvent(ClientCacheEntryRemovedEvent< std::vector< char >> marshEv, std::vector< char >listId, uint8_t isCustom) const
Definition: CacheClientListener.h:77
void add_listener(std::function< void(ClientCacheEntryRemovedEvent< K >)> callback)
Definition: CacheClientListener.h:48
Definition: CacheClientListener.h:28
RemoteCacheBase & cache
Definition: CacheClientListener.h:36
void add_listener(std::function< void(ClientCacheEntryModifiedEvent< K >)> callback)
Definition: CacheClientListener.h:45
virtual void processEvent(ClientCacheEntryCreatedEvent< std::vector< char >> marshEv, std::vector< char >listId, uint8_t isCustom) const
Definition: CacheClientListener.h:55
virtual void processEvent(ClientCacheEntryModifiedEvent< std::vector< char >> marshEv, std::vector< char >listId, uint8_t isCustom) const
Definition: CacheClientListener.h:66
Definition: ClientListener.h:35
virtual void processEvent(ClientCacheEntryCustomEvent ev, std::vector< char >listId, uint8_t isCustom) const
Definition: CacheClientListener.h:99
Definition: CacheClientListener.h:33
void add_listener(std::function< void(ClientCacheEntryExpiredEvent< K >)> callback)
Definition: CacheClientListener.h:42
Definition: RemoteCacheBase.h:36
void add_listener(std::function< void(ClientCacheEntryCreatedEvent< K >)> callback)
Definition: CacheClientListener.h:39
void add_listener(std::function< void(ClientCacheEntryCustomEvent)> callback)
Definition: CacheClientListener.h:51
CacheClientListener(RemoteCache< K, V > &cache)
Definition: CacheClientListener.h:38