dispatcher

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2021 License: Apache-2.0 Imports: 6 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithChildSpec added in v0.14.0

func WithChildSpec(childSpec ChildSpec) option

WithChildSpec provides an optional dispatcher child spec passed by an upstream dispatcher when creating a child. Using this option a hierarchy of dispatchers can be built.

func WithFinalizer added in v0.14.0

func WithFinalizer(finalizer func()) option

WithFinalizer if provided then this function should be called before the dispatcher terminates.

Types

type ChildSpec added in v0.14.0

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

ChildSpec is a data structure passed to Factory.SpawnChild.

func NewChildSpec4Test added in v0.14.0

func NewChildSpec4Test(requests chan consumer.Request) ChildSpec

NewChildSpec4Test creates a ChildSpec to be used in testing.

func (*ChildSpec) Dispose added in v0.14.0

func (cs *ChildSpec) Dispose()

Dispose is a function that should be called when all child operation goroutine are stopped and it is ready to be garbage collected.

func (*ChildSpec) Key added in v0.14.0

func (cs *ChildSpec) Key() Key

Key returns a key value that all requests dispatched to the child's requests channel will have.

func (*ChildSpec) Requests added in v0.14.0

func (cs *ChildSpec) Requests() <-chan consumer.Request

Requests returns a channel that dispatcher will send requests for this child to. The child is supposed to read from this channel. If the parent dispatcher closes the channel it means that the child should stop.

type Factory

type Factory interface {
	// KeyOf returns a key of a child that should server the specified request.
	KeyOf(rq consumer.Request) Key

	// SpawnChild creates and starts a new child instance that should read and
	// handle requests from requestsCh. The requests sent down to the channel
	// by the dispatcher are guaranteed to have the specified key.
	//
	// If a child stops/dies for any reason (e.g. expired, fatally failed, or
	// explicitly ordered to stop) it must send itself down to disposalCh to
	// let the parent dispatcher know, that it no longer handles requests.
	//
	// A child must not close either of the provided channels, otherwise the
	// dispatcher will panic.
	SpawnChild(childSpec ChildSpec)
}

Factory defines an interface to create dispatcher children.

type Key added in v0.14.0

type Key string

Key uniquely identifies a child that should handle a particular request.

type T

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

T dispatcher requests to child nodes based on the request key value determined by a factory. It creates child nodes on demand using the factory. Children are obliged to notify the dispatcher when they stop by calling ChildSpec.Dispose() function. If dispatcher sees that a stopped child still has requests to process it will create a successor child.

A dispatcher can be a child of another dispatcher. To do that it needs to be spawned with child spec passed to a child factory by an upstream dispatcher.

Only root dispatcher can be explicitly stopped, the rest should only stop if their requests channel is closed or their last child terminated.

func Spawn added in v0.14.0

func Spawn(parentActDesc *actor.Descriptor, factory Factory, cfg *config.Proxy, options ...option) *T

Spawn creates and starts a dispatcher instance with a particular child factory and a proxy config. If the created dispatcher is a child of an upstream dispatcher then it should be initialized with a child spec provided by the upstream dispatcher in Factory.SpawnChild call.

func (*T) Requests

func (d *T) Requests() chan<- consumer.Request

Requests returns a channel to send requests to the dispatcher.

func (*T) Stop

func (d *T) Stop()

Stop terminates a running dispatcher. In a hierarchy of dispatchers only the root dispatcher can be explicitly stopped. An attempt to stop a downstream dispatcher will result in panic.

func (*T) Wait4Stop added in v0.14.0

func (d *T) Wait4Stop(timeout time.Duration) bool

Wait4Stop blocks until the dispatcher terminates. It is supposed to be used with downstream dispatchers (not root) that cannot be stopped explicitly.

Jump to

Keyboard shortcuts

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