-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathevents.go
303 lines (263 loc) · 9.98 KB
/
events.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
* Copyright (c) 2008-2021, Hazelcast, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package hazelcast
import (
"time"
"github.com/hazelcast/hazelcast-go-client/cluster"
)
// EntryEventType is the type of an entry event.
type EntryEventType int32
const (
// EntryAdded is dispatched if an entry is added.
EntryAdded EntryEventType = 1 << 0
// EntryRemoved is dispatched if an entry is removed.
EntryRemoved EntryEventType = 1 << 1
// EntryUpdated is dispatched if an entry is updated.
EntryUpdated EntryEventType = 1 << 2
// EntryEvicted is dispatched if an entry is evicted.
EntryEvicted EntryEventType = 1 << 3
// EntryExpired is dispatched if an entry is expired.
EntryExpired EntryEventType = 1 << 4
// EntryAllEvicted is dispatched if all entries are evicted.
EntryAllEvicted EntryEventType = 1 << 5
// EntryAllCleared is dispatched if all entries are cleared.
EntryAllCleared EntryEventType = 1 << 6
// EntryMerged is dispatched if an entry is merged after a network partition.
EntryMerged EntryEventType = 1 << 7
// EntryInvalidated is dispatched if an entry is invalidated.
EntryInvalidated EntryEventType = 1 << 8
// EntryLoaded is dispatched if an entry is loaded.
EntryLoaded EntryEventType = 1 << 9
)
// EntryNotifiedHandler is called when an entry event happens.
type EntryNotifiedHandler func(event *EntryNotified)
const (
eventEntryNotified = "entrynotified"
eventLifecycleEventStateChanged = "lifecyclestatechanged"
eventMessagePublished = "messagepublished"
eventQueueItemNotified = "queue.itemnotified"
eventListItemNotified = "list.itemnotified"
eventSetItemNotified = "set.itemnotified"
eventDistributedObjectNotified = "distributedobjectnotified"
)
// EntryNotified contains information about an entry event.
// Member may have the zero value of cluster.MemberInfo if the member is not known at the time the corresponding callback runs.
// You can check that situation by checking whether Member.UUID is the default UUID.
type EntryNotified struct {
MergingValue interface{}
Key interface{}
Value interface{}
OldValue interface{}
MapName string
Member cluster.MemberInfo
NumberOfAffectedEntries int
EventType EntryEventType
}
func (e *EntryNotified) EventName() string {
return eventEntryNotified
}
func newEntryNotifiedEvent(
mapName string,
member cluster.MemberInfo,
key interface{},
value interface{},
oldValue interface{},
mergingValue interface{},
numberOfAffectedEntries int,
eventType EntryEventType,
) *EntryNotified {
return &EntryNotified{
MapName: mapName,
Member: member,
Key: key,
Value: value,
OldValue: oldValue,
MergingValue: mergingValue,
NumberOfAffectedEntries: numberOfAffectedEntries,
EventType: eventType,
}
}
// LifecycleState indicates the state of the lifecycle event.
type LifecycleState int
func (s LifecycleState) String() string {
switch s {
case LifecycleStateStarting:
return "starting"
case LifecycleStateStarted:
return "started"
case LifecycleStateShuttingDown:
return "shutting down"
case LifecycleStateShutDown:
return "shutdown"
case LifecycleStateConnected:
return "client connected"
case LifecycleStateDisconnected:
return "client disconnected"
case LifecycleStateChangedCluster:
return "changed cluster"
default:
return "UNKNOWN"
}
}
const (
// LifecycleStateStarting signals that the client is starting.
LifecycleStateStarting LifecycleState = iota
// LifecycleStateStarted signals that the client started.
LifecycleStateStarted
// LifecycleStateShuttingDown signals that the client is shutting down.
LifecycleStateShuttingDown
// LifecycleStateShutDown signals that the client shut down.
LifecycleStateShutDown
// LifecycleStateConnected signals that the client connected to the cluster.
LifecycleStateConnected
// LifecycleStateDisconnected signals that the client disconnected from the cluster.
LifecycleStateDisconnected
// LifecycleStateChangedCluster signals that the client is connected to a new cluster.
LifecycleStateChangedCluster
)
// LifecycleStateChangeHandler is called when a lifecycle event occurs.
type LifecycleStateChangeHandler func(event LifecycleStateChanged)
// LifecycleStateChanged contains information about a lifecycle event.
type LifecycleStateChanged struct {
State LifecycleState
}
func (e *LifecycleStateChanged) EventName() string {
return eventLifecycleEventStateChanged
}
func newLifecycleStateChanged(state LifecycleState) *LifecycleStateChanged {
return &LifecycleStateChanged{State: state}
}
// MessagePublished contains information about a message published event.
// Member may have the zero value of cluster.MemberInfo if the member is not known at the time the corresponding callback runs.
// You can check that situation by checking whether Member.UUID is the default UUID.
type MessagePublished struct {
PublishTime time.Time
Value interface{}
TopicName string
Member cluster.MemberInfo
}
func (m *MessagePublished) EventName() string {
return eventMessagePublished
}
func newMessagePublished(name string, value interface{}, publishTime time.Time, member cluster.MemberInfo) *MessagePublished {
return &MessagePublished{
TopicName: name,
Value: value,
PublishTime: publishTime,
Member: member,
}
}
// ItemEventType describes event types for item related events.
type ItemEventType int32
const (
// ItemAdded stands for item added event.
ItemAdded ItemEventType = 1
// ItemRemoved stands for item removed event.
ItemRemoved ItemEventType = 2
)
// QueueItemNotifiedHandler is called when an item notified event is generated for a Queue.
type QueueItemNotifiedHandler func(event *QueueItemNotified)
// QueueItemNotified contains information about an item notified event.
// Member may have the zero value of cluster.MemberInfo if the member is not known at the time the corresponding callback runs.
// You can check that situation by checking whether Member.UUID is the default UUID.
type QueueItemNotified struct {
Value interface{}
QueueName string
Member cluster.MemberInfo
EventType ItemEventType
}
func (q QueueItemNotified) EventName() string {
return eventQueueItemNotified
}
func newQueueItemNotified(name string, value interface{}, member cluster.MemberInfo, eventType int32) *QueueItemNotified {
return &QueueItemNotified{
QueueName: name,
Value: value,
Member: member,
EventType: ItemEventType(eventType),
}
}
// ListItemNotifiedHandler is a handler function for the List item listener.
type ListItemNotifiedHandler func(event *ListItemNotified)
// ListItemNotified describes the List item event.
// Member may have the zero value of cluster.MemberInfo if the member is not known at the time the corresponding callback runs.
// You can check that situation by checking whether Member.UUID is the default UUID.
type ListItemNotified struct {
Value interface{}
ListName string
Member cluster.MemberInfo
EventType ItemEventType
}
// EventName returns generic event name, common for all List item listeners.
func (q ListItemNotified) EventName() string {
return eventListItemNotified
}
func newListItemNotified(name string, value interface{}, member cluster.MemberInfo, eventType int32) *ListItemNotified {
return &ListItemNotified{
ListName: name,
Value: value,
Member: member,
EventType: ItemEventType(eventType),
}
}
// SetItemNotifiedHandler is called when an item notified event is generated for a Set.
type SetItemNotifiedHandler func(event *SetItemNotified)
// SetItemNotified contains information about an item notified event.
// Member may have the zero value of cluster.MemberInfo if the member is not known at the time the corresponding callback runs.
// You can check that situation by checking whether Member.UUID is the default UUID.
type SetItemNotified struct {
Value interface{}
SetName string
Member cluster.MemberInfo
EventType ItemEventType
}
func (q SetItemNotified) EventName() string {
return eventSetItemNotified
}
func newSetItemNotified(name string, value interface{}, member cluster.MemberInfo, eventType int32) *SetItemNotified {
return &SetItemNotified{
SetName: name,
Value: value,
Member: member,
EventType: ItemEventType(eventType),
}
}
// DistributedObjectEventType describes event type of a distributed object.
type DistributedObjectEventType string
const (
// DistributedObjectCreated is the event type when a distributed object is created.
DistributedObjectCreated DistributedObjectEventType = "CREATED"
// DistributedObjectDestroyed is the event type when a distributed object is destroyed.
DistributedObjectDestroyed DistributedObjectEventType = "DESTROYED"
)
// DistributedObjectNotifiedHandler is called when a distribute object event occurs.
type DistributedObjectNotifiedHandler func(event DistributedObjectNotified)
// DistributedObjectNotified contains informatino about the distributed object event.
type DistributedObjectNotified struct {
ServiceName string
ObjectName string
EventType DistributedObjectEventType
}
func (d DistributedObjectNotified) EventName() string {
return eventDistributedObjectNotified
}
func newDistributedObjectNotified(service string, object string, eventType DistributedObjectEventType) DistributedObjectNotified {
return DistributedObjectNotified{
ServiceName: service,
ObjectName: object,
EventType: eventType,
}
}