routerpkg

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 6 Imported by: 15

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 = 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 = New(false, "route capacity has been reached")
)

Functions

func Errorf

func Errorf(shouldBan bool, format string, args ...interface{}) error

Errorf formats according to a format specifier and returns the string as a ProtocolError.

func New

func New(shouldBan bool, message string) error

New returns a ProtocolError with the supplied message. New also records the stack trace at the point it was called.

func Wrap

func Wrap(shouldBan bool, err error, message string) error

Wrap wraps the given error and returns it as a ProtocolError.

func Wrapf

func Wrapf(shouldBan bool, err error, format string, args ...interface{}) error

Wrapf wraps the given error with the given format and returns it as a ProtocolError.

Types

type OnRouteCapacityReachedHandler

type OnRouteCapacityReachedHandler func()

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

type ProtocolError

type ProtocolError struct {
	ShouldBan bool
	Cause     error
}

func (ProtocolError) Error

func (e ProtocolError) Error() string

func (ProtocolError) Unwrap

func (e ProtocolError) Unwrap() error

Unwrap returns the cause of ProtocolError, to be used with `errors.Unwrap()`

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