Class: Droonga::Handler

Inherits:
Object
  • Object
show all
Includes:
Pluggable
Defined in:
lib/droonga/handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Pluggable

#processable?

Constructor Details

#initialize(options = {}) ⇒ Handler

Returns a new instance of Handler.



30
31
32
33
34
35
# File 'lib/droonga/handler.rb', line 30

def initialize(options={})
  @options = options
  @name = options[:name]
  @database_name = options[:database]
  prepare
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



28
29
30
# File 'lib/droonga/handler.rb', line 28

def context
  @context
end

#envelopeObject (readonly)

Returns the value of attribute envelope.



28
29
30
# File 'lib/droonga/handler.rb', line 28

def envelope
  @envelope
end

#nameObject (readonly)

Returns the value of attribute name.



28
29
30
# File 'lib/droonga/handler.rb', line 28

def name
  @name
end

Instance Method Details

#emit(value, name = nil) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/droonga/handler.rb', line 66

def emit(value, name = nil)
  unless name
    if @output_names
      name = @output_names.first
    else
      @output_values = @task["values"] = value
      return
    end
  end
  @output_values[name] = value
end

#post(message, destination) ⇒ Object



78
79
80
# File 'lib/droonga/handler.rb', line 78

def post(message, destination)
  @forwarder.forward(envelope, message, destination)
end

#prefer_synchronous?(command) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/droonga/handler.rb', line 49

def prefer_synchronous?(command)
  find_plugin(command).prefer_synchronous?(command)
end

#process(envelope) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/droonga/handler.rb', line 53

def process(envelope)
  $log.trace("#{log_tag}: process: start")
  body, command, arguments = parse_envelope(envelope)
  plugin = find_plugin(command)
  if plugin.nil?
    $log.trace("#{log_tag}: process: done: no plugin: <#{command}>")
    return
  end
  process_command(plugin, command, body, arguments)
  $log.trace("#{log_tag}: process: done: <#{command}>",
             :plugin => plugin.class)
end

#shutdownObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/droonga/handler.rb', line 37

def shutdown
  $log.trace("#{log_tag}: shutdown: start")
  super
  @forwarder.shutdown
  if @database
    @database.close
    @context.close
    @database = @context = nil
  end
  $log.trace("#{log_tag}: shutdown: done")
end