-
Notifications
You must be signed in to change notification settings - Fork 13
/
worker-proxy.go
136 lines (119 loc) · 3.64 KB
/
worker-proxy.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package process_master
import (
"context"
"errors"
"sync"
"github.com/eolinker/eosc/service"
"google.golang.org/grpc"
)
var _ service.WorkerServiceClient = (*WorkerServiceProxy)(nil)
var (
ErrClientNotInit = errors.New("no client")
)
type WorkerServiceProxy struct {
client service.WorkerServiceClient
locker sync.RWMutex
}
func (wc *WorkerServiceProxy) AddExtender(ctx context.Context, in *service.WorkerAddExtender, opts ...grpc.CallOption) (*service.WorkerResponse, error) {
client := wc.GetWorkerProcess()
if client != nil {
return client.AddExtender(ctx, in, opts...)
}
return nil, ErrClientNotInit
}
func (wc *WorkerServiceProxy) DelExtenderCheck(ctx context.Context, in *service.WorkerDelExtender, opts ...grpc.CallOption) (*service.WorkerResponse, error) {
client := wc.GetWorkerProcess()
if client != nil {
return client.DelExtenderCheck(ctx, in, opts...)
}
return nil, ErrClientNotInit
}
func (wc *WorkerServiceProxy) GetWorkerProcess() service.WorkerServiceClient {
wc.locker.RLock()
c := wc.client
wc.locker.RUnlock()
return c
}
func (wc *WorkerServiceProxy) SetWorkerProcess(client service.WorkerServiceClient) {
wc.locker.Lock()
wc.client = client
wc.locker.Unlock()
}
func NewWorkerServiceProxy() *WorkerServiceProxy {
return &WorkerServiceProxy{
locker: sync.RWMutex{},
}
}
func (wc *WorkerServiceProxy) DeleteCheck(ctx context.Context, in *service.WorkerDeleteRequest, opts ...grpc.CallOption) (*service.WorkerResponse, error) {
client := wc.GetWorkerProcess()
if client != nil {
return client.DeleteCheck(ctx, in, opts...)
}
return nil, ErrClientNotInit
}
func (wc *WorkerServiceProxy) SetCheck(ctx context.Context, in *service.WorkerSetRequest, opts ...grpc.CallOption) (*service.WorkerResponse, error) {
client := wc.GetWorkerProcess()
if client != nil {
response, err := client.SetCheck(ctx, in, opts...)
if err != nil {
return nil, err
}
return response, nil
}
return nil, ErrClientNotInit
}
func (wc *WorkerServiceProxy) Delete(ctx context.Context, in *service.WorkerDeleteRequest, opts ...grpc.CallOption) (*service.WorkerResponse, error) {
client := wc.GetWorkerProcess()
if client != nil {
response, err := client.Delete(ctx, in, opts...)
if err != nil {
return nil, err
}
return response, nil
}
return nil, ErrClientNotInit
}
func (wc *WorkerServiceProxy) Set(ctx context.Context, in *service.WorkerSetRequest, opts ...grpc.CallOption) (*service.WorkerResponse, error) {
client := wc.GetWorkerProcess()
if client != nil {
response, err := client.Set(ctx, in, opts...)
if err != nil {
return nil, err
}
return response, nil
}
return nil, ErrClientNotInit
}
func (wc *WorkerServiceProxy) Ping(ctx context.Context, in *service.WorkerHelloRequest, opts ...grpc.CallOption) (*service.WorkerResponse, error) {
client := wc.GetWorkerProcess()
if client != nil {
response, err := client.Ping(ctx, in, opts...)
if err != nil {
return nil, err
}
return response, nil
}
return nil, ErrClientNotInit
}
func (wc *WorkerServiceProxy) Reset(ctx context.Context, in *service.ResetRequest, opts ...grpc.CallOption) (*service.WorkerResponse, error) {
client := wc.GetWorkerProcess()
if client != nil {
response, err := client.Reset(ctx, in, opts...)
if err != nil {
return nil, err
}
return response, nil
}
return nil, ErrClientNotInit
}
func (wc *WorkerServiceProxy) Status(ctx context.Context, in *service.StatusRequest, opts ...grpc.CallOption) (*service.StatusResponse, error) {
client := wc.GetWorkerProcess()
if client != nil {
response, err := client.Status(ctx, in, opts...)
if err != nil {
return nil, err
}
return response, nil
}
return nil, ErrClientNotInit
}