-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.go
More file actions
81 lines (62 loc) · 1.54 KB
/
Copy pathapplication.go
File metadata and controls
81 lines (62 loc) · 1.54 KB
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
package ichord
import (
"os"
"github.com/deepdive7/icfg"
"github.com/deepdive7/ilog"
)
type Application interface {
ID() UUID
Startup(args *icfg.Config) error
ShutDown() error
// When a error occurs in the functionality of the DHT
OnError(err error)
// Receive a message intended for the self node
OnDeliver(msg *Message)
// Received a message that needs to be routed onwards
OnForward(msg *Message, node *Node) bool // return False if chord should not forward
// A new node has joined the network
OnNodeJoin(node *Node)
// A node has left the network
OnNodeExit(node *Node)
// Received a heartbeat signal from a peer
OnHeartbeat(node *Node)
}
func NewLogApp() *LogApp {
return &LogApp{
id: NewID(),
log: ilog.NewSimpleDefaultLogger(os.Stdout, 0, "logapp->", true),
}
}
type LogApp struct {
id UUID
log ilog.Logger
}
func (la *LogApp) ID() UUID {
return la.id
}
func (la *LogApp) Startup(cfg *icfg.Config) error {
return nil
}
func (la *LogApp) OnError(err error) {
la.log.Error(err.Error())
}
func (la *LogApp) OnDeliver(msg *Message) {
la.log.Info("OnDeliver:", msg.String())
}
func (la *LogApp) OnForward(msg *Message, node *Node) bool {
la.log.Info("OnForward:", node.String())
return true
}
func (la *LogApp) OnNodeJoin(node *Node) {
la.log.Info("OnNodeJoin:", node.String())
}
func (la *LogApp) OnNodeExit(node *Node) {
la.log.Info("OnNodeExit:", node.String())
}
func (la *LogApp) OnHeartbeat(node *Node) {
la.log.Info("OnHeartbeat:", node.String())
}
func (la *LogApp) ShutDown() error {
la.log = nil
return nil
}