Class: Flor::TransientExecutor

Inherits:
Executor
  • Object
show all
Defined in:
lib/flor/core/texecutor.rb

Direct Known Subclasses

ConfExecutor

Defined Under Namespace

Classes: TransientLogger, TransientUnit

Instance Attribute Summary

Attributes inherited from Executor

#execution, #hooks, #traps, #unit

Instance Method Summary collapse

Methods inherited from Executor

#conf, #counter, #counter_add, #counter_next, #exid, #node, #traps_and_hooks, #trigger_block, #trigger_hook, #trigger_trap, #vars

Constructor Details

#initialize(conf = {}) ⇒ TransientExecutor

Returns a new instance of TransientExecutor.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/flor/core/texecutor.rb', line 84

def initialize(conf={})

  conf = Flor::Conf.prepare(conf, {})

  super(
    TransientUnit.new(conf),
    [], # no hooks
    [], # no traps
    {
      'exid' => Flor.generate_exid('eval', 'u0'),
      'nodes' => {}, 'counters' => {}, 'start' => Flor.tstamp
    })

  @unit.archive = {} if conf['archive']
end

Instance Method Details

#archiveObject



101
# File 'lib/flor/core/texecutor.rb', line 101

def archive; @unit.archive[exid]; end

#cloneObject

Used in specs when testing multiple message arrival order on a “suite” of transient executors



163
164
165
166
167
168
169
170
171
172
# File 'lib/flor/core/texecutor.rb', line 163

def clone

  c = TransientExecutor.allocate

  c.instance_variable_set(:@unit, @unit)
  c.instance_variable_set(:@traps, []) # not useful for a TransientEx clone
  c.instance_variable_set(:@execution, Flor.dup(@execution))

  c
end

#journalObject



100
# File 'lib/flor/core/texecutor.rb', line 100

def journal; @unit.journal; end

#launch(tree, opts = {}) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/flor/core/texecutor.rb', line 103

def launch(tree, opts={})

  @unit.opts = opts
  @unit.archive ||= {} if opts[:archive]

  @unit.logger.log_src(tree, opts)

  messages = [ Flor.make_launch_msg(@execution['exid'], tree, opts) ]

  @unit.logger.log_tree(messages.first['tree'], '0', opts)

  walk(messages, opts)
end

#step(message) ⇒ Object



155
156
157
158
# File 'lib/flor/core/texecutor.rb', line 155

def step(message)

  process(message)
end

#walk(messages, opts = {}) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/flor/core/texecutor.rb', line 117

def walk(messages, opts={})

  loop do

    message = messages.shift
    return nil unless message

    if message['point'] == 'terminated' && messages.any?
      #
      # try to handle 'terminated' last
      #
      messages << message
      message = messages.shift
    end

    msgs = process(message)

    messages.concat(msgs)

    return messages \
      if message_match?(message, opts[:until_after])
    return messages \
      if message_match?(messages, opts[:until])
        #
        # Walk is suspended if options :until_after or :until
        # are satisfied.
        # Returns the remaining messages.

    return message \
      if message['point'] == 'terminated'
    return message \
      if message['point'] == 'failed' && message['on_error'] == nil
        #
        # Walk exits when execution terminates or fails (without on_error).
        # Returns the last message
  end
end