list

package
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2016 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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) 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

type RoundRobin

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

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

func NewRoundRobin

func NewRoundRobin(peerIDs []peer.Identifier, agent peer.Agent) (*RoundRobin, error)

NewRoundRobin creates a new round robin PeerList using

func (*RoundRobin) Add

func (pl *RoundRobin) Add(pid peer.Identifier) error

Add a peer identifier to the round robin

func (*RoundRobin) ChoosePeer

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

ChoosePeer selects the next available peer in the round robin

func (*RoundRobin) NotifyStatusChanged

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

NotifyStatusChanged when the peer's status changes

func (*RoundRobin) Remove

func (pl *RoundRobin) Remove(pid peer.Identifier) error

Remove a peer identifier from the round robin

func (*RoundRobin) Start

func (pl *RoundRobin) Start() error

Start notifies the RoundRobin that requests will start coming

func (*RoundRobin) Stop

func (pl *RoundRobin) Stop() error

Stop notifies the RoundRobin that requests will stop coming

Jump to

Keyboard shortcuts

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