Class: Droonga::Processor

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Processor.



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

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

Instance Method Details

#process(message) ⇒ Object



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

def process(message)
  logger.trace("process: start")
  type = message["type"]
  if @handler_runner.processable?(type)
    logger.trace("process: handlable: #{type}")
    synchronous = @handler_runner.prefer_synchronous?(type)
    change_schema = @handler_runner.change_schema?(type)
    if @n_workers.zero? or synchronous or change_schema
      @handler_runner.process(message)
      if change_schema
        @job_pusher.broadcast(database_reopen_message)
      end
    else
      @job_pusher.push(message)
    end
  else
    logger.trace("process: ignore #{type}")
  end
  logger.trace("process: done")
end

#shutdownObject



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

def shutdown
  logger.trace("shutdown: start")
  @handler_runner.shutdown
  logger.trace("shutdown: done")
end

#startObject



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

def start
  @handler_runner = HandlerRunner.new(@loop, @options)
  @handler_runner.start
end