-
Notifications
You must be signed in to change notification settings - Fork 3
/
sink.go
54 lines (44 loc) · 829 Bytes
/
sink.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
package examples
import (
. "github.com/danalex97/Speer/interfaces"
"fmt"
)
type SinkExample struct {
Transport
id string
parent string
ctr int
}
func (s *SinkExample) New(util NodeUtil) Node {
return &SinkExample{
Transport: util.Transport(),
id: util.Id(),
parent: util.Join(),
ctr: 0,
}
}
func (s *SinkExample) root() bool {
return s.parent == ""
}
func (s *SinkExample) OnJoin() {
// send my id to the parent
if !s.root() {
s.ControlSend(s.parent, s.id)
}
}
func (s *SinkExample) OnNotify() {
select {
case m, _ := <-s.ControlRecv():
if !s.root() {
// forward each message
s.ControlSend(s.parent, m)
} else {
// the root will print the messages
s.ctr += 1
fmt.Println("message #", s.ctr, "received", m)
}
default:
}
}
func (s *SinkExample) OnLeave() {
}