Class: OFlow::Flow

Inherits:
Object
  • Object
show all
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

#name

Instance Method Summary collapse

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

#full_name, #init_name

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.

Parameters:

  • flow (Flow)

    Flow containing the Flow

  • name (name)

    Flow base name

  • options (Hash)

    additional options for the Flow



18
19
20
21
22
# File 'lib/oflow/flow.rb', line 18

def initialize(flow, name, options)
  init_name(flow, name)
  init_tasks()
  init_links()
end

Instance Method Details

#_clearObject



71
72
# File 'lib/oflow/flow.rb', line 71

def _clear()
end

#describe(detail = 0, indent = 0) ⇒ Object

Returns a String describing the Flow.

Parameters:

  • detail (Fixnum) (defaults to: 0)

    higher values result in more detail in the description

  • indent (Fixnum) (defaults to: 0)

    the number of spaces to indent the description



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.

Parameters:

  • op (Symbol)

    identifies the Link in question



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.

Parameters:

  • op (Symbol)

    identifies the link that points to the destination Task or Flow

  • box (Box)

    contents or data for the request

Raises:



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.

Parameters:

  • label (Symbol|String)

    identifier for the Link

  • task_name (Symbol|String)

    _name base name of teh Task to link to

  • op (Symbol|String)

    operation to call when forwarding a request to the target Task

Raises:



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