roundrobin

package
v1.0.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2016 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

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

List is a PeerList which rotates which peers are to be selected in a circle

func New

func New(transport peer.Transport) *List

New creates a new round robin PeerList

func (*List) Choose

func (pl *List) Choose(ctx context.Context, req *transport.Request) (peer.Peer, func(error), error)

Choose selects the next available peer in the round robin

func (*List) Introspect

func (pl *List) Introspect() introspection.ChooserStatus

Introspect returns a ChooserStatus with a summary of the Peers.

func (*List) IsRunning

func (pl *List) IsRunning() bool

IsRunning returns whether the peer list is running.

func (*List) NotifyStatusChanged

func (pl *List) NotifyStatusChanged(pid peer.Identifier)

NotifyStatusChanged when the peer's status changes

func (*List) Start

func (pl *List) Start() error

Start notifies the List that requests will start coming

func (*List) Stop

func (pl *List) Stop() error

Stop notifies the List that requests will stop coming

func (*List) Update

func (pl *List) Update(updates peer.ListUpdates) error

Update applies the additions and removals of peer Identifiers to the list it returns a multi-error result of every failure that happened without circuit breaking due to failures

type PeerRing

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

PeerRing provides a safe way to interact (Add/Remove/Get) with a potentially changing list of peer objects PeerRing is NOT Thread-safe, make sure to only call PeerRing functions with a lock

func NewPeerRing

func NewPeerRing(capacity int) *PeerRing

NewPeerRing creates a new PeerRing with an initial capacity

func (*PeerRing) Add

func (pr *PeerRing) Add(p peer.Peer) error

Add a peer.Peer to the end of the PeerRing, if the ring is empty it initializes the nextNode marker

func (*PeerRing) All

func (pr *PeerRing) All() []peer.Peer

All returns a snapshot of all the peers from the ring as a list.

func (*PeerRing) GetPeer

func (pr *PeerRing) GetPeer(pid peer.Identifier) peer.Peer

GetPeer returns the Peer from the Ring or Nil

func (*PeerRing) Next

func (pr *PeerRing) Next() peer.Peer

Next returns the next peer in the ring, or nil if there is no peer in the ring after it has the next peer, it increments the nextPeer marker in the ring

func (*PeerRing) Remove

func (pr *PeerRing) Remove(p peer.Peer) error

Remove a peer Peer from the PeerRing, if the PeerID is not in the ring return an error

func (*PeerRing) RemoveAll

func (pr *PeerRing) RemoveAll() []peer.Peer

RemoveAll pops all the peers from the ring and returns them in a list

Jump to

Keyboard shortcuts

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