forked from tendermint/tendermint
-
Notifications
You must be signed in to change notification settings - Fork 2
/
eventmeter.go
69 lines (58 loc) · 1.81 KB
/
eventmeter.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
66
67
68
69
package mock
import (
stdlog "log"
"reflect"
"github.com/tendermint/go-amino"
"github.com/tendermint/tendermint/libs/log"
em "github.com/tendermint/tendermint/tools/tm-monitor/eventmeter"
)
type EventMeter struct {
latencyCallback em.LatencyCallbackFunc
disconnectCallback em.DisconnectCallbackFunc
eventCallback em.EventCallbackFunc
}
func (e *EventMeter) Start() error { return nil }
func (e *EventMeter) Stop() {}
func (e *EventMeter) SetLogger(l log.Logger) {}
func (e *EventMeter) RegisterLatencyCallback(cb em.LatencyCallbackFunc) { e.latencyCallback = cb }
func (e *EventMeter) RegisterDisconnectCallback(cb em.DisconnectCallbackFunc) {
e.disconnectCallback = cb
}
func (e *EventMeter) Subscribe(query string, cb em.EventCallbackFunc) error {
e.eventCallback = cb
return nil
}
func (e *EventMeter) Unsubscribe(query string) error {
e.eventCallback = nil
return nil
}
func (e *EventMeter) Call(callback string, args ...interface{}) {
switch callback {
case "latencyCallback":
e.latencyCallback(args[0].(float64))
case "disconnectCallback":
e.disconnectCallback()
case "eventCallback":
e.eventCallback(args[0].(*em.EventMetric), args[1])
}
}
type RpcClient struct {
Stubs map[string]interface{}
cdc *amino.Codec
}
func (c *RpcClient) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) {
s, ok := c.Stubs[method]
if !ok {
stdlog.Fatalf("Call to %s, but no stub is defined for it", method)
}
rv, rt := reflect.ValueOf(result), reflect.TypeOf(result)
rv, rt = rv.Elem(), rt.Elem()
rv.Set(reflect.ValueOf(s))
return s, nil
}
func (c *RpcClient) Codec() *amino.Codec {
return c.cdc
}
func (c *RpcClient) SetCodec(cdc *amino.Codec) {
c.cdc = cdc
}