class Dynflow::Connectors::Direct::Core
Public Class Methods
new(connector)
click to toggle source
# File lib/dynflow/connectors/direct.rb, line 7 def initialize(connector) @connector = connector @worlds = {} @executor_round_robin = RoundRobin.new end
Public Instance Methods
handle_envelope(envelope)
click to toggle source
# File lib/dynflow/connectors/direct.rb, line 28 def handle_envelope(envelope) if world = find_receiver(envelope) @connector.receive(world, envelope) else log(Logger::ERROR, "Receiver for envelope #{ envelope } not found") end end
start_listening(world)
click to toggle source
# File lib/dynflow/connectors/direct.rb, line 13 def start_listening(world) @worlds[world.id] = world @executor_round_robin.add(world) if world.executor end
stop_listening(world)
click to toggle source
# File lib/dynflow/connectors/direct.rb, line 22 def stop_listening(world) @worlds.delete(world.id) @executor_round_robin.delete(world) if world.executor reference.tell(:terminate!) if @worlds.empty? end
stop_receiving_new_work(world)
click to toggle source
# File lib/dynflow/connectors/direct.rb, line 18 def stop_receiving_new_work(world) @executor_round_robin.delete(world) end
Private Instance Methods
find_receiver(envelope)
click to toggle source
# File lib/dynflow/connectors/direct.rb, line 38 def find_receiver(envelope) receiver = if Dispatcher::AnyExecutor === envelope.receiver_id @executor_round_robin.next else @worlds[envelope.receiver_id] end raise Dynflow::Error, "No executor available" unless receiver return receiver end