-
Notifications
You must be signed in to change notification settings - Fork 45
/
pipelistener.go
57 lines (47 loc) · 1.06 KB
/
pipelistener.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
package p2putil
// MultiListener can contain multiple unit listeners and toss events
type MultiListener struct {
ls []PipeEventListener
}
func NewMultiListener(ls ...PipeEventListener) *MultiListener {
return &MultiListener{ls: ls}
}
func (ml *MultiListener) AppendListener(l PipeEventListener) {
ml.ls = append(ml.ls, l)
}
func (ml *MultiListener) OnIn(element interface{}) {
for _, l := range ml.ls {
l.OnIn(element)
}
}
func (ml *MultiListener) OnDrop(element interface{}) {
for _, l := range ml.ls {
l.OnDrop(element)
}
}
func (ml *MultiListener) OnOut(element interface{}) {
for _, l := range ml.ls {
l.OnOut(element)
}
}
// StatListener make summation
type StatListener struct {
incnt uint64
outcnt uint64
dropcnt uint64
consecdrop uint64
}
func NewStatLister() *StatListener {
return &StatListener{}
}
func (l *StatListener) OnIn(element interface{}) {
l.incnt++
}
func (l *StatListener) OnDrop(element interface{}) {
l.dropcnt++
l.consecdrop++
}
func (l *StatListener) OnOut(element interface{}) {
l.outcnt++
l.consecdrop = 0
}