forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.go
60 lines (48 loc) · 2.01 KB
/
player.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
// Copyright 2012, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gorpcbinlogplayer
import (
"time"
"github.com/youtube/vitess/go/rpcplus"
"github.com/youtube/vitess/go/rpcwrap/bsonrpc"
"github.com/youtube/vitess/go/vt/binlog/binlogplayer"
"github.com/youtube/vitess/go/vt/binlog/proto"
)
// GoRpcBinlogPlayerResponse is the type returned by the Client for streaming
type GoRpcBinlogPlayerResponse struct {
*rpcplus.Call
}
func (response *GoRpcBinlogPlayerResponse) Error() error {
return response.Call.Error
}
// GoRpcBinlogPlayerClient implements a BinlogPlayerClient over go rpc
type GoRpcBinlogPlayerClient struct {
*rpcplus.Client
}
func (client *GoRpcBinlogPlayerClient) Dial(addr string, connTimeout time.Duration) error {
var err error
client.Client, err = bsonrpc.DialHTTP("tcp", addr, connTimeout, nil)
return err
}
func (client *GoRpcBinlogPlayerClient) Close() {
client.Client.Close()
}
func (client *GoRpcBinlogPlayerClient) ServeUpdateStream(req *proto.UpdateStreamRequest, responseChan chan *proto.StreamEvent) binlogplayer.BinlogPlayerResponse {
resp := client.Client.StreamGo("UpdateStream.ServeUpdateStream", req, responseChan)
return &GoRpcBinlogPlayerResponse{resp}
}
func (client *GoRpcBinlogPlayerClient) StreamKeyRange(req *proto.KeyRangeRequest, responseChan chan *proto.BinlogTransaction) binlogplayer.BinlogPlayerResponse {
resp := client.Client.StreamGo("UpdateStream.StreamKeyRange", req, responseChan)
return &GoRpcBinlogPlayerResponse{resp}
}
func (client *GoRpcBinlogPlayerClient) StreamTables(req *proto.TablesRequest, responseChan chan *proto.BinlogTransaction) binlogplayer.BinlogPlayerResponse {
resp := client.Client.StreamGo("UpdateStream.StreamTables", req, responseChan)
return &GoRpcBinlogPlayerResponse{resp}
}
// Registration as a factory
func init() {
binlogplayer.RegisterBinlogPlayerClientFactory("gorpc", func() binlogplayer.BinlogPlayerClient {
return &GoRpcBinlogPlayerClient{}
})
}