-
Notifications
You must be signed in to change notification settings - Fork 63
/
internal.go
57 lines (47 loc) · 1.09 KB
/
internal.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
package rpcv3
import (
"context"
"github.com/paralus/paralus/pkg/pool"
grpcpool "github.com/processout/grpc-go-pool"
)
// ClusterClient is the interface for accessing all the RPCs
// exposed by Cluster service
type ClusterClient interface {
Unhealthy()
Close() error
ClusterServiceClient
}
type clusterClient struct {
*grpcpool.ClientConn
*clusterServiceClient
}
var _ ClusterClient = (*clusterClient)(nil)
// ClusterPool maintains pool of grpc connections to cluster service
type ClusterPool interface {
Close()
NewClient(ctx context.Context) (ClusterClient, error)
}
// NewClusterPool new cluster pool
func NewClusterPool(addr string, maxConn int) ClusterPool {
return &clusterPool{
GRPCPool: pool.NewGRPCPool(addr, maxConn, nil),
}
}
type clusterPool struct {
*pool.GRPCPool
}
func (p *clusterPool) Close() {
if p.GRPCPool != nil {
p.GRPCPool.Close()
}
}
func (p *clusterPool) NewClient(ctx context.Context) (ClusterClient, error) {
cc, err := p.GetConnection(ctx)
if err != nil {
return nil, err
}
return &clusterClient{
cc,
&clusterServiceClient{cc.ClientConn},
}, nil
}