Class: Fbp::Flow_node
Overview
Description
The flow node provides the ability of taking a network of Fbp nodes and wrap that network in a single node. This is done by creating a Flow description record. A Flow description record is a data structure that describes an entire network of Fbp noes. Given a Flow description record the Flow node class will create the entire network and then wrap that network so that writing to the input of a Flow node instance will forward that input to the first node in the created network. The output of the created network will be forwarded to the output of the Flow node instance.
There are module functions associated with the Flow node class. These functions provide the ability to take a Fbp network and create a Flow description record that describes the network. There are also functions that take a Flow description record and write them to the file system and read a file with a Flow description record and re-create the Flow description record.
Discussion
A Flow description record is an Array of Hashes with the following keys
Flow Description Record
[{:node => symbol_of_the_Fbp_node_class_name, :options =>{class_specific_hash}, :input => nil || [{index => output_channel_name_symbol}]}]
:node This is a symbol that is the name of the Fbp node to be instantiated.
:options This is a hash which is the IIP needed to parameterize the newly instantiated node.
:input This is either nil or an array of hashes. Each hash is keyed by the index in the array of nodes that are described by the Flow Description Record with the value being the symbol name of the output channel from which to get the input for the node.
Example Flow Description Record
The following is a simple network that will read in a file and split the file into two based upon a selector. The two outputs are sorted using the Sort Node and the output of the two different data streams and then writen out to different two files.
======================================================
| {:selectors=>[{:data=>{:comparison=>Fbp::CONTAINS, |
============== | {:comparison=>Fbp::CONTAINS, :value=>"Magic", |
| ~/input.txt |=== | :match=>:magic, :reject=>:output}}] |
============== | ======================================================
| (IIP) | (IIP)
\/ \/
============================== ======================
| | output to input | |
| Fbp::Test_file_reader_node |==================> | Fbp::Selector_node |
| | | |
============================== ======================
| |
output to input | |
===================================================== |
| magic to input |
| =========================================================
| |
| |
| |
| | ======================= ================================================================
| | | {:sort_keys=>:data} | | {:file_name=>"/Users/local/magic.txt", :file_open_mode=>"w"} |
| | ======================= ================================================================
| | | (IIP) | (IIP)
| | \/ \/
| | =================== =============================
| ==> | "Fbp::Sort_node |=================>| Fbp::Text_file_writer_node |===> nil
| =================== =============================
|
| ======================= =================================================================
| | {:sort_keys=>:data} | | {:file_name=>"/Users/local/muggle.txt", :file_open_mode=>"w"} |
| ======================= =================================================================
| | (IIP) | (IIP)
| \/ \/
| =================== ==============================
====> | "Fbp::Sort_node |================>| Fbp::Text_file_writer_node | ===> nil
=================== ==============================
The beginning node in this network is the Fbp::Test_file_reader_node node. If that node is used to call The Fbp::make_flow_description function, the following will be returned.
[
:options=>{:file_name=>“/Users/local/input.txt”, :input=>nil},
:options=>{:selectors=>[{:data=>{:comparison=>6, :value=>“Magic”, :match=>:magic, :reject=>:output}]}, :input=>},
:options=>{:sort_keys=>:data, :input=>},
:options=>{:file_name=>“/Users/local/muggle.txt”, :file_open_mode=>“w”, :input=>},
:options=>{:sort_keys=>:data, :input=>},
:options=>{:file_name=>“/Users/local/magic.txt”, :file_open_mode=>“w”, :input=>}
]
There are some important things to note about this Flow Description Record. Each node is represented by a Hash. That hash has three items as noted previously. The order of the hashes in the array is important. It allows the :input key to be based upon the index of the node from which the referring node will receive its input.
For example the Fbp::Selector_node which is the second node in the array will receive its input from the Fbp::Test_file_reader_node node which is the first node in the array. This is denoted by the :input => [0=>:output] key value pair hash that defines the Fbp::Selector_node. This reads as The input of the Fbp::Selector_node comes form the node defined in the zeroth position of the Flow Description Record and takes its input from the output channel of that node
Future Development
Many FBP solutions have a visual configuration tool to form networks from existing nodes. The Flow node could be used in conjunction with a drawing tool to allow for non-programmer development of networks. This is an area that should be pursued.
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
-
#do_node_work(args) ⇒ Object
This will forward the do_node_work method to the first node in the network being serviced by this Flow_node instance.
-
#execute ⇒ Object
This will forward the execute method to the first node in the network being serviced by this Flow_node instance.
-
#initialize(flow_desc = nil) ⇒ Flow_node
constructor
When creating a new Flow_node instance one can optionally provide a flow description record.
-
#is_ready_to_run? ⇒ Boolean
Checks to see if this Flow_node instance has a flow description record.
-
#register_for_output_from_node(node, output_channel = :output) ⇒ Object
This will forward the register request to the last node in the network being serviced by this Flow_node instance.
-
#wait_until_completed ⇒ Object
This will forward the wait_until_completed method to the last node in the network being serviced by this Flow_node instance.
-
#write_to_input(obj) ⇒ Object
This will write to the first object in the network being serviced by this Flow_node instance.
Methods inherited from Node
#clean_option, #merge_options!, #set_option, #stop, #unregister_for_output_from_node, #write_to_output
Constructor Details
#initialize(flow_desc = nil) ⇒ Flow_node
When creating a new Flow_node instance one can optionally provide a flow description record.
244 245 246 247 248 249 |
# File 'lib/fbp/flow-node.rb', line 244 def initialize(flow_desc = nil) super() [:flow_desc] = flow_desc @flow_created = false @node_objects = Array.new end |
Instance Method Details
#do_node_work(args) ⇒ Object
This will forward the do_node_work method to the first node in the network being serviced by this Flow_node instance.
Discussion
Should a way be provided to set which node in the network is the ‘first’ node?
322 323 324 325 |
# File 'lib/fbp/flow-node.rb', line 322 def do_node_work(args) node = @node_objects.first node.do_node_work(args) if !node.nil? end |
#execute ⇒ Object
This will forward the execute method to the first node in the network being serviced by this Flow_node instance.
Discussion
Should a way be provided to set which node in the network is the ‘first’ node?
308 309 310 311 312 |
# File 'lib/fbp/flow-node.rb', line 308 def execute make_flow if !@flow_created node = @node_objects.first node.execute if !node.nil? end |
#is_ready_to_run? ⇒ Boolean
Checks to see if this Flow_node instance has a flow description record. If the does have a flow description record then true will be returned otherwise false. A Flow_node instance will not execute until it has a low description record.
257 258 259 |
# File 'lib/fbp/flow-node.rb', line 257 def is_ready_to_run? .has_key? :flow_desc end |
#register_for_output_from_node(node, output_channel = :output) ⇒ Object
This will forward the register request to the last node in the network being serviced by this Flow_node instance.
Discussion
Should a way be provided to set which node in the network is the ‘last’ node?
282 283 284 285 |
# File 'lib/fbp/flow-node.rb', line 282 def register_for_output_from_node(node, output_channel = :output) last_name = @node_objects.last last_name.register_for_output_from_node(node, output_channel) if !last_name.nil? && node.nil? end |
#wait_until_completed ⇒ Object
This will forward the wait_until_completed method to the last node in the network being serviced by this Flow_node instance.
Discussion
Should a way be provided to set which node in the network is the ‘last’ node?
295 296 297 298 |
# File 'lib/fbp/flow-node.rb', line 295 def wait_until_completed node = @node_objects.last node.wait_until_completed if !node.nil? end |
#write_to_input(obj) ⇒ Object
This will write to the first object in the network being serviced by this Flow_node instance.
Discussion
Should a way be provided to set which node in the network is the ‘first’ node?
269 270 271 272 |
# File 'lib/fbp/flow-node.rb', line 269 def write_to_input(obj) node = @node_objects.first node.input_queue << obj if !node.nil? && !obj.nil? end |