Documentation ¶
Overview ¶
Package behaviors provides several generic and always useful standard behaviors for the Tideland Go Cells. They are simply created by calling NewXyzBehavior(). Their configuration is done by constructor arguments. Additionally some of them take functions or implementations of interfaces to control their processing. These behaviors are:
Broadcaster ¶
The broadcaster behavior simply emits all received events to all of its subscribers. It is intended to be used as a top level behavior to directly rigger multiple handlers instead of emitting an event manually to those handlers.
Callback ¶
The callback behavior allows you to provide a number of functions which will be called when an event is received. Those functions have the topic and the payload of the event as argument.
Collector ¶
The collector behavior collects all received events. They can be retrieved and resetted. It also emits all received events to its subscribers.
Configurator ¶
After receiving a ReadConfigurationTopic with a filename as payload the configuration behavior reads this configuration and emits it. If it is started with a validator the configuration is validated after the reading.
Counter ¶
The counter behavior is created with a counter function as argument. This function is called for each event and returns the IDs of counters which are incremented then. The counters are emitted each time and also can be resetted.
Filter ¶
The filter behavior is created with a filtering function which is called for each event. If this function call returns true the event emitted, otherwise it is dropped.
Finite State Machine ¶
The FSM behavior implements a finite state machine. State functions process the events and return the following state function.
Logger ¶
The logger behavior logs every event. The used level is INFO.
Mapper ¶
The mapper behavior is created with a mapping. It is called with each received event and returns a new mapped one.
Round Robin ¶
The round robin behavior distributes each received event round robin to its subscribers. It can be used for load balancing.
Scene ¶
The scene behavior stores a received payload using the event topic as key in the event scene. So it can be used later by other behaviors or by the external environments, which can wait until the setting.
Simple Processor ¶
The simple behavior is created with a simple event processing function. Useful if no state and no complex recovery is needed.
Ticker ¶
The ticker behavior emits a tick event in a defined interval to its subscribers. So they can process chronological tasks beside other events.
Index ¶
- Constants
- func Configuration(event cells.Event) configuration.Configuration
- func NewBroadcasterBehavior() cells.Behavior
- func NewCallbackBehavior(cbfs ...CallbackFunc) cells.Behavior
- func NewCollectorBehavior(max int) cells.Behavior
- func NewConfiguratorBehavior(validator ConfigurationValidator) cells.Behavior
- func NewCounterBehavior(cf CounterFunc) cells.Behavior
- func NewFSMBehavior(state FSMState) cells.Behavior
- func NewFilterBehavior(ff FilterFunc) cells.Behavior
- func NewLoggerBehavior() cells.Behavior
- func NewMapperBehavior(mf MapFunc) cells.Behavior
- func NewRoundRobinBehavior() cells.Behavior
- func NewRouterBehavior(rf RouterFunc) cells.Behavior
- func NewSceneBehavior() cells.Behavior
- func NewSimpleProcessorBehavior(spf SimpleProcessorFunc) cells.Behavior
- func NewTickerBehavior(duration time.Duration) cells.Behavior
- func PackageVersion() version.Version
- type CallbackFunc
- type ConfigurationValidator
- type CounterFunc
- type Counters
- type EventData
- type FSMState
- type FSMStatus
- type FilterFunc
- type MapFunc
- type RouterFunc
- type SimpleProcessorFunc
Constants ¶
const ( // Topics. ReadConfigurationTopic = "read-configuration!" ConfigurationTopic = "configuration" TickerTopic = "tick!" // Payload keys. ConfigurationFilenamePayload = "configuration:filename" ConfigurationPayload = "configuration" TickerIDPayload = "ticker:id" TickerTimePayload = "ticker:time" )
const ( ErrCannotReadConfiguration = iota + 1 ErrCannotValidateConfiguration )
Error codes.
Variables ¶
This section is empty.
Functions ¶
func Configuration ¶
func Configuration(event cells.Event) configuration.Configuration
Configuration returns the configuration payload of the passed event or an empty configuration.
func NewBroadcasterBehavior ¶
NewBroadcasterBehavior creates a broadcasting behavior that just emits every received event. It's intended to work as an entry point for events, which shall be immediately processed by several subscribers.
func NewCallbackBehavior ¶
func NewCallbackBehavior(cbfs ...CallbackFunc) cells.Behavior
NewCallbackBehavior creates a behavior with a number of callback functions. Each time an event is received those functions are called in the same order they have been passed.
func NewCollectorBehavior ¶
NewCollectorBehaviorFactory creates a collector behavior. It collects a configured maximum number events emitted directly or by subscription. The event is passed through. The collected events can be requested with the topic "collected?" and will be stored in the scene store named in the events payload. Additionally the collection can be resetted with "reset!".
func NewConfiguratorBehavior ¶
func NewConfiguratorBehavior(validator ConfigurationValidator) cells.Behavior
NewConfiguratorBehavior creates the configurator behavior. It loads a configuration file and emits the it to its subscribers. If a validator is passed the read configuration will be validated using it. Errors will be logged.
func NewCounterBehavior ¶
func NewCounterBehavior(cf CounterFunc) cells.Behavior
NewCounterBehavior creates a counter behavior based on the passed function. It increments and emits those counters named by the result of the counter function. The counters can be retrieved with the request "counters?" and reset with "reset!".
func NewFSMBehavior ¶
NewFSMBehavior creates a finite state machine behavior based on the passed initial state function. The function is called with the event has to return the next state, which can be the same one. In case of nil the stae will be transfered into a generic end state, if an error is returned the state is a generic error state.
func NewFilterBehavior ¶
func NewFilterBehavior(ff FilterFunc) cells.Behavior
NewFilterBehavior creates a filter behavior based on the passed function. It emits every received event for which the filter function returns true.
func NewLoggerBehavior ¶
NewLoggerBehavior creates a logging behavior. It logs emitted events with info level.
func NewMapperBehavior ¶
NewMapperBehavior creates a map behavior based on the passed function. It emits the mapped events.
func NewRoundRobinBehavior ¶
NewRoundRobinBehavior creates a behavior emitting the received events to its subscribers in a very simple way. Subscriptions or unsubscriptions during runtime may influence the order.
func NewRouterBehavior ¶
func NewRouterBehavior(rf RouterFunc) cells.Behavior
NewRouterBehavior creates a router behavior using the passed function to determine to which subscriber the received event will be emitted.
func NewSceneBehavior ¶
NewSceneBehavior creates a scene behavior that stores the payload of an event using the topic of an event as key in its scene. This way external code can wait for this topic as flag and fetch the value. It's not intended to use it as a standard behvior, even if it works. Instead it can be used in testing scenarios.
func NewSimpleProcessorBehavior ¶
func NewSimpleProcessorBehavior(spf SimpleProcessorFunc) cells.Behavior
NewSimpleProcessorBehavior creates a filter behavior based on the passed function. Instead of an own logic and an own state it uses the passed simple processor function for the event processing.
func NewTickerBehavior ¶
NewTickerBehavior creates a ticker behavior.
func PackageVersion ¶
PackageVersion returns the version of the version package.
Types ¶
type CallbackFunc ¶
CallbackFunc is a function called by the behavior when it recieves an event.
type ConfigurationValidator ¶
type ConfigurationValidator func(configuration.Configuration) error
ConfigurationValidator defines a function for the validation of a new read configuration.
type CounterFunc ¶
CounterFunc is the signature of a function which analyzis an event and returns, which counters shall be incremented.
type FSMState ¶
FSMState is the signature of a function or method which processes an event and returns the following state or an error.
type FSMStatus ¶
FSMStatus contains information about the current status of the FSM.
func RequestFSMStatus ¶
func RequestFSMStatus(env cells.Environment, id string) FSMStatus
RequestFSMStatus retrieves the status of a FSM cell.
type FilterFunc ¶
FilterFunc is a function type checking if an event shall be filtered.
type RouterFunc ¶
RouterFunc is a function type determinig which subscribed cells shall receive the event.