fluent-plugin-droonga 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -4
- data/benchmark/watch/benchmark-notify.rb +2 -2
- data/benchmark/watch/benchmark-scan.rb +3 -0
- data/benchmark/watch/fluentd.conf +0 -1
- data/fluent-plugin-droonga.gemspec +2 -3
- data/lib/droonga/catalog.rb +10 -124
- data/lib/droonga/catalog/base.rb +140 -0
- data/lib/droonga/catalog/version1.rb +23 -0
- data/lib/droonga/catalog_loader.rb +33 -0
- data/lib/droonga/collector.rb +2 -71
- data/lib/droonga/collector_plugin.rb +2 -34
- data/lib/droonga/dispatcher.rb +141 -196
- data/lib/droonga/distribution_planner.rb +76 -0
- data/lib/droonga/distributor.rb +5 -7
- data/lib/droonga/distributor_plugin.rb +23 -15
- data/lib/droonga/engine.rb +2 -2
- data/lib/droonga/event_loop.rb +46 -0
- data/lib/droonga/farm.rb +9 -5
- data/lib/droonga/fluent_message_sender.rb +84 -0
- data/lib/droonga/forwarder.rb +43 -53
- data/lib/droonga/handler.rb +20 -68
- data/lib/droonga/handler_message.rb +61 -0
- data/lib/droonga/handler_messenger.rb +92 -0
- data/lib/droonga/handler_plugin.rb +10 -12
- data/lib/droonga/input_adapter.rb +52 -0
- data/lib/droonga/{adapter.rb → input_adapter_plugin.rb} +7 -13
- data/lib/droonga/input_message.rb +11 -11
- data/lib/droonga/logger.rb +4 -3
- data/lib/droonga/message_pack_packer.rb +62 -0
- data/lib/droonga/message_processing_error.rb +54 -0
- data/lib/droonga/message_pusher.rb +60 -0
- data/lib/droonga/message_receiver.rb +61 -0
- data/lib/droonga/output_adapter.rb +53 -0
- data/lib/droonga/{adapter_plugin.rb → output_adapter_plugin.rb} +3 -21
- data/lib/droonga/output_message.rb +37 -0
- data/lib/droonga/partition.rb +27 -5
- data/lib/droonga/pluggable.rb +9 -4
- data/lib/droonga/plugin.rb +12 -3
- data/lib/droonga/plugin/collector/basic.rb +91 -18
- data/lib/droonga/plugin/distributor/crud.rb +9 -9
- data/lib/droonga/plugin/distributor/distributed_search_planner.rb +401 -0
- data/lib/droonga/plugin/distributor/groonga.rb +5 -5
- data/lib/droonga/plugin/distributor/search.rb +4 -246
- data/lib/droonga/plugin/distributor/watch.rb +11 -6
- data/lib/droonga/plugin/handler/add.rb +69 -7
- data/lib/droonga/plugin/handler/groonga.rb +6 -6
- data/lib/droonga/plugin/handler/search.rb +5 -3
- data/lib/droonga/plugin/handler/watch.rb +19 -13
- data/lib/droonga/plugin/{adapter → input_adapter}/groonga.rb +5 -11
- data/lib/droonga/plugin/{adapter → input_adapter}/groonga/select.rb +2 -36
- data/lib/droonga/plugin/output_adapter/groonga.rb +30 -0
- data/lib/droonga/plugin/output_adapter/groonga/select.rb +54 -0
- data/lib/droonga/plugin_loader.rb +2 -2
- data/lib/droonga/processor.rb +21 -23
- data/lib/droonga/replier.rb +40 -0
- data/lib/droonga/searcher.rb +298 -174
- data/lib/droonga/server.rb +0 -67
- data/lib/droonga/session.rb +85 -0
- data/lib/droonga/test.rb +21 -0
- data/lib/droonga/test/stub_distributor.rb +31 -0
- data/lib/droonga/test/stub_handler.rb +37 -0
- data/lib/droonga/test/stub_handler_message.rb +35 -0
- data/lib/droonga/test/stub_handler_messenger.rb +34 -0
- data/lib/droonga/time_formatter.rb +37 -0
- data/lib/droonga/watcher.rb +1 -0
- data/lib/droonga/worker.rb +16 -19
- data/lib/fluent/plugin/out_droonga.rb +9 -9
- data/lib/groonga_command_converter.rb +5 -5
- data/sample/cluster/catalog.json +1 -1
- data/test/command/config/default/catalog.json +19 -1
- data/test/command/fixture/event.jsons +41 -0
- data/test/command/fixture/user-table.jsons +9 -0
- data/test/command/run-test.rb +2 -2
- data/test/command/suite/add/error/invalid-integer.expected +20 -0
- data/test/command/suite/add/error/invalid-integer.test +12 -0
- data/test/command/suite/add/error/invalid-time.expected +20 -0
- data/test/command/suite/add/error/invalid-time.test +12 -0
- data/test/command/suite/add/error/missing-key.expected +13 -0
- data/test/command/suite/add/error/missing-key.test +16 -0
- data/test/command/suite/add/error/missing-table.expected +13 -0
- data/test/command/suite/add/error/missing-table.test +16 -0
- data/test/command/suite/add/error/unknown-column.expected +20 -0
- data/test/command/suite/add/error/unknown-column.test +12 -0
- data/test/command/suite/add/error/unknown-table.expected +13 -0
- data/test/command/suite/add/error/unknown-table.test +17 -0
- data/test/command/suite/add/minimum.expected +1 -3
- data/test/command/suite/add/with-values.expected +1 -3
- data/test/command/suite/add/without-key.expected +1 -3
- data/test/command/suite/message/error/missing-dataset.expected +13 -0
- data/test/command/suite/message/error/missing-dataset.test +5 -0
- data/test/command/suite/message/error/unknown-command.expected +13 -0
- data/test/command/suite/message/error/unknown-command.test +6 -0
- data/test/command/suite/message/error/unknown-dataset.expected +13 -0
- data/test/command/suite/message/error/unknown-dataset.test +6 -0
- data/test/command/suite/search/{array-attribute-label.expected → attributes/array.expected} +0 -0
- data/test/command/suite/search/{array-attribute-label.test → attributes/array.test} +0 -0
- data/test/command/suite/search/{hash-attribute-label.expected → attributes/hash.expected} +0 -0
- data/test/command/suite/search/{hash-attribute-label.test → attributes/hash.test} +0 -0
- data/test/command/suite/search/{condition-nested.expected → condition/nested.expected} +0 -0
- data/test/command/suite/search/{condition-nested.test → condition/nested.test} +0 -0
- data/test/command/suite/search/{condition-query.expected → condition/query.expected} +0 -0
- data/test/command/suite/search/{condition-query.test → condition/query.test} +0 -0
- data/test/command/suite/search/{condition-script.expected → condition/script.expected} +0 -0
- data/test/command/suite/search/{condition-script.test → condition/script.test} +0 -0
- data/test/command/suite/search/error/cyclic-source.expected +18 -0
- data/test/command/suite/search/error/cyclic-source.test +12 -0
- data/test/command/suite/search/error/deeply-cyclic-source.expected +21 -0
- data/test/command/suite/search/error/deeply-cyclic-source.test +15 -0
- data/test/command/suite/search/error/missing-source-parameter.expected +17 -0
- data/test/command/suite/search/error/missing-source-parameter.test +11 -0
- data/test/command/suite/search/error/unknown-source.expected +18 -0
- data/test/command/suite/search/error/unknown-source.test +12 -0
- data/test/command/suite/search/{minimum.expected → group/count.expected} +2 -1
- data/test/command/suite/search/{minimum.test → group/count.test} +5 -3
- data/test/command/suite/search/group/limit.expected +19 -0
- data/test/command/suite/search/group/limit.test +20 -0
- data/test/command/suite/search/group/string.expected +36 -0
- data/test/command/suite/search/group/string.test +44 -0
- data/test/command/suite/search/{chained-queries.expected → multiple/chained.expected} +0 -0
- data/test/command/suite/search/{chained-queries.test → multiple/chained.test} +0 -0
- data/test/command/suite/search/{multiple-queries.expected → multiple/parallel.expected} +0 -0
- data/test/command/suite/search/{multiple-queries.test → multiple/parallel.test} +0 -0
- data/test/command/suite/search/{output-range.expected → range/only-output.expected} +0 -0
- data/test/command/suite/search/{output-range.test → range/only-output.test} +0 -0
- data/test/command/suite/search/{sort-range.expected → range/only-sort.expected} +0 -0
- data/test/command/suite/search/{sort-range.test → range/only-sort.test} +0 -0
- data/test/command/suite/search/{sort-and-output-range.expected → range/sort-and-output.expected} +0 -0
- data/test/command/suite/search/{sort-and-output-range.test → range/sort-and-output.test} +0 -0
- data/test/command/suite/search/range/too-large-output-offset.expected +16 -0
- data/test/command/suite/search/range/too-large-output-offset.test +25 -0
- data/test/command/suite/search/range/too-large-sort-offset.expected +16 -0
- data/test/command/suite/search/range/too-large-sort-offset.test +28 -0
- data/test/command/suite/search/response/records/value/time.expected +24 -0
- data/test/command/suite/search/response/records/value/time.test +24 -0
- data/test/command/suite/search/sort/default-offset-limit.expected +43 -0
- data/test/command/suite/search/sort/default-offset-limit.test +26 -0
- data/test/command/suite/search/{sort-with-invisible-column.expected → sort/invisible-column.expected} +0 -0
- data/test/command/suite/search/{sort-with-invisible-column.test → sort/invisible-column.test} +0 -0
- data/test/command/suite/watch/subscribe.expected +12 -0
- data/test/command/suite/watch/subscribe.test +9 -0
- data/test/command/suite/watch/unsubscribe.expected +12 -0
- data/test/command/suite/watch/unsubscribe.test +9 -0
- data/test/unit/{test_catalog.rb → catalog/test_version1.rb} +12 -4
- data/test/unit/fixtures/{catalog.json → catalog/version1.json} +0 -0
- data/test/unit/helper.rb +2 -0
- data/test/unit/plugin/collector/test_basic.rb +289 -33
- data/test/unit/plugin/distributor/test_search.rb +176 -861
- data/test/unit/plugin/distributor/test_search_planner.rb +1102 -0
- data/test/unit/plugin/handler/groonga/test_column_create.rb +17 -13
- data/test/unit/plugin/handler/groonga/test_table_create.rb +10 -10
- data/test/unit/plugin/handler/test_add.rb +74 -11
- data/test/unit/plugin/handler/test_groonga.rb +15 -1
- data/test/unit/plugin/handler/test_search.rb +33 -17
- data/test/unit/plugin/handler/test_watch.rb +43 -27
- data/test/unit/run-test.rb +2 -0
- data/test/unit/test_message_pack_packer.rb +51 -0
- data/test/unit/test_time_formatter.rb +29 -0
- metadata +208 -110
- data/lib/droonga/job_queue.rb +0 -87
- data/lib/droonga/job_queue_schema.rb +0 -65
- data/test/unit/test_adapter.rb +0 -51
- data/test/unit/test_job_queue_schema.rb +0 -45
data/lib/droonga/handler.rb
CHANGED
@@ -18,6 +18,8 @@
|
|
18
18
|
require "groonga"
|
19
19
|
|
20
20
|
require "droonga/forwarder"
|
21
|
+
require "droonga/handler_message"
|
22
|
+
require "droonga/handler_messenger"
|
21
23
|
require "droonga/pluggable"
|
22
24
|
require "droonga/handler_plugin"
|
23
25
|
|
@@ -25,15 +27,22 @@ module Droonga
|
|
25
27
|
class Handler
|
26
28
|
include Pluggable
|
27
29
|
|
28
|
-
attr_reader :context, :
|
30
|
+
attr_reader :context, :name
|
29
31
|
|
30
|
-
def initialize(options={})
|
32
|
+
def initialize(loop, options={})
|
33
|
+
@loop = loop
|
31
34
|
@options = options
|
32
35
|
@name = options[:name]
|
33
36
|
@database_name = options[:database]
|
34
37
|
prepare
|
35
38
|
end
|
36
39
|
|
40
|
+
def start
|
41
|
+
$log.trace("#{log_tag}: start: start")
|
42
|
+
@forwarder.start
|
43
|
+
$log.trace("#{log_tag}: start: done")
|
44
|
+
end
|
45
|
+
|
37
46
|
def shutdown
|
38
47
|
$log.trace("#{log_tag}: shutdown: start")
|
39
48
|
super
|
@@ -50,96 +59,39 @@ module Droonga
|
|
50
59
|
find_plugin(command).prefer_synchronous?(command)
|
51
60
|
end
|
52
61
|
|
53
|
-
def process(
|
62
|
+
def process(message)
|
54
63
|
$log.trace("#{log_tag}: process: start")
|
55
|
-
|
64
|
+
command = message["type"]
|
56
65
|
plugin = find_plugin(command)
|
57
66
|
if plugin.nil?
|
58
67
|
$log.trace("#{log_tag}: process: done: no plugin: <#{command}>")
|
59
68
|
return
|
60
69
|
end
|
61
|
-
process_command(plugin, command,
|
70
|
+
process_command(plugin, command, message)
|
62
71
|
$log.trace("#{log_tag}: process: done: <#{command}>",
|
63
72
|
:plugin => plugin.class)
|
64
73
|
end
|
65
74
|
|
66
|
-
def emit(value, name = nil)
|
67
|
-
unless name
|
68
|
-
if @output_names
|
69
|
-
name = @output_names.first
|
70
|
-
else
|
71
|
-
@output_values = @task["values"] = value
|
72
|
-
return
|
73
|
-
end
|
74
|
-
end
|
75
|
-
@output_values[name] = value
|
76
|
-
end
|
77
|
-
|
78
|
-
def post(message, destination)
|
79
|
-
@forwarder.forward(envelope, message, destination)
|
80
|
-
end
|
81
|
-
|
82
75
|
private
|
83
|
-
def parse_envelope(envelope)
|
84
|
-
@envelope = envelope
|
85
|
-
envelope["via"] ||= []
|
86
|
-
[envelope["body"], envelope["type"], envelope["arguments"]]
|
87
|
-
end
|
88
|
-
|
89
76
|
def prepare
|
90
77
|
if @database_name && !@database_name.empty?
|
91
78
|
@context = Groonga::Context.new
|
92
79
|
@database = @context.open_database(@database_name)
|
93
80
|
end
|
94
81
|
load_plugins(@options[:handlers] || [])
|
95
|
-
@forwarder = Forwarder.new
|
82
|
+
@forwarder = Forwarder.new(@loop)
|
96
83
|
end
|
97
84
|
|
98
85
|
def instantiate_plugin(name)
|
99
86
|
HandlerPlugin.repository.instantiate(name, self)
|
100
87
|
end
|
101
88
|
|
102
|
-
def process_command(plugin, command,
|
103
|
-
|
104
|
-
|
105
|
-
@task = request["task"]
|
106
|
-
return false unless @task.is_a? Hash
|
107
|
-
|
108
|
-
@component = @task["component"]
|
109
|
-
return false unless @component.is_a? Hash
|
110
|
-
|
111
|
-
@output_values = @task["values"]
|
112
|
-
@body = @component["body"]
|
113
|
-
@output_names = @component["outputs"]
|
114
|
-
@id = request["id"]
|
115
|
-
@value = request["value"]
|
116
|
-
@input_name = request["name"]
|
117
|
-
@descendants = request["descendants"]
|
89
|
+
def process_command(plugin, command, raw_message)
|
90
|
+
handler_message = HandlerMessage.new(raw_message)
|
91
|
+
handler_message.validate
|
118
92
|
|
119
|
-
|
120
|
-
|
121
|
-
true
|
122
|
-
end
|
123
|
-
|
124
|
-
def output
|
125
|
-
result = @task["values"]
|
126
|
-
if @component["post"]
|
127
|
-
destination = @component["post"]
|
128
|
-
destination = envelope["replyTo"] if destination == true
|
129
|
-
post(result, destination)
|
130
|
-
end
|
131
|
-
@descendants.each do |name, dests|
|
132
|
-
message = {
|
133
|
-
"id" => @id,
|
134
|
-
"input" => name,
|
135
|
-
"value" => result[name]
|
136
|
-
}
|
137
|
-
dests.each do |routes|
|
138
|
-
routes.each do |route|
|
139
|
-
post(message, "to"=>route, "type"=>"dispatcher")
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
93
|
+
messenger = HandlerMessenger.new(@forwarder, handler_message, @options)
|
94
|
+
plugin.process(command, handler_message, messenger)
|
143
95
|
end
|
144
96
|
|
145
97
|
def log_tag
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Copyright (C) 2013 Droonga Project
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License version 2.1 as published by the Free Software Foundation.
|
6
|
+
#
|
7
|
+
# This library is distributed in the hope that it will be useful,
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
10
|
+
# Lesser General Public License for more details.
|
11
|
+
#
|
12
|
+
# You should have received a copy of the GNU Lesser General Public
|
13
|
+
# License along with this library; if not, write to the Free Software
|
14
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
|
+
|
16
|
+
module Droonga
|
17
|
+
class HandlerMessage
|
18
|
+
attr_reader :raw
|
19
|
+
def initialize(raw)
|
20
|
+
@raw = raw
|
21
|
+
end
|
22
|
+
|
23
|
+
def validate
|
24
|
+
unless task.is_a?(Hash)
|
25
|
+
raise "<task> value isn't object: <#{@raw.inspect}>"
|
26
|
+
end
|
27
|
+
|
28
|
+
unless component.is_a?(Hash)
|
29
|
+
raise "<task/component> value isn't object: <#{@raw.inspect}>"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def [](name)
|
34
|
+
@raw[name]
|
35
|
+
end
|
36
|
+
|
37
|
+
def body
|
38
|
+
@body ||= self["body"]
|
39
|
+
end
|
40
|
+
|
41
|
+
def task
|
42
|
+
@task ||= body["task"]
|
43
|
+
end
|
44
|
+
|
45
|
+
def component
|
46
|
+
@component ||= task["component"]
|
47
|
+
end
|
48
|
+
|
49
|
+
def request
|
50
|
+
@request ||= component["body"]
|
51
|
+
end
|
52
|
+
|
53
|
+
def id
|
54
|
+
@id ||= body["id"]
|
55
|
+
end
|
56
|
+
|
57
|
+
def descendants
|
58
|
+
@descendants ||= body["descendants"]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# Copyright (C) 2013 Droonga Project
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License version 2.1 as published by the Free Software Foundation.
|
6
|
+
#
|
7
|
+
# This library is distributed in the hope that it will be useful,
|
8
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
10
|
+
# Lesser General Public License for more details.
|
11
|
+
#
|
12
|
+
# You should have received a copy of the GNU Lesser General Public
|
13
|
+
# License along with this library; if not, write to the Free Software
|
14
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
15
|
+
|
16
|
+
require "droonga/replier"
|
17
|
+
require "droonga/forwarder"
|
18
|
+
|
19
|
+
module Droonga
|
20
|
+
class HandlerMessenger
|
21
|
+
def initialize(forwarder, message, options={})
|
22
|
+
@forwarder = forwarder
|
23
|
+
@message = message
|
24
|
+
@options = options
|
25
|
+
@replier = Replier.new(@forwarder)
|
26
|
+
@dispatcher = @options[:dispatcher]
|
27
|
+
end
|
28
|
+
|
29
|
+
def emit(value)
|
30
|
+
descendants = @message.descendants
|
31
|
+
raw_message = @message.raw
|
32
|
+
if descendants.empty?
|
33
|
+
return if raw_message["replyTo"].nil?
|
34
|
+
@replier.reply(raw_message.merge("body" => value))
|
35
|
+
else
|
36
|
+
descendants.each do |name, dests|
|
37
|
+
body = {
|
38
|
+
"id" => @message.id,
|
39
|
+
"input" => name,
|
40
|
+
"value" => value[name],
|
41
|
+
}
|
42
|
+
dests.each do |dest|
|
43
|
+
if @dispatcher
|
44
|
+
@dispatcher.dispatch(body, dest)
|
45
|
+
else
|
46
|
+
message = raw_message.merge("body" => body)
|
47
|
+
forward(message, "to" => dest, "type" => "dispatcher")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def error(status_code, body)
|
55
|
+
descendants = @message.descendants
|
56
|
+
raw_message = @message.raw
|
57
|
+
if descendants.empty?
|
58
|
+
return if raw_message["replyTo"].nil?
|
59
|
+
response = raw_message.merge("statusCode" => status_code,
|
60
|
+
"body" => body)
|
61
|
+
@replier.reply(response)
|
62
|
+
else
|
63
|
+
#XXX IMPLEMENT ME!!
|
64
|
+
raise error
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Forwards a Droonga message to other Droonga Engine.
|
69
|
+
#
|
70
|
+
# @param [Hash] droonga_message
|
71
|
+
# The Droonga message to be forwarded.
|
72
|
+
# @param [Hash] destination
|
73
|
+
# The destination of the Droonga message. See {Forwarder#forward} to
|
74
|
+
# know about how to specify destination.
|
75
|
+
#
|
76
|
+
# @return [void]
|
77
|
+
#
|
78
|
+
# @see Forwarder#forward
|
79
|
+
def forward(droonga_message, destination)
|
80
|
+
@forwarder.forward(droonga_message, destination)
|
81
|
+
end
|
82
|
+
|
83
|
+
def inspect
|
84
|
+
"\#<#{self.class} id=#{object_id}>"
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
def log_tag
|
89
|
+
"[#{Process.ppid}][#{Process.pid}] handler_messenger"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -16,6 +16,7 @@
|
|
16
16
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
17
|
|
18
18
|
require "droonga/plugin"
|
19
|
+
require "droonga/message_processing_error"
|
19
20
|
|
20
21
|
module Droonga
|
21
22
|
class HandlerPlugin < Plugin
|
@@ -27,20 +28,17 @@ module Droonga
|
|
27
28
|
@context = @handler.context
|
28
29
|
end
|
29
30
|
|
30
|
-
def envelope
|
31
|
-
@handler.envelope
|
32
|
-
end
|
33
|
-
|
34
|
-
def emit(value, name=nil)
|
35
|
-
@handler.emit(value, name)
|
36
|
-
end
|
37
|
-
|
38
|
-
def post(body, destination=nil)
|
39
|
-
@handler.post(body, destination)
|
40
|
-
end
|
41
|
-
|
42
31
|
def prefer_synchronous?(command)
|
43
32
|
false
|
44
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def run_command(command, message, messenger)
|
37
|
+
begin
|
38
|
+
super
|
39
|
+
rescue MessageProcessingError => error
|
40
|
+
messenger.error(error.status_code, error.response_body)
|
41
|
+
end
|
42
|
+
end
|
45
43
|
end
|
46
44
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2013 Droonga Project
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License version 2.1 as published by the Free Software Foundation.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
|
18
|
+
require "droonga/pluggable"
|
19
|
+
require "droonga/input_adapter_plugin"
|
20
|
+
require "droonga/input_message"
|
21
|
+
|
22
|
+
module Droonga
|
23
|
+
class InputAdapter
|
24
|
+
include Pluggable
|
25
|
+
|
26
|
+
def initialize(dispatcher, options={})
|
27
|
+
@dispatcher = dispatcher
|
28
|
+
load_plugins(options[:plugins] || [])
|
29
|
+
end
|
30
|
+
|
31
|
+
def adapt(message)
|
32
|
+
adapted_message = message
|
33
|
+
@plugins.each do |plugin|
|
34
|
+
input_message = InputMessage.new(adapted_message)
|
35
|
+
command = input_message.command
|
36
|
+
next unless plugin.processable?(command)
|
37
|
+
process(command, input_message)
|
38
|
+
adapted_message = input_message.adapted_message
|
39
|
+
end
|
40
|
+
adapted_message
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def instantiate_plugin(name)
|
45
|
+
InputAdapterPlugin.repository.instantiate(name, @dispatcher)
|
46
|
+
end
|
47
|
+
|
48
|
+
def log_tag
|
49
|
+
"input-adapter"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -15,25 +15,19 @@
|
|
15
15
|
# License along with this library; if not, write to the Free Software
|
16
16
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
17
|
|
18
|
-
require "droonga/
|
19
|
-
require "droonga/adapter_plugin"
|
18
|
+
require "droonga/plugin"
|
20
19
|
|
21
20
|
module Droonga
|
22
|
-
class
|
23
|
-
|
21
|
+
class InputAdapterPlugin < Plugin
|
22
|
+
extend PluginRegisterable
|
24
23
|
|
25
|
-
def initialize(dispatcher
|
24
|
+
def initialize(dispatcher)
|
25
|
+
super()
|
26
26
|
@dispatcher = dispatcher
|
27
|
-
load_plugins(options[:adapters] || [])
|
28
27
|
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
AdapterPlugin.repository.instantiate(name, @dispatcher)
|
33
|
-
end
|
34
|
-
|
35
|
-
def log_tag
|
36
|
-
"adapter"
|
29
|
+
def forward(message, destination)
|
30
|
+
@dispatcher.forward(message, destination)
|
37
31
|
end
|
38
32
|
end
|
39
33
|
end
|
@@ -17,35 +17,35 @@
|
|
17
17
|
|
18
18
|
module Droonga
|
19
19
|
class InputMessage
|
20
|
-
def initialize(
|
21
|
-
@
|
20
|
+
def initialize(raw_message)
|
21
|
+
@raw_message = raw_message
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
# TODO: We can create adapted
|
24
|
+
def adapted_message
|
25
|
+
# TODO: We can create adapted message non-destructively.
|
26
26
|
# If it is not performance issue, it is better that we don't
|
27
|
-
# change
|
28
|
-
@
|
27
|
+
# change message destructively. Consider about it later.
|
28
|
+
@raw_message
|
29
29
|
end
|
30
30
|
|
31
31
|
def add_route(route)
|
32
|
-
@
|
32
|
+
@raw_message["via"].push(route)
|
33
33
|
end
|
34
34
|
|
35
35
|
def body
|
36
|
-
@
|
36
|
+
@raw_message["body"]
|
37
37
|
end
|
38
38
|
|
39
39
|
def body=(body)
|
40
|
-
@
|
40
|
+
@raw_message["body"] = body
|
41
41
|
end
|
42
42
|
|
43
43
|
def command
|
44
|
-
@
|
44
|
+
@raw_message["type"]
|
45
45
|
end
|
46
46
|
|
47
47
|
def command=(command)
|
48
|
-
@
|
48
|
+
@raw_message["type"] = command
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|