Documentation
¶
Index ¶
- type Agent
- type ChangeListener
- type ConnectionStatus
- type ErrAgentHasNoReferenceToPeer
- type ErrChooseContextHasNoDeadline
- type ErrInvalidAgentConversion
- type ErrInvalidPeerConversion
- type ErrInvalidPeerType
- type ErrPeerAddAlreadyInList
- type ErrPeerHasNoReferenceToSubscriber
- type ErrPeerListAlreadyStarted
- type ErrPeerListNotStarted
- type ErrPeerRemoveNotInList
- type Identifier
- type List
- type Peer
- type Status
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent interface {
// Get or create a Peer for the Subscriber
RetainPeer(Identifier, Subscriber) (Peer, error)
// Unallocate a peer from the Subscriber
ReleasePeer(Identifier, Subscriber) error
}
Agent manages Peers across different Subscribers. A Subscriber will request a Peer for a specific PeerIdentifier and the Agent has the ability to create a new Peer or return an existing one.
type ChangeListener ¶
type ChangeListener interface {
// Add a peer to the List (Called directly from a PeerProvider)
Add(Identifier) error
// Remove a peer from the List (Called directly from a PeerProvider)
Remove(Identifier) error
}
ChangeListener listens to adds and removes of Peers from a PeerProvider A List will implement the PeerChangeListener interface in order to receive updates to the list of Peers it is keeping track of
type ConnectionStatus ¶
type ConnectionStatus int
ConnectionStatus maintains information about the Peer's connection state
const ( Unavailable ConnectionStatus = iota // Connecting indicates the Peer is in the process of connecting Connecting // Available indicates the Peer is available for requests Available )
type ErrAgentHasNoReferenceToPeer ¶
ErrAgentHasNoReferenceToPeer is called when an agent is expected to operate on a Peer it has no reference to
func (ErrAgentHasNoReferenceToPeer) Error ¶
func (e ErrAgentHasNoReferenceToPeer) Error() string
type ErrChooseContextHasNoDeadline ¶
type ErrChooseContextHasNoDeadline string
ErrChooseContextHasNoDeadline is returned when a context is sent to a peerlist with no deadline
func (ErrChooseContextHasNoDeadline) Error ¶
func (e ErrChooseContextHasNoDeadline) Error() string
type ErrInvalidAgentConversion ¶
ErrInvalidAgentConversion is called when an agent can't be properly converted
func (ErrInvalidAgentConversion) Error ¶
func (e ErrInvalidAgentConversion) Error() string
type ErrInvalidPeerConversion ¶
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 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 ¶
func (e ErrPeerHasNoReferenceToSubscriber) Error() string
type ErrPeerListAlreadyStarted ¶
type ErrPeerListAlreadyStarted string
ErrPeerListAlreadyStarted represents a failure because Start() was already called on the peerlist.
func (ErrPeerListAlreadyStarted) Error ¶
func (e ErrPeerListAlreadyStarted) Error() string
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 Identifier ¶
type Identifier interface {
Identifier() string
}
Identifier is able to uniquely identify a peer (e.g. hostport)
type List ¶
type List interface {
// Notify the PeerList that it will start receiving requests
Start() error
// Notify the PeerList that it will stop receiving requests
Stop() error
// Choose a Peer for the next call, block until a peer is available (or timeout)
ChoosePeer(context.Context, *transport.Request) (Peer, error)
}
List is a collection of Peers. Outbounds request peers from the peer.List to determine where to send requests
type Peer ¶
type Peer interface {
Identifier
// Get the status of the Peer
Status() Status
// Tell the peer that a request is starting/ending
// The callsite should look like:
// done := peer.StartRequest()
// defer done()
// // Do request
StartRequest() (finish func())
}
Peer is a level on top of Identifier. It should be created by a Agent 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
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.