router

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: ISC Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxMessages is the default capacity for a route with a capacity defined
	DefaultMaxMessages = 200
)

Variables

View Source
var (
	// ErrTimeout signifies that one of the router functions had a timeout.
	ErrTimeout = protocolerrors.New(false, "timeout expired")

	// ErrRouteClosed indicates that a route was closed while reading/writing.
	ErrRouteClosed = errors.New("route is closed")

	// ErrRouteCapacityReached indicates that route's capacity has been reached
	ErrRouteCapacityReached = protocolerrors.New(false, "route capacity has been reached")
)

Functions

This section is empty.

Types

type OnRouteCapacityReachedHandler

type OnRouteCapacityReachedHandler func()

OnRouteCapacityReachedHandler is a function that is to be called when one of the routes reaches capacity.

type Route

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

Route represents an incoming or outgoing Router route

func NewRoute

func NewRoute(name string) *Route

NewRoute create a new Route

func (*Route) Close

func (r *Route) Close()

Close closes this route

func (*Route) Dequeue

func (r *Route) Dequeue() (appmessage.Message, error)

Dequeue dequeues a message from the Route

func (*Route) DequeueWithTimeout

func (r *Route) DequeueWithTimeout(timeout time.Duration) (appmessage.Message, error)

DequeueWithTimeout attempts to dequeue a message from the Route and returns an error if the given timeout expires first.

func (*Route) Enqueue

func (r *Route) Enqueue(message appmessage.Message) error

Enqueue enqueues a message to the Route

func (*Route) MaybeEnqueue

func (r *Route) MaybeEnqueue(message appmessage.Message) error

MaybeEnqueue enqueues a message to the route, but doesn't throw an error if it's closed or its capacity has been reached.

type Router

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

Router routes messages by type to their respective input channels

func NewRouter

func NewRouter(name string) *Router

NewRouter creates a new empty router

func (*Router) AddIncomingRoute

func (r *Router) AddIncomingRoute(name string, messageTypes []appmessage.MessageCommand) (*Route, error)

AddIncomingRoute registers the messages of types `messageTypes` to be routed to the given `route`

func (*Router) AddIncomingRouteWithCapacity

func (r *Router) AddIncomingRouteWithCapacity(name string, capacity int, messageTypes []appmessage.MessageCommand) (*Route, error)

AddIncomingRouteWithCapacity registers the messages of types `messageTypes` to be routed to the given `route` with a capacity of `capacity`

func (*Router) Close

func (r *Router) Close()

Close shuts down the router by closing all registered incoming routes and the outgoing route

func (*Router) EnqueueIncomingMessage

func (r *Router) EnqueueIncomingMessage(message appmessage.Message) error

EnqueueIncomingMessage enqueues the given message to the appropriate route

func (*Router) OutgoingRoute

func (r *Router) OutgoingRoute() *Route

OutgoingRoute returns the outgoing route

func (*Router) RemoveRoute

func (r *Router) RemoveRoute(messageTypes []appmessage.MessageCommand) error

RemoveRoute unregisters the messages of types `messageTypes` from the router

Jump to

Keyboard shortcuts

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