-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcollects.go
42 lines (33 loc) · 910 Bytes
/
collects.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
package endure
import (
"github.com/roadrunner-server/errors"
)
func (e *Endure) collects() error {
vertices := e.graph.TopologicalOrder()
for i := 0; i < len(vertices); i++ {
if !vertices[i].IsActive() {
continue
}
if _, ok := vertices[i].Plugin().(Collector); !ok {
continue
}
// in deps
collects := vertices[i].Plugin().(Collector).Collects()
// get vals
for j := 0; j < len(collects); j++ {
impl := e.registar.ImplementsExcept(collects[j].Type, vertices[i].Plugin())
if len(impl) == 0 {
continue
}
for k := 0; k < len(impl); k++ {
value, ok := e.registar.TypeValue(impl[k].Plugin(), collects[j].Type)
if !ok {
return errors.E("this is likely a bug, nil value from the implements. Value should be initialized due to the topological order")
}
// call user's callback
collects[j].Callback(value.Interface())
}
}
}
return nil
}