-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.go
184 lines (145 loc) · 4.83 KB
/
event.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
package context
import (
"time"
)
type ApplicationEventId uint64
var applicationContextEventId = GetEventId("github.com.procyon.ApplicationContextEvent")
var applicationContextStartedEventId = GetEventId("github.com.procyon.ApplicationContextStartedEvent")
var applicationContextStoppedEventId = GetEventId("github.com.procyon.ApplicationContextStoppedEvent")
var applicationContextRefreshedEventId = GetEventId("github.com.procyon.ApplicationContextRefreshedEvent")
var applicationContextClosedEventId = GetEventId("github.com.procyon.ApplicationContextClosedEvent")
func ApplicationContextEventId() ApplicationEventId {
return applicationContextEventId
}
func ApplicationContextStartedEventId() ApplicationEventId {
return applicationContextStartedEventId
}
func ApplicationContextStoppedEventId() ApplicationEventId {
return applicationContextStoppedEventId
}
func ApplicationContextRefreshedEventId() ApplicationEventId {
return applicationContextRefreshedEventId
}
func ApplicationContextClosedEventId() ApplicationEventId {
return applicationContextClosedEventId
}
func GetEventId(eventName string) ApplicationEventId {
if len(eventName) > 0 {
hash := uint64(0)
for _, character := range eventName {
hash = uint64(31)*hash + uint64(character)
}
return ApplicationEventId(hash)
}
return 0
}
type ApplicationEvent interface {
GetEventId() ApplicationEventId
GetParentEventId() ApplicationEventId
GetSource() interface{}
GetTimestamp() int64
}
type ApplicationContextEvent interface {
ApplicationEvent
GetApplicationContext() ApplicationContext
}
type ApplicationContextStartedEvent struct {
source ApplicationContext
timestamp int64
}
func NewApplicationContextStartedEvent(source ApplicationContext) ApplicationContextStartedEvent {
return ApplicationContextStartedEvent{
source: source,
timestamp: time.Now().Unix(),
}
}
func (event ApplicationContextStartedEvent) GetEventId() ApplicationEventId {
return applicationContextStartedEventId
}
func (event ApplicationContextStartedEvent) GetParentEventId() ApplicationEventId {
return applicationContextEventId
}
func (event ApplicationContextStartedEvent) GetSource() interface{} {
return event.source
}
func (event ApplicationContextStartedEvent) GetTimestamp() int64 {
return event.timestamp
}
func (event ApplicationContextStartedEvent) GetApplicationContext() ApplicationContext {
return event.source
}
type ApplicationContextStoppedEvent struct {
source ApplicationContext
timestamp int64
}
func NewApplicationContextStoppedEvent(source ApplicationContext) ApplicationContextStoppedEvent {
return ApplicationContextStoppedEvent{
source: source,
timestamp: time.Now().Unix(),
}
}
func (event ApplicationContextStoppedEvent) GetEventId() ApplicationEventId {
return applicationContextStoppedEventId
}
func (event ApplicationContextStoppedEvent) GetParentEventId() ApplicationEventId {
return applicationContextEventId
}
func (event ApplicationContextStoppedEvent) GetSource() interface{} {
return event.source
}
func (event ApplicationContextStoppedEvent) GetTimestamp() int64 {
return event.timestamp
}
func (event ApplicationContextStoppedEvent) GetApplicationContext() ApplicationContext {
return event.source
}
type ApplicationContextRefreshedEvent struct {
source ApplicationContext
timestamp int64
}
func NewApplicationContextRefreshedEvent(source ApplicationContext) ApplicationContextRefreshedEvent {
return ApplicationContextRefreshedEvent{
source: source,
timestamp: time.Now().Unix(),
}
}
func (event ApplicationContextRefreshedEvent) GetEventId() ApplicationEventId {
return applicationContextRefreshedEventId
}
func (event ApplicationContextRefreshedEvent) GetParentEventId() ApplicationEventId {
return applicationContextEventId
}
func (event ApplicationContextRefreshedEvent) GetSource() interface{} {
return event.source
}
func (event ApplicationContextRefreshedEvent) GetTimestamp() int64 {
return event.timestamp
}
func (event ApplicationContextRefreshedEvent) GetApplicationContext() ApplicationContext {
return event.source
}
type ApplicationContextClosedEvent struct {
source ApplicationContext
timestamp int64
}
func NewApplicationContextClosedEvent(source ApplicationContext) ApplicationContextClosedEvent {
return ApplicationContextClosedEvent{
source: source,
timestamp: time.Now().Unix(),
}
}
func (event ApplicationContextClosedEvent) GetEventId() ApplicationEventId {
return applicationContextClosedEventId
}
func (event ApplicationContextClosedEvent) GetParentEventId() ApplicationEventId {
return applicationContextEventId
}
func (event ApplicationContextClosedEvent) GetSource() interface{} {
return event.source
}
func (event ApplicationContextClosedEvent) GetTimestamp() int64 {
return event.timestamp
}
func (event ApplicationContextClosedEvent) GetApplicationContext() ApplicationContext {
return event.source
}