forked from couchbase/gocbcore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpcfgcontroller.go
40 lines (32 loc) · 896 Bytes
/
httpcfgcontroller.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
package gocbcore
type httpConfigController struct {
muxer *httpMux
seenNodes map[string]uint64
*baseHTTPConfigController
}
func newHTTPConfigController(bucketName string, props httpPollerProperties, muxer *httpMux,
cfgMgr *configManagementComponent) *httpConfigController {
ctrlr := &httpConfigController{
muxer: muxer,
seenNodes: make(map[string]uint64),
}
ctrlr.baseHTTPConfigController = newBaseHTTPConfigController(bucketName, props, cfgMgr, ctrlr.GetEndpoint)
return ctrlr
}
func (hcc *httpConfigController) GetEndpoint(iterNum uint64) string {
var pickedSrv string
for _, srv := range hcc.muxer.MgmtEps() {
if hcc.seenNodes[srv] >= iterNum {
continue
}
pickedSrv = srv
break
}
if pickedSrv != "" {
hcc.seenNodes[pickedSrv] = iterNum
}
return pickedSrv
}
func (hcc *httpConfigController) CanPoll() bool {
return len(hcc.muxer.MgmtEps()) > 0
}