Class: Flor::Executor
- Inherits:
-
Object
show all
- Defined in:
- lib/flor/core/executor.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#conf ⇒ Object
-
#counter(key) ⇒ Object
-
#counter_add(key, count) ⇒ Object
-
#counter_next(key) ⇒ Object
-
#exid ⇒ Object
-
#initialize(unit, hooks, traps, execution) ⇒ Executor
constructor
A new instance of Executor.
-
#node(msg_or_nid, node_instance = false) ⇒ Object
-
#traps_and_hooks ⇒ Object
-
#trigger_block(block, opts, message) ⇒ Object
-
#trigger_hook(hook, message) ⇒ Object
-
#trigger_trap(trap, message) ⇒ Object
-
#vars(nid, vs = {}) ⇒ Object
Given a nid, returns a copy of all the var the node sees at that point.
Constructor Details
#initialize(unit, hooks, traps, execution) ⇒ Executor
Returns a new instance of Executor.
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/flor/core/executor.rb', line 12
def initialize(unit, hooks, traps, execution)
@unit = unit
@execution = execution
@hooks = hooks @traps = traps
@htraps = nil
end
|
Instance Attribute Details
#execution ⇒ Object
Returns the value of attribute execution.
8
9
10
|
# File 'lib/flor/core/executor.rb', line 8
def execution
@execution
end
|
#hooks ⇒ Object
Returns the value of attribute hooks.
9
10
11
|
# File 'lib/flor/core/executor.rb', line 9
def hooks
@hooks
end
|
#traps ⇒ Object
Returns the value of attribute traps.
10
11
12
|
# File 'lib/flor/core/executor.rb', line 10
def traps
@traps
end
|
#unit ⇒ Object
Returns the value of attribute unit.
7
8
9
|
# File 'lib/flor/core/executor.rb', line 7
def unit
@unit
end
|
Instance Method Details
#conf ⇒ Object
23
|
# File 'lib/flor/core/executor.rb', line 23
def conf; @unit.conf; end
|
#counter(key) ⇒ Object
45
46
47
48
|
# File 'lib/flor/core/executor.rb', line 45
def counter(key)
@execution['counters'][key.to_s] || -1
end
|
#counter_add(key, count) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/flor/core/executor.rb', line 50
def counter_add(key, count)
k = key.to_s
@execution['counters'][k] ||= 0
@execution['counters'][k] += count
end
|
#counter_next(key) ⇒ Object
58
59
60
61
|
# File 'lib/flor/core/executor.rb', line 58
def counter_next(key)
counter_add(key, 1)
end
|
#exid ⇒ Object
24
|
# File 'lib/flor/core/executor.rb', line 24
def exid; @execution['exid']; end
|
#node(msg_or_nid, node_instance = false) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/flor/core/executor.rb', line 26
def node(msg_or_nid, node_instance=false)
return nil unless msg_or_nid
nid = msg_or_nid
msg = msg_or_nid
if nid.is_a?(String)
msg = nil
else
nid = msg['nid']
end
n = @execution['nodes'][nid]
return nil unless n
node_instance ? Flor::Node.new(self, n, msg) : n
end
|
#traps_and_hooks ⇒ Object
127
128
129
130
131
132
133
134
135
|
# File 'lib/flor/core/executor.rb', line 127
def traps_and_hooks
@htraps = nil if @htraps && @htraps.size != @traps.size
@htraps ||= @traps.collect(&:to_hook)
@hhooks ||= @hooks.collect(&:to_hook)
@htraps + @hhooks
end
|
#trigger_block(block, opts, message) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/flor/core/executor.rb', line 91
def trigger_block(block, opts, message)
r =
case block.arity
when 1 then block.call(message)
when 2 then block.call(message, opts)
else block.call(self, message, opts)
end
r.is_a?(Array) && r.all? { |e| e.is_a?(Hash) } ? r : []
end
|
#trigger_hook(hook, message) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/flor/core/executor.rb', line 71
def trigger_hook(hook, message)
m =
case
when hook.respond_to?(:notify) then :notify
when hook.respond_to?(:on_message) then :on_message
else :on
end
as =
case hook.method(m).arity
when 3 then [ @unit, self, message ]
when 2 then [ self, message ]
else [ message ]
end
r = hook.send(m, *as)
Flor.is_array_of_messages?(r) ? r : []
end
|
#trigger_trap(trap, message) ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/flor/core/executor.rb', line 63
def trigger_trap(trap, message)
del, msgs = trap.trigger(self, message)
@traps.delete(trap) if del
msgs
end
|
#vars(nid, vs = {}) ⇒ Object
Given a nid, returns a copy of all the var the node sees at that point.
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/flor/core/executor.rb', line 106
def vars(nid, vs={})
n = node(nid); return vs unless n
(n['vars'] || {})
.each { |k, v| vs[k] = Flor.dup(v) unless vs.has_key?(k) }
pnid = n['parent']
if @unit.loader && pnid == nil && n['vdomain'] != false
@unit.loader.variables(n['vdomain'] || Flor.domain(@exid))
.each { |k, v| vs[k] = Flor.dup(v) unless vs.has_key?(k) }
end
if cn = n['cnid']; vars(cn, vs); end
vars(pnid, vs) if pnid
vs
end
|