Documentation ¶
Overview ¶
The flow package is a framework for Flow-based programming in Go.
Index ¶
- Constants
- Variables
- func Annotate(componentName string, info ComponentInfo) bool
- func Factory(componentName string) interface{}
- func NewGraph() interface{}
- func Register(componentName string, constructor ComponentConstructor) bool
- func RegisterJSON(componentName, filePath string) bool
- func RunNet(i interface{})
- func RunProc(c interface{}) bool
- func StopProc(c interface{}) bool
- func Unregister(componentName string) bool
- func UpdateComponentInfo(componentName string) bool
- type Canvas
- type Component
- type ComponentConstructor
- type ComponentEntry
- type ComponentInfo
- type Finalizable
- type Graph
- func (n *Graph) Add(c interface{}, name string) bool
- func (n *Graph) AddGraph(name string) bool
- func (n *Graph) AddIIP(data interface{}, processName, portName string) bool
- func (n *Graph) AddNew(componentName string, processName string) bool
- func (n *Graph) AnnotateInPort(name string, info PortInfo) bool
- func (n *Graph) AnnotateOutPort(name string, info PortInfo) bool
- func (n *Graph) Connect(senderName, senderPort, receiverName, receiverPort string) bool
- func (n *Graph) ConnectBuf(senderName, senderPort, receiverName, receiverPort string, bufferSize int) bool
- func (n *Graph) DecSendChanRefCount(c reflect.Value) bool
- func (n *Graph) Disconnect(senderName, senderPort, receiverName, receiverPort string) bool
- func (n *Graph) Get(processName string) interface{}
- func (n *Graph) IncSendChanRefCount(c reflect.Value)
- func (n *Graph) InitGraphState()
- func (n *Graph) MapInPort(name, procName, procPort string) bool
- func (n *Graph) MapOutPort(name, procName, procPort string) bool
- func (n *Graph) Ready() <-chan struct{}
- func (n *Graph) Remove(processName string) bool
- func (n *Graph) RemoveIIP(processName, portName string) bool
- func (n *Graph) Rename(processName, newName string) bool
- func (n *Graph) RenameInPort(oldName, newName string) bool
- func (n *Graph) RenameOutPort(oldName, newName string) bool
- func (n *Graph) RunProc(procName string) bool
- func (n *Graph) SetInPort(name string, channel interface{}) bool
- func (n *Graph) SetOutPort(name string, channel interface{}) bool
- func (n *Graph) Stop()
- func (n *Graph) StopProc(procName string) bool
- func (n *Graph) UnmapInPort(name string) bool
- func (n *Graph) UnmapOutPort(name string) bool
- func (n *Graph) UnsetInPort(name string) bool
- func (n *Graph) UnsetOutPort(name string) bool
- func (n *Graph) Wait() <-chan struct{}
- type Initializable
- type Looper
- type Message
- type PortInfo
- type Runtime
- type Shutdowner
Constants ¶
const ( // ComponentModeUndefined stands for a fallback component mode (Async). ComponentModeUndefined = iota // ComponentModeAsync stands for asynchronous functioning mode. ComponentModeAsync // ComponentModeSync stands for synchronous functioning mode. ComponentModeSync // ComponentModePool stands for async functioning with a fixed pool. ComponentModePool )
const DefaultRegistryCapacity = 64
DefaultRegistryCapacity is the capacity component registry is initialized with.
Variables ¶
var ComponentRegistry = make(map[string]ComponentEntry, DefaultRegistryCapacity)
ComponentRegistry is used to register components and spawn processes given just a string component name.
var DefaultBufferSize = 0
DefaultBufferSize is the default channel buffer capacity.
var DefaultComponentMode = ComponentModeAsync
DefaultComponentMode is the preselected functioning mode of all components being run.
var DefaultNetworkCapacity = 32
DefaultNetworkCapacity is the default capacity of network's processes/ports maps.
var DefaultNetworkPortsNum = 16
Default network output or input ports number
Functions ¶
func Annotate ¶
func Annotate(componentName string, info ComponentInfo) bool
Annotate sets component information utilized by runtimes and FBP protocol clients. Recommended fields are: Description and Icon. Other fields are infered by the runtime itself.
func Factory ¶
func Factory(componentName string) interface{}
Factory creates a new instance of a component registered under a specific name.
func NewGraph ¶
func NewGraph() interface{}
NewGraph creates a new canvas graph that can be modified at run-time. Implements ComponentConstructor interace, so can it be used with Factory.
func Register ¶
func Register(componentName string, constructor ComponentConstructor) bool
Register registers a component so that it can be instantiated at run-time using component Factory. It returns true on success or false if component name is already taken.
func RegisterJSON ¶
RegisterJSON registers an external JSON graph definition as a component that can be instantiated at run-time using component Factory. It returns true on success or false if component name is already taken.
func RunNet ¶
func RunNet(i interface{})
RunNet runs the network by starting all of its processes. It runs Init/Finish handlers if the network implements Initializable/Finalizable interfaces.
func RunProc ¶
func RunProc(c interface{}) bool
RunProc runs event handling loop on component ports. It returns true on success or panics with error message and returns false on error.
func StopProc ¶
func StopProc(c interface{}) bool
StopProc terminates the process if it is running. It doesn't close any in or out ports of the process, so it can be replaced without side effects.
func Unregister ¶
Unregister removes a component with a given name from the component registry and returns true or returns false if no such component is registered.
func UpdateComponentInfo ¶
UpdateComponentInfo extracts run-time information about a component and its ports. It is called when an FBP protocol client requests component information.
Types ¶
type Canvas ¶
type Canvas struct {
Graph
}
Canvas is a generic graph that is manipulated at run-time only
type Component ¶
type Component struct { // Is running flag indicates that the process is currently running. IsRunning bool // Net is a pointer to network to inform it when the process is started and over // or to change its structure at run time. Net *Graph // Mode is component's functioning mode. Mode int8 // PoolSize is used to define pool size when using ComponentModePool. PoolSize uint8 // Term chan is used to terminate the process immediately without closing // any channels. Term chan struct{} }
Component is a generic flow component that has to be contained in concrete components. It stores network-specific information.
type ComponentConstructor ¶
type ComponentConstructor func() interface{}
ComponentConstructor is a function that can be registered in the ComponentRegistry so that it is used when creating new processes of a specific component using Factory function at run-time.
type ComponentEntry ¶
type ComponentEntry struct { // Constructor is a function that creates a component instance. // It is required for the factory to add components at run-time. Constructor ComponentConstructor // Run-time component description Info ComponentInfo }
ComponentEntry contains runtime information about a component
type ComponentInfo ¶
type ComponentInfo struct { Name string `json:"name"` Description string `json:"description"` Icon string `json:"icon"` Subgraph bool `json:"subgraph"` InPorts []PortInfo `json:"inPorts"` OutPorts []PortInfo `json:"outPorts"` }
ComponentInfo represents a component to a protocol client
type Finalizable ¶
type Finalizable interface {
Finish()
}
Finalizable is the interface implemented by components/graphs with extra finalization code.
type Graph ¶
type Graph struct { // Net is a pointer to parent network. Net *Graph // contains filtered or unexported fields }
Graph represents a graph of processes connected with packet channels.
func LoadJSON ¶
LoadJSON loads a JSON graph definition file into a flow.Graph object that can be run or used in other networks
func ParseJSON ¶
ParseJSON converts a JSON network definition string into a flow.Graph object that can be run or used in other networks
func (*Graph) Add ¶
Add adds a new process with a given name to the network. It returns true on success or panics and returns false on error.
func (*Graph) AddGraph ¶
AddGraph adds a new blank graph instance to a network. That instance can be modified then at run-time.
func (*Graph) AddNew ¶
AddNew creates a new process instance using component factory and adds it to the network.
func (*Graph) AnnotateInPort ¶
AnnotateInPort sets optional run-time annotation for the port utilized by runtimes and FBP protocol clients.
func (*Graph) AnnotateOutPort ¶
AnnotateOutPort sets optional run-time annotation for the port utilized by runtimes and FBP protocol clients.
func (*Graph) Connect ¶
Connect connects a sender to a receiver and creates a channel between them using DefaultBufferSize. Normally such a connection is unbuffered but you can change by setting flow.DefaultBufferSize > 0 or by using ConnectBuf() function instead. It returns true on success or panics and returns false if error occurs.
func (*Graph) ConnectBuf ¶
func (n *Graph) ConnectBuf(senderName, senderPort, receiverName, receiverPort string, bufferSize int) bool
Connect connects a sender to a receiver using a channel with a buffer of a given size. It returns true on success or panics and returns false if error occurs.
func (*Graph) DecSendChanRefCount ¶
Decrements SendChanRefCount It returns true if the RefCount has reached 0
func (*Graph) Disconnect ¶
Disconnect removes a connection between sender's outport and receiver's inport.
func (*Graph) IncSendChanRefCount ¶
Increments SendChanRefCount
func (*Graph) InitGraphState ¶
func (n *Graph) InitGraphState()
InitGraphState method initializes graph fields and allocates memory.
func (*Graph) MapInPort ¶
MapInPort adds an inport to the net and maps it to a contained proc's port. It returns true on success or panics and returns false on error.
func (*Graph) MapOutPort ¶
MapOutPort adds an outport to the net and maps it to a contained proc's port. It returns true on success or panics and returns false on error.
func (*Graph) Ready ¶
func (n *Graph) Ready() <-chan struct{}
Ready returns a channel that can be used to suspend the caller goroutine until the network is ready to accept input packets
func (*Graph) Remove ¶
Remove deletes a process from the graph. First it stops the process if running. Then it disconnects it from other processes and removes the connections from the graph. Then it drops the process itself.
func (*Graph) Rename ¶
Rename changes a process name in all connections, external ports, IIPs and the graph itself.
func (*Graph) RenameInPort ¶
RenameInPort changes graph's inport name
func (*Graph) RenameOutPort ¶
RenameOutPort changes graph's outport name
func (*Graph) SetInPort ¶
SetInPort assigns a channel to a network's inport to talk to the outer world. It returns true on success or false if the inport cannot be set.
func (*Graph) SetOutPort ¶
SetOutPort assigns a channel to a network's outport to talk to the outer world. It returns true on success or false if the outport cannot be set.
func (*Graph) Stop ¶
func (n *Graph) Stop()
Stop terminates the network without closing any connections
func (*Graph) UnmapInPort ¶
UnmapInPort removes an existing inport mapping
func (*Graph) UnmapOutPort ¶
UnmapOutPort removes an existing outport mapping
func (*Graph) UnsetInPort ¶
UnsetInPort removes an external inport from the graph
func (*Graph) UnsetOutPort ¶
UnsetOutPort removes an external outport from the graph
type Initializable ¶
type Initializable interface {
Init()
}
Initalizable is the interface implemented by components/graphs with custom initialization code.
type Looper ¶
type Looper interface {
Loop()
}
Looper is a long-running process which actively receives data from its ports using a Loop function
type Message ¶
type Message struct { // Protocol is NoFlo protocol identifier: // "runtime", "component", "graph" or "network" Protocol string `json:"protocol"` // Command is a command to be executed within the protocol Command string `json:"command"` // Payload is JSON-encoded body of the message Payload interface{} `json:"payload"` }
Message represents a single FBP protocol message
type PortInfo ¶
type PortInfo struct { Id string `json:"id"` Type string `json:"type"` Description string `json:"description"` Addressable bool `json:"addressable"` // ignored Required bool `json:"required"` Values []interface{} `json:"values"` // ignored Default interface{} `json:"default"` // ignored }
PortInfo represents a port to a runtime client
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime is a NoFlo-compatible runtime implementing the FBP protocol
type Shutdowner ¶
type Shutdowner interface {
Shutdown()
}
Shutdowner is the interface implemented by components overriding default Shutdown() behavior.