This repository has been archived by the owner on Feb 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
/
feature_client.go
192 lines (164 loc) · 6.16 KB
/
feature_client.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// Copyright 2019 eBay Inc.
// Primary authors: Simon Fell, Diego Ongaro,
// Raymond Kroeker, and Sathish Kandasamy.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package viewclient
import (
"github.com/ebay/akutan/rpc"
"github.com/ebay/akutan/space"
"github.com/ebay/akutan/viewclient/fanout"
"github.com/ebay/akutan/viewclient/viewreg"
)
// ****************************************************************************************************************
// This code used to be automatically generated, but it's no longer worth the trouble. Copy-paste as needed.
// ****************************************************************************************************************
// CarouselClient is a client for the Carousel service running on the particular view instance
type CarouselClient struct {
View viewreg.View
Stub rpc.CarouselClient
}
// Serves returns the Range in the HashSpace that this view contains.
func (c *CarouselClient) Serves() space.Range {
return c.View.Partition.HashRange()
}
func (c *CarouselClient) String() string {
return c.View.String()
}
// A ViewInfoPredicate is used to filter views. Sometimes nil is used in place
// of a predicate that always returns true.
type ViewInfoPredicate func(v viewreg.View) bool
// CarouselViews returns all views that support the Carousel feature, if pred is non-nil
// only those views passing the view predicate are included
func (c *Client) CarouselViews(pred ViewInfoPredicate) CarouselClients {
views := c.Registry.HealthyViews(viewreg.CarouselFeature)
res := make(CarouselClients, 0, len(views))
for _, view := range views {
if pred == nil || pred(view) {
res = append(res, &CarouselClient{
View: view,
Stub: view.Carousel(),
})
}
}
return res
}
// CarouselClients is a collection of CarouselClient, you typically get one of these
// from the Client.CarouselViews() method.
type CarouselClients []*CarouselClient
// Len returns the number of clients in this list. This is part of the implementation
// of the fanout.Views interface
func (c CarouselClients) Len() int {
return len(c)
}
// View returns the i'th client in this collect. This is part of the implementation
// of the fanout.Views interface
func (c CarouselClients) View(i int) fanout.View {
return c[i]
}
// DiagnosticsClient is a client for the Diagnostic service running on the particular view instance
type DiagnosticsClient struct {
View viewreg.View
Stub rpc.DiagnosticsClient
}
func (c *DiagnosticsClient) String() string {
return c.View.String()
}
// DiagnosticsViews returns all views that support the Diagnostics feature.
func (c *Client) DiagnosticsViews() []*DiagnosticsClient {
// c.Registry.HealthyViews(viewreg.DiagnosticsFeature) would filter out
// unhealthy views, but callers of this function usually want those.
views := c.Registry.AllViews()
res := make([]*DiagnosticsClient, len(views))
for i := range views {
res[i] = &DiagnosticsClient{
View: views[i],
Stub: views[i].Diagnostics(),
}
}
return res
}
// ReadFactsPOClient is a client for the ReadFactsPO service running on the particular view instance
type ReadFactsPOClient struct {
View viewreg.View
Stub rpc.ReadFactsPOClient
}
// Serves returns the hash range that this view contains. this is an implementation of the
// fanout.View interface
func (c *ReadFactsPOClient) Serves() space.Range {
return c.View.Partition.HashRange()
}
func (c *ReadFactsPOClient) String() string {
return c.View.String()
}
// ReadFactsPOClients is a collection of ReadFatsPOClient's. Typically you'd get these from
// a call to Client.ReadFactsPOViews()
type ReadFactsPOClients []*ReadFactsPOClient
// Len returns the number of clients in this collection. This is part of the implementation
// of the fanout.Views interface
func (c ReadFactsPOClients) Len() int {
return len(c)
}
// View return's the i'th View in this collection. This is part of the implementation
// of the fanout.Views interface
func (c ReadFactsPOClients) View(i int) fanout.View {
return c[i]
}
// ReadFactsPOViews returns all views that support the ReadFactsPO feature.
func (c *Client) ReadFactsPOViews() ReadFactsPOClients {
views := c.Registry.HealthyViews(viewreg.HashPOFeature)
res := make([]*ReadFactsPOClient, len(views))
for i := range views {
res[i] = &ReadFactsPOClient{
View: views[i],
Stub: views[i].HashPO(),
}
}
return res
}
// ReadFactsSPClient is a client for the ReadFactsSP service running on the particular view instance
type ReadFactsSPClient struct {
View viewreg.View
Stub rpc.ReadFactsSPClient
}
// Serves returns the range in Hash(SP) space that the related view contains. This is an implementation
// of the fanout.View interface
func (c *ReadFactsSPClient) Serves() space.Range {
return c.View.Partition.HashRange()
}
func (c *ReadFactsSPClient) String() string {
return c.View.String()
}
// ReadFactsSPClients is a collection of ReadFactsSPClient's. You typically get one of these from
// calling Client.ReadFactsSPViews()
type ReadFactsSPClients []*ReadFactsSPClient
// Len returns the number of clients in this collection. This is part of the implementation of the
// fanout.Views interface
func (c ReadFactsSPClients) Len() int {
return len(c)
}
// View returns the i'th client in the collection. This is part of the fanout.Views interface implementation
func (c ReadFactsSPClients) View(i int) fanout.View {
return c[i]
}
// ReadFactsSPViews returns all views that support the ReadFactsSP feature.
func (c *Client) ReadFactsSPViews() ReadFactsSPClients {
views := c.Registry.HealthyViews(viewreg.HashSPFeature)
res := make([]*ReadFactsSPClient, len(views))
for i := range views {
res[i] = &ReadFactsSPClient{
View: views[i],
Stub: views[i].HashSP(),
}
}
return res
}