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
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
Key returns a key value that all requests dispatched to the child's requests channel will have.
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.