forked from ctripcorp/nephele
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree.go
65 lines (57 loc) · 1.23 KB
/
tree.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
package cat
type Tree interface {
NewTransaction(string, string) Transaction
NewEvent(string, string) Event
NewHeartbeat(string, string) Heartbeat
}
type tree struct {
stack []Transaction
root Transaction
}
func NewTree() Tree {
return &tree{
make([]Transaction, 0),
nil,
}
}
func (this *tree) NewTransaction(t string, n string) Transaction {
stack := this.stack
transaction := NewTransaction(t, n, this.flush_t)
l := len(stack)
if l > 0 {
parent := stack[l-1]
parent.AddChild(transaction)
} else {
this.root = transaction
}
this.stack = append(stack, transaction)
return transaction
}
func (this *tree) NewEvent(t string, n string) Event {
return NewEvent(t, n, this.flush)
}
func (this *tree) NewHeartbeat(t string, n string) Heartbeat {
return NewHeartbeat(t, n, this.flush)
}
func (this *tree) flush_t(t Transaction) {
stack := this.stack
current := len(stack) - 1
for ; current > -1; current-- {
if stack[current] == t {
this.stack = stack[:current]
break
}
}
if current == 0 {
sender_transaction_channel <- this.root
}
}
func (this *tree) flush(m Message) {
stack := this.stack
current := len(stack) - 1
if current == -1 {
aggregator_message_channel <- m
} else {
stack[current].AddChild(m)
}
}