Class: OFlow::Flow
- Inherits:
-
Object
- Object
- OFlow::Flow
- Includes:
- HasErrorHandler, HasLinks, HasLog, HasName, HasTasks
- Defined in:
- lib/oflow/flow.rb
Overview
The Class used to managing interactions between Tasks and sub-Flows. It can be thought of as a container for Tasks where the Flow keeps track of the Links between the Tasks.
Instance Attribute Summary
Attributes included from HasName
Instance Method Summary collapse
- #_clear ⇒ Object
-
#describe(detail = 0, indent = 0) ⇒ Object
Returns a String describing the Flow.
-
#has_input(op) ⇒ Object
Returns true if the Flow has a Link identified by the op.
-
#initialize(flow, name, options) ⇒ Flow
constructor
Create a new Flow.
-
#receive(op, box) ⇒ Object
Receive a request which is redirected to a Linked target Task.
-
#route(label, task_name, op) ⇒ Object
Add a Link from the edge of the Flow to a Task contained in the Flow.
Methods included from HasLog
#debug, #error, #fatal, #info, #log, #log=, #log_msg, #warn
Methods included from HasErrorHandler
#error_handler, #error_handler=, #handle_error
Methods included from HasName
Methods included from HasLinks
#find_link, #has_links?, #init_links, #link, #links, #resolve_link, #set_link_target
Methods included from HasTasks
#_locate, #_validation_errors, #busy?, #clear, #each_task, #find_task, #flow, #flush, #init_tasks, #locate, #queue_count, #resolve_all_links, #shutdown, #start, #state=, #step, #stop, #task, #task_count, #validate, #wakeup, #walk_tasks
Constructor Details
#initialize(flow, name, options) ⇒ Flow
Create a new Flow.
18 19 20 21 22 |
# File 'lib/oflow/flow.rb', line 18 def initialize(flow, name, ) init_name(flow, name) init_tasks() init_links() end |
Instance Method Details
#_clear ⇒ Object
71 72 |
# File 'lib/oflow/flow.rb', line 71 def _clear() end |
#describe(detail = 0, indent = 0) ⇒ Object
Returns a String describing the Flow.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/oflow/flow.rb', line 54 def describe(detail=0, indent=0) i = ' ' * indent lines = ["#{i}#{name} (#{self.class}) {"] @tasks.each_value { |t| lines << t.describe(detail, indent + 2) } @links.each { |local,link| if link.ingress lines << " #{i}#{local} * #{link.target_name}:#{link.op}" else lines << " #{i}#{local} => #{link.target_name}:#{link.op}" end } lines << i + "}" lines.join("\n") end |
#has_input(op) ⇒ Object
Returns true if the Flow has a Link identified by the op.
47 48 49 |
# File 'lib/oflow/flow.rb', line 47 def has_input(op) !find_link(op).nil? end |
#receive(op, box) ⇒ Object
Receive a request which is redirected to a Linked target Task.
38 39 40 41 42 43 |
# File 'lib/oflow/flow.rb', line 38 def receive(op, box) box = box.receive(full_name, op) lnk = find_link(op) raise LinkError.new(op) if lnk.nil? || lnk.target.nil? lnk.target.receive(lnk.op, box) end |
#route(label, task_name, op) ⇒ Object
Add a Link from the edge of the Flow to a Task contained in the Flow.
28 29 30 31 32 33 |
# File 'lib/oflow/flow.rb', line 28 def route(label, task_name, op) op = op.to_sym unless op.nil? label = label.to_sym unless label.nil? raise ConfigError.new("Link #{label} already exists.") unless find_link(label).nil? @links[label] = Link.new(task_name.to_sym, op, true) end |