Skip to content

Commit

Permalink
users can set their customized selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
smallnest committed Oct 31, 2017
1 parent 842c22c commit aca02cb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions client/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const (
ConsistentHash
//Closest is selecting the closest server
Closest

// SelectByUser is selecting by implementation of users
SelectByUser = 1000
)

var selectModeStrs = [...]string{
Expand Down
2 changes: 2 additions & 0 deletions client/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func newSelector(selectMode SelectMode, servers map[string]string) Selector {
return newWeightedICMPSelector(servers)
case ConsistentHash:
return newConsistentHashSelector(servers)
case SelectByUser:
return nil
default:
return newRandomSelector(servers)
}
Expand Down
7 changes: 6 additions & 1 deletion client/xclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,19 @@ func NewXClient(servicePath string, failMode FailMode, selectMode SelectMode, di
servers[p.Key] = p.Value
}
client.servers = servers
if selectMode != Closest {
if selectMode != Closest && selectMode != SelectByUser {
client.selector = newSelector(selectMode, servers)
}

client.Plugins = &pluginContainer{}
return client
}

// SetSelector sets customized selector by users.
func (c *xClient) SetSelector(s Selector) {
c.selector = s
}

// SetPlugins sets client's plugins.
func (c *xClient) SetPlugins(plugins PluginContainer) {
c.Plugins = plugins
Expand Down

0 comments on commit aca02cb

Please sign in to comment.