Class: Droonga::HandlerMessenger
- Inherits:
-
Object
- Object
- Droonga::HandlerMessenger
- Defined in:
- lib/droonga/handler_messenger.rb
Instance Attribute Summary collapse
-
#cluster ⇒ Object
readonly
Returns the value of attribute cluster.
-
#database_name ⇒ Object
readonly
Returns the value of attribute database_name.
-
#dispatcher ⇒ Object
readonly
Returns the value of attribute dispatcher.
-
#engine_state ⇒ Object
readonly
Returns the value of attribute engine_state.
Instance Method Summary collapse
- #emit(value) ⇒ Object
- #error(status_code, body) ⇒ Object
-
#forward(droonga_message, destination) ⇒ void
Forwards a Droonga message to other Droonga Engine.
-
#initialize(forwarder, message, options = {}) ⇒ HandlerMessenger
constructor
A new instance of HandlerMessenger.
- #inspect ⇒ Object
Constructor Details
#initialize(forwarder, message, options = {}) ⇒ HandlerMessenger
Returns a new instance of HandlerMessenger.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/droonga/handler_messenger.rb', line 26 def initialize(forwarder, , ={}) @forwarder = forwarder @message = @options = @replier = Replier.new(@forwarder) @dispatcher = [:dispatcher] @engine_state = [:engine_state] @cluster = [:cluster] @database_name = [:database] end |
Instance Attribute Details
#cluster ⇒ Object (readonly)
Returns the value of attribute cluster.
24 25 26 |
# File 'lib/droonga/handler_messenger.rb', line 24 def cluster @cluster end |
#database_name ⇒ Object (readonly)
Returns the value of attribute database_name.
24 25 26 |
# File 'lib/droonga/handler_messenger.rb', line 24 def database_name @database_name end |
#dispatcher ⇒ Object (readonly)
Returns the value of attribute dispatcher.
24 25 26 |
# File 'lib/droonga/handler_messenger.rb', line 24 def dispatcher @dispatcher end |
#engine_state ⇒ Object (readonly)
Returns the value of attribute engine_state.
24 25 26 |
# File 'lib/droonga/handler_messenger.rb', line 24 def engine_state @engine_state end |
Instance Method Details
#emit(value) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/droonga/handler_messenger.rb', line 37 def emit(value) descendants = @message.descendants = @message.raw if descendants.empty? return if ["replyTo"].nil? @replier.reply(.merge("body" => value)) else descendants.each do |name, dests| body = { "id" => @message.id, "input" => name, "value" => value[name], } dests.each do |dest| if @dispatcher @dispatcher.dispatch(body, dest) else = .merge("body" => body) forward(, "to" => dest, "type" => "dispatcher") end end end end end |
#error(status_code, body) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/droonga/handler_messenger.rb', line 62 def error(status_code, body) descendants = @message.descendants = @message.raw if descendants.empty? return if ["replyTo"].nil? response = .merge("statusCode" => status_code, "body" => body) @replier.reply(response) else #XXX This is just a temporary solution. We should rewrite this, # to put errors outside of the message body. Otherwise # plugins cannot use the name "errors" for their message body. body = { "id" => @message.id, "input" => "errors", "value" => { database_name => { "statusCode" => status_code, "body" => body, }, }, } all_dests = [] descendants.each do |name, dests| all_dests += dests end all_dests.each do |dest| if @dispatcher @dispatcher.dispatch(body, dest) else = .merge("statusCode" => status_code, "body" => body,) forward(, "to" => dest, "type" => "dispatcher") end end end end |
#forward(droonga_message, destination) ⇒ void
This method returns an undefined value.
Forwards a Droonga message to other Droonga Engine.
111 112 113 114 |
# File 'lib/droonga/handler_messenger.rb', line 111 def forward(, destination) ["date"] ||= new_date @forwarder.forward(, destination) end |
#inspect ⇒ Object
116 117 118 |
# File 'lib/droonga/handler_messenger.rb', line 116 def inspect "\#<#{self.class} id=#{object_id}>" end |