-
Notifications
You must be signed in to change notification settings - Fork 17
/
turbo_event.go
92 lines (75 loc) · 2.04 KB
/
turbo_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
package turbo
type IEvent interface {
}
//返回的事件
type IBackwardEvent interface {
IEvent
}
//向前的事件
type IForwardEvent interface {
IEvent
}
type PacketEvent struct {
IForwardEvent
Packet *Packet //本次的数据包
RemoteClient *TClient
}
func NewPacketEvent(remoteClient *TClient, packet *Packet) *PacketEvent {
return &PacketEvent{Packet: packet, RemoteClient: remoteClient}
}
type HeartbeatEvent struct {
IForwardEvent
RemoteClient *TClient
Opaque uint32
Version int64
}
//心跳事件
func NewHeartbeatEvent(remoteClient *TClient, opaque uint32, version int64) *HeartbeatEvent {
return &HeartbeatEvent{
Version: version,
Opaque: opaque,
RemoteClient: remoteClient}
}
//远程操作事件
type RemotingEvent struct {
Event IForwardEvent
futures chan map[string]*Future //所有的回调的future
errFutures map[string]*Future //错误的回调future
TargetHost []string //发送的特定hostport
GroupIds []string //本次发送的分组
Packet *Packet //tlv的packet数据
}
func NewRemotingEvent(packet *Packet, targetHost []string, groupIds ...string) *RemotingEvent {
revent := &RemotingEvent{
TargetHost: targetHost,
GroupIds: groupIds,
Packet: packet,
futures: make(chan map[string]*Future, 1)}
return revent
}
func (self *RemotingEvent) AttachEvent(Event IForwardEvent) {
self.Event = Event
}
func (self *RemotingEvent) AttachErrFutures(futures map[string]*Future) {
self.errFutures = futures
}
//等待响应
func (self *RemotingEvent) Wait() map[string]*Future {
return <-self.futures
}
//网络回调事件
type RemoteFutureEvent struct {
IBackwardEvent
*RemotingEvent
Futures map[string] /*groupid*/ *Future //网络结果回调
}
//网络回调事件
func NewRemoteFutureEvent(remoteEvent *RemotingEvent, futures map[string]*Future) *RemoteFutureEvent {
fe := &RemoteFutureEvent{Futures: futures}
fe.RemotingEvent = remoteEvent
return fe
}
//到头的事件
type SunkEvent struct {
IForwardEvent
}