Class: Droonga::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(loop, message_pusher, options = {}) ⇒ Processor

Returns a new instance of Processor.



22
23
24
25
26
27
# File 'lib/droonga/processor.rb', line 22

def initialize(loop, message_pusher, options={})
  @loop = loop
  @message_pusher = message_pusher
  @options = options
  @n_workers = @options[:n_workers] || 0
end

Instance Method Details

#process(message) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/droonga/processor.rb', line 40

def process(message)
  $log.trace("#{log_tag}: process: start")
  command = message["type"]
  if @handler.processable?(command)
    $log.trace("#{log_tag}: process: handlable: #{command}")
    synchronous = @handler.prefer_synchronous?(command)
    if @n_workers.zero? or synchronous
      @handler.process(message)
    else
      @message_pusher.push(message)
    end
  else
    $log.trace("#{log_tag}: process: ignore #{command}")
  end
  $log.trace("#{log_tag}: process: done")
end

#shutdownObject



34
35
36
37
38
# File 'lib/droonga/processor.rb', line 34

def shutdown
  $log.trace("#{log_tag}: shutdown: start")
  @handler.shutdown
  $log.trace("#{log_tag}: shutdown: done")
end

#startObject



29
30
31
32
# File 'lib/droonga/processor.rb', line 29

def start
  @handler = Handler.new(@loop, @options)
  @handler.start
end