peer

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2017 License: MIT Imports: 3 Imported by: 49

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chooser

type Chooser interface {
	transport.Lifecycle

	// Choose a Peer for the next call, block until a peer is available (or timeout)
	Choose(context.Context, *transport.Request) (peer Peer, onFinish func(error), err error)
}

Chooser is a collection of Peers. Outbounds request peers from the peer.Chooser to determine where to send requests.

type ChooserList added in v1.7.0

type ChooserList interface {
	Chooser
	List
}

ChooserList is both a Chooser and a List, useful for expressing both capabilities of a single instance.

type ConnectionStatus

type ConnectionStatus int

ConnectionStatus maintains information about the Peer's connection state

const (
	// Unavailable indicates the Peer is unavailable for requests
	Unavailable ConnectionStatus = iota

	// Connecting indicates the Peer is in the process of connecting
	Connecting

	// Available indicates the Peer is available for requests
	Available
)

func (ConnectionStatus) String

func (i ConnectionStatus) String() string

type ErrChooseContextHasNoDeadline

type ErrChooseContextHasNoDeadline string

ErrChooseContextHasNoDeadline is returned when a context is sent to a peerlist with no deadline

func (ErrChooseContextHasNoDeadline) Error

type ErrInvalidPeerConversion

type ErrInvalidPeerConversion struct {
	Peer         Peer
	ExpectedType string
}

ErrInvalidPeerConversion is called when a peer can't be properly converted

func (ErrInvalidPeerConversion) Error

func (e ErrInvalidPeerConversion) Error() string

type ErrInvalidPeerType

type ErrInvalidPeerType struct {
	ExpectedType   string
	PeerIdentifier Identifier
}

ErrInvalidPeerType is when a specfic peer type is required, but was not passed in

func (ErrInvalidPeerType) Error

func (e ErrInvalidPeerType) Error() string

type ErrInvalidTransportConversion

type ErrInvalidTransportConversion struct {
	Transport    Transport
	ExpectedType string
}

ErrInvalidTransportConversion is called when a transport can't be properly converted

func (ErrInvalidTransportConversion) Error

type ErrPeerAddAlreadyInList

type ErrPeerAddAlreadyInList string

ErrPeerAddAlreadyInList is returned to peer providers if the peerlist is already tracking a peer for the added identifier

func (ErrPeerAddAlreadyInList) Error

func (e ErrPeerAddAlreadyInList) Error() string

type ErrPeerHasNoReferenceToSubscriber

type ErrPeerHasNoReferenceToSubscriber struct {
	PeerIdentifier Identifier
	PeerSubscriber Subscriber
}

ErrPeerHasNoReferenceToSubscriber is called when a Peer is expected to operate on a PeerSubscriber it has no reference to

func (ErrPeerHasNoReferenceToSubscriber) Error

type ErrPeerListAlreadyStarted

type ErrPeerListAlreadyStarted string

ErrPeerListAlreadyStarted represents a failure because Start() was already called on the peerlist.

func (ErrPeerListAlreadyStarted) Error

type ErrPeerListNotStarted

type ErrPeerListNotStarted string

ErrPeerListNotStarted represents a failure because Start() was not called on a peerlist or if Stop() was called.

func (ErrPeerListNotStarted) Error

func (e ErrPeerListNotStarted) Error() string

type ErrPeerRemoveNotInList

type ErrPeerRemoveNotInList string

ErrPeerRemoveNotInList is returned to peer providers if the peerlist is not tracking the peer to remove for a given identifier

func (ErrPeerRemoveNotInList) Error

func (e ErrPeerRemoveNotInList) Error() string

type ErrTransportHasNoReferenceToPeer

type ErrTransportHasNoReferenceToPeer struct {
	TransportName  string
	PeerIdentifier string
}

ErrTransportHasNoReferenceToPeer is called when a transport is expected to operate on a Peer it has no reference to

func (ErrTransportHasNoReferenceToPeer) Error

type Identifier

type Identifier interface {
	Identifier() string
}

Identifier is able to uniquely identify a peer (e.g. hostport)

type List

type List interface {
	// Update performs the additions and removals to the Peer List
	Update(updates ListUpdates) error
}

List listens to adds and removes of Peers from a PeerProvider A Chooser will implement the List interface in order to receive updates to the list of Peers it is keeping track of

type ListUpdates

type ListUpdates struct {
	// Additions are the identifiers that should be added to the list
	Additions []Identifier

	// Removals are the identifiers that should be removed to the list
	Removals []Identifier
}

ListUpdates specifies the updates to be made to a List

type Peer

type Peer interface {
	Identifier

	// Get the status of the Peer
	Status() Status

	// Tell the peer that a request is starting
	StartRequest()

	// Tell the peer that a request has finished
	EndRequest()
}

Peer is a level on top of Identifier. It should be created by a Transport so we can maintain multiple references to the same downstream peer (e.g. hostport). This is useful for load balancing requests to downstream services.

type Status

type Status struct {
	// Current number of pending requests on this peer
	PendingRequestCount int

	// Current status of the Peer's connection
	ConnectionStatus ConnectionStatus
}

Status holds all the information about a peer's state that would be useful to Subscribers

func (Status) String

func (s Status) String() string

type Subscriber

type Subscriber interface {
	// The Peer Notifies the Subscriber when its status changes (e.g. connections status, pending requests)
	NotifyStatusChanged(Identifier)
}

Subscriber listens to changes of a Peer over time.

type Transport

type Transport interface {
	// Get or create a Peer for the Subscriber
	RetainPeer(Identifier, Subscriber) (Peer, error)

	// Unallocate a peer from the Subscriber
	ReleasePeer(Identifier, Subscriber) error
}

Transport manages Peers across different Subscribers. A Subscriber will request a Peer for a specific PeerIdentifier and the Transport has the ability to create a new Peer or return an existing one.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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