-
Notifications
You must be signed in to change notification settings - Fork 0
/
procbundle.go
67 lines (46 loc) · 1.29 KB
/
procbundle.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
package proc
import (
"github.com/fangjie-luoxi/cellnet"
)
// 处理器设置接口,由各Peer实现
type ProcessorBundle interface {
// 设置 传输器,负责收发消息
SetTransmitter(v cellnet.MessageTransmitter)
// 设置 接收后,发送前的事件处理流程
SetHooker(v cellnet.EventHooker)
// 设置 接收后最终处理回调
SetCallback(v cellnet.EventCallback)
}
// 让EventCallback保证放在ses的队列里,而不是并发的
func NewQueuedEventCallback(callback cellnet.EventCallback) cellnet.EventCallback {
return func(ev cellnet.Event) {
if callback != nil {
cellnet.SessionQueuedCall(ev.Session(), func() {
callback(ev)
})
}
}
}
// 当需要多个Hooker时,使用NewMultiHooker将多个hooker合并成1个hooker处理
type MultiHooker []cellnet.EventHooker
func (self MultiHooker) OnInboundEvent(input cellnet.Event) (output cellnet.Event) {
for _, h := range self {
input = h.OnInboundEvent(input)
if input == nil {
break
}
}
return input
}
func (self MultiHooker) OnOutboundEvent(input cellnet.Event) (output cellnet.Event) {
for _, h := range self {
input = h.OnOutboundEvent(input)
if input == nil {
break
}
}
return input
}
func NewMultiHooker(h ...cellnet.EventHooker) cellnet.EventHooker {
return MultiHooker(h)
}