composition

package
v0.0.0-...-5a170ab Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2016 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(handlers ...bh.Handler) bh.Handler

All composes handlers in a pipeline with the same sequence. An incoming message is passed to the i'th handler, if the (i-1)'th handler has successfully processed the incoming message.

If any of these handlers returns an error, the whole transaction will be aborted, meaning that a message is either processed by all of these handlers or none of them.

func Any

func Any(handlers ...bh.Handler) bh.Handler

Any composes handlers as a logic OR function. An incoming message is passed to the i'th handler, if the (i-1)'th handler cannot successfully process the incoming message. Note that the map functions should never drop the packet or panic.

Types

type ComposeFunc

type ComposeFunc func(msg bh.Msg, ctx bh.RcvContext, err error) Step

ComposeFunc implements a single step for a ComposedHandler. At step i, the ComposedHandler calls handler i, and then invokes this function with the msg, the receiver context and the error of calling the handler (if any). The ComposeFunc in response tells the ComposedHandler how to proceed.

type ComposedHandler

type ComposedHandler struct {
	Handlers []bh.Handler // handlers to be composed.
	Composer ComposeFunc  // the Composer.
	Isolate  bool         // whether to isolate the dictionaries.
}

ComposedHandler composes a set of handlers (ie, Handlers) using the Composer.

func (*ComposedHandler) Map

func (c *ComposedHandler) Map(msg bh.Msg, ctx bh.MapContext) bh.MappedCells

Map method of the composed handler.

func (*ComposedHandler) Rcv

func (c *ComposedHandler) Rcv(msg bh.Msg, ctx bh.RcvContext) error

Rcv method of the composed handler.

type Step

type Step int
const (
	// Continue means that the composer should continue to the next handler,
	// leaving the transcation open. If all handlers are already called, continue
	// results either in a commit if there no error, or otherwise in an abort.
	Continue Step = iota
	// Abort means that the composer should immidiately abort the transaction and
	// return.
	Abort
	// Commit means that the composer should immmidiately commit the transcation
	// and return.
	Commit
	// ContinueOrAbort acts similar to Coninue except, when there is no handlers
	// left, it will result in an abort.
	ContinueOrAbort
)

func ComposeAll

func ComposeAll(msg bh.Msg, ctx bh.RcvContext, err error) Step

ComposeAll is a ComposeFunc that aborts when there is an error, and continues otherwise.

func ComposeAny

func ComposeAny(msg bh.Msg, ctx bh.RcvContext, err error) Step

ComposeAny is a ComposeFunc that Commit's when is no error, and ContinueOrAbort's if there is an error.

Jump to

Keyboard shortcuts

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