Help us shape the future of Go! Take the 2026 Go Developer Survey

picker

package
v1.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2016 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Picker

type Picker struct {
	// contains filtered or unexported fields
}

Picker implements a grpc Picker

func NewPicker

func NewPicker(r Remotes, initial ...string) *Picker

NewPicker returns a Picker

func (*Picker) Close

func (p *Picker) Close() error

Close closes all the Conn's owned by this Picker.

func (*Picker) Init

func (p *Picker) Init(cc *grpc.ClientConn) error

Init does initial processing for the Picker, e.g., initiate some connections.

func (*Picker) Pick

Pick blocks until either a transport.ClientTransport is ready for the upcoming RPC or some error happens.

func (*Picker) PickAddr

func (p *Picker) PickAddr() (string, error)

PickAddr picks a peer address for connecting. This will be called repeated for connecting/reconnecting.

func (*Picker) Reset

func (p *Picker) Reset() error

Reset the current connection and force a reconnect to another address.

func (*Picker) State

func (p *Picker) State() (grpc.ConnectivityState, error)

State returns the connectivity state of the underlying connections.

func (*Picker) WaitForStateChange

func (p *Picker) WaitForStateChange(ctx context.Context, sourceState grpc.ConnectivityState) (grpc.ConnectivityState, error)

WaitForStateChange blocks until the state changes to something other than the sourceState. It returns the new state or error.

type Remotes

type Remotes interface {
	// Weight returns the remotes with their current weights.
	Weights() map[api.Peer]int

	// Select a remote from the set of available remotes with optionally
	// excluding ID or address.
	Select(...string) (api.Peer, error)

	// Observe records an experience with a particular remote. A positive weight
	// indicates a good experience and a negative weight a bad experience.
	//
	// The observation will be used to calculate a moving weight, which is
	// implementation dependent. This method will be called such that repeated
	// observations of the same master in each session request are favored.
	Observe(peer api.Peer, weight int)

	// ObserveIfExists records an experience with a particular remote if when a
	// remote exists.
	ObserveIfExists(peer api.Peer, weight int)

	// Remove the remote from the list completely.
	Remove(addrs ...api.Peer)
}

Remotes keeps track of remote addresses by weight, informed by observations.

func NewRemotes

func NewRemotes(peers ...api.Peer) Remotes

NewRemotes returns a Remotes instance with the provided set of addresses. Entries provided are heavily weighted initially.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL