Class: Droonga::Command::DroongaEngine::CommandRunner
- Inherits:
-
Object
- Object
- Droonga::Command::DroongaEngine::CommandRunner
- Includes:
- Loggable
- Defined in:
- lib/droonga/command/droonga_engine.rb
Instance Attribute Summary collapse
-
#on_command ⇒ Object
writeonly
Sets the attribute on_command.
Instance Method Summary collapse
-
#initialize(loop) ⇒ CommandRunner
constructor
A new instance of CommandRunner.
- #log_tag ⇒ Object
- #push_command(command) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(loop) ⇒ CommandRunner
Returns a new instance of CommandRunner.
759 760 761 762 763 |
# File 'lib/droonga/command/droonga_engine.rb', line 759 def initialize(loop) @loop = loop @commands = [] @on_command = nil end |
Instance Attribute Details
#on_command=(value) ⇒ Object (writeonly)
Sets the attribute on_command
758 759 760 |
# File 'lib/droonga/command/droonga_engine.rb', line 758 def on_command=(value) @on_command = value end |
Instance Method Details
#log_tag ⇒ Object
798 799 800 |
# File 'lib/droonga/command/droonga_engine.rb', line 798 def log_tag "command_runner" end |
#push_command(command) ⇒ Object
791 792 793 794 795 796 |
# File 'lib/droonga/command/droonga_engine.rb', line 791 def push_command(command) return if @async_watcher.nil? first_command_p = @commands.empty? @commands << command @async_watcher.signal if first_command_p end |
#start ⇒ Object
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 |
# File 'lib/droonga/command/droonga_engine.rb', line 765 def start logger.trace("start: stert") @async_watcher = Coolio::AsyncWatcher.new @async_watcher.on_signal do commands = @commands.uniq @commands.clear until commands.empty? command = commands.shift @on_command.call(command) if @on_command end end @loop.attach(@async_watcher) logger.trace("start: async watcher attached", :watcher => @async_watcher) logger.trace("start: done") end |
#stop ⇒ Object
782 783 784 785 786 787 788 789 |
# File 'lib/droonga/command/droonga_engine.rb', line 782 def stop return if @async_watcher.nil? logger.trace("stop: stert") @async_watcher.detach # logger.trace("stop: watcher detached", :watcher => @async_watcher) @async_watcher = nil logger.trace("stop: done") end |