-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_methods.go
More file actions
56 lines (45 loc) · 1.47 KB
/
node_methods.go
File metadata and controls
56 lines (45 loc) · 1.47 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
/*
* This module implements handlers for methods that are registered by the node
* itself.
*/
package node
func (node *node) HandleGetUsage(args []interface{}, kwargs map[string]interface{}, details map[string]interface{}) (result *CallResult) {
counts := node.stats.GetUsage()
result = &CallResult{
Args: []interface{}{counts},
}
return
}
func (node *node) HandleEvictDomain(args []interface{}, kwargs map[string]interface{}, details map[string]interface{}) (result *CallResult) {
domain, ok := args[0].(string)
count := 0
if ok {
count = node.EvictDomain(domain)
}
result = &CallResult{
Args: []interface{}{count},
}
return
}
func (node *node) HandleUnregisterAll(args []interface{}, kwargs map[string]interface{}, details map[string]interface{}) (result *CallResult) {
endpoint, ok := args[0].(string)
count := 0
if ok {
count = node.Dealer.UnregisterAll(URI(endpoint))
}
result = &CallResult{
Args: []interface{}{count},
}
return
}
func (node *node) RegisterNodeMethods() {
options := make(map[string]interface{}, 0)
endpoint := string(node.agent.pdid + "/getUsage")
node.agent.Register(endpoint, node.HandleGetUsage, options)
options = make(map[string]interface{}, 0)
endpoint = string(node.agent.pdid + "/evictDomain")
node.agent.Register(endpoint, node.HandleEvictDomain, options)
options = make(map[string]interface{}, 0)
endpoint = string(node.agent.pdid + "/unregisterAll")
node.agent.Register(endpoint, node.HandleUnregisterAll, options)
}