Class: Wakame::Triggers::ProcessCommand

Inherits:
Wakame::Trigger show all
Defined in:
lib/wakame/triggers/process_command.rb

Constant Summary

Constants included from AttributeHelper

AttributeHelper::CONVERT_CLASSES, AttributeHelper::PRIMITIVE_CLASSES

Instance Attribute Summary

Attributes inherited from Wakame::Trigger

#rule_engine

Instance Method Summary collapse

Methods inherited from Wakame::Trigger

#agent_monitor, #bind_engine, #command_queue, #master, #service_cluster, #trigger_action

Methods included from AttributeHelper

#dump_attrs

Methods included from FilterChain

included, #run_filter

Instance Method Details

#cleanupObject



29
30
31
# File 'lib/wakame/triggers/process_command.rb', line 29

def cleanup
  @@command_thread.kill if @@command_thread.alive?
end

#register_hooksObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/wakame/triggers/process_command.rb', line 5

def register_hooks
  @@command_thread ||= Thread.new {
    while cmd = self.command_queue.deq_cmd
      res = nil
      begin
        EM.barrier {
          Wakame.log.debug("#{self.class}: Being processed the command: #{cmd.class}")
          cmd.run(self)
          res = cmd
        }
      rescue => e
        Wakame.log.error(e)
        res = e
      ensure
        self.command_queue.enq_result(res)
      end
    end
  }
  
  #event_subscribe(Event::CommandReceived) { |event|
  #  event.command.run(self)
  #}
end