Documentation ¶
Overview ¶
Package fer provides a basic framework to run FairMQ-like processes. Clients create fer Devices that exchange data via fer message queue sockets.
A client device might look like so:
import "github.com/alice-go/fer" import "github.com/alice-go/fer/config" type myDevice struct { cfg config.Device imsg chan fer.Msg omsg chan fer.Msg }
A device needs to implement the fer.Device interface:
func (dev *myDevice) Run(ctl fer.Controller) error { ... }
Optionnally, the following methods may be also implemented:
func (dev *myDevice) Configure(cfg config.Device) error { ... } func (dev *myDevice) Init(ctl fer.Controller) error { ... } func (dev *myDevice) Pause(ctl fer.Controller) error { ... } func (dev *myDevice) Reset(ctl fer.Controller) error { ... }
Typically, the Configure method is used to retrieve the configuration associated with the client's device. The Init method is used to retrieve the channels of input/output data messages. The Run method is an infinite for-loop, selecting on these input/output data messages. This infinite for-loop will also NEED to listen for the Controller.Done() channel to exit that for-loop.
e.g.:
func (dev *myDevice) Init(ctl fer.Controller) error { imsg, err := ctl.Chan("data-1", 0) omsg, err := ctl.Chan("data-2", 0) dev.imsg = imsg dev.omsg = omsg return nil } func (dev *myDevice) Run(ctl fer.Controller) error { for { select { case data := <-dev.imsg: dev.omsg <- bytes.Repeat(data, 2) case <-ctl.Done(): return nil } } }
Then, to create an executable:
package main func main() { err := fer.Main(&myDevice{}) if err != nil { log.Fatal(err) } }
Build it as usual and run like so:
$> go build -o my-device $> ./my-device --help Usage of my-device: -control string starts device in interactive/static mode (default "interactive") -id string device ID -mq-config string path to JSON file holding device configuration -transport string transport mechanism to use (zeromq, nanomsg, go-chan, ...) (default "zeromq") $> ./my-device --id my-id --mq-config ./path/to/config.json
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cmd ¶
type Cmd byte
Cmd describes commands to be sent to a device, via a channel.
const ( // CmdInitDevice is the command sent to initialize a device CmdInitDevice Cmd = iota // CmdInitTask is the command sent to initialize the tasks of a device CmdInitTask // CmdRun is the command sent to run a device CmdRun // CmdPause is the command sent to pause the execution of a device CmdPause // CmdStop is the command sent to stop the execution of a device CmdStop // CmdResetTask is the command sent to reset the state of the tasks of a device CmdResetTask // CmdResetDevice is the command sent to reset the state of a device CmdResetDevice // CmdEnd is the command sent to end a device CmdEnd // CmdError is the command sent to notify of an error CmdError )
type Controller ¶
type Controller interface { Logger Chan(name string, i int) (chan Msg, error) Done() chan Cmd // contains filtered or unexported methods }
Controller controls devices execution and gives a device access to input and output data channels.
type DevConfigurer ¶
type DevConfigurer interface { // Configure hands a device its configuration. Configure(cfg config.Device) error }
DevConfigurer configures a fer device.
type DevIniter ¶
type DevIniter interface { // Init gives a chance to the device to initialize internal // data structures, retrieve channels to input/output data. Init(ctl Controller) error }
DevIniter initializes a fer device.
type DevPauser ¶
type DevPauser interface { // Pause pauses the device's execution. Pause(ctl Controller) error }
DevPauser pauses the execution of a fer device.
type DevReseter ¶
type DevReseter interface { // Reset resets the device's internal state. Reset(ctl Controller) error }
DevReseter resets a fer device.
type Device ¶
type Device interface { // Run is where the device's main activity happens. // Run should loop forever, until the Controller.Done() channel says // otherwise. Run(ctl Controller) error }
Device is a handle to what users get to run via the Fer toolkit.
Devices are configured according to command-line flags and a JSON configuration file. Clients need to implement the Run method to receive and send data via the Controller data channels.
Directories ¶
Path | Synopsis |
---|---|
_example
|
|
cmd
|
|
fer-json-fmt
fer-json-fmt format JSON configuration files following the one true style.
|
fer-json-fmt format JSON configuration files following the one true style. |
fer-json-validate
fer-json-validate validates JSON configuration files honor FairMQ's JSON schema.
|
fer-json-validate validates JSON configuration files honor FairMQ's JSON schema. |
Package config implements command-line flag parsing and fer devices configuration from JSON files.
|
Package config implements command-line flag parsing and fer devices configuration from JSON files. |
Package mq provides interfaces for message-queue sockets.
|
Package mq provides interfaces for message-queue sockets. |
nanomsg
Package nanomsg implements the mq.Driver interface and allows to use mq.Sockets via nanomsg sockets.
|
Package nanomsg implements the mq.Driver interface and allows to use mq.Sockets via nanomsg sockets. |
zeromq
Package zeromq implements the mq.Driver interface and allows to use mq.Sockets via ZeroMQ sockets.
|
Package zeromq implements the mq.Driver interface and allows to use mq.Sockets via ZeroMQ sockets. |