fluent-plugin-droonga 0.9.0 → 0.9.9
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/.travis.yml +3 -0
- data/Gemfile +8 -1
- data/fluent-plugin-droonga.gemspec +2 -2
- data/lib/droonga/adapter.rb +39 -0
- data/lib/droonga/adapter_runner.rb +99 -0
- data/lib/droonga/catalog/base.rb +11 -11
- data/lib/droonga/catalog/dataset.rb +54 -0
- data/lib/droonga/catalog/version1.rb +1 -1
- data/lib/droonga/collector.rb +5 -7
- data/lib/droonga/collector_plugin.rb +7 -7
- data/lib/droonga/command.rb +36 -0
- data/lib/droonga/{plugin/input_adapter/crud.rb → command_repository.rb} +14 -8
- data/lib/droonga/dispatcher.rb +86 -54
- data/lib/droonga/distributed_command_planner.rb +183 -0
- data/lib/droonga/distributor.rb +43 -17
- data/lib/droonga/handler.rb +13 -72
- data/lib/droonga/handler_message.rb +5 -5
- data/lib/droonga/handler_messenger.rb +4 -1
- data/lib/droonga/handler_plugin.rb +2 -2
- data/lib/droonga/handler_runner.rb +104 -0
- data/lib/droonga/input_message.rb +4 -4
- data/lib/droonga/legacy_pluggable.rb +66 -0
- data/lib/droonga/{input_adapter.rb → legacy_plugin.rb} +27 -22
- data/lib/droonga/{plugin_repository.rb → legacy_plugin_repository.rb} +2 -4
- data/lib/droonga/message_matcher.rb +101 -0
- data/lib/droonga/{input_adapter_plugin.rb → planner.rb} +14 -10
- data/lib/droonga/planner_plugin.rb +54 -0
- data/lib/droonga/pluggable.rb +9 -45
- data/lib/droonga/plugin.rb +9 -33
- data/lib/droonga/plugin/collector/basic.rb +2 -0
- data/lib/droonga/plugin/collector/search.rb +31 -37
- data/lib/droonga/plugin/{handler/groonga/table_remove.rb → metadata/adapter_message.rb} +23 -18
- data/lib/droonga/plugin/{handler/search.rb → metadata/handler_action.rb} +19 -15
- data/lib/droonga/plugin/metadata/input_message.rb +39 -0
- data/lib/droonga/plugin/planner/crud.rb +49 -0
- data/lib/droonga/plugin/{distributor → planner}/distributed_search_planner.rb +62 -70
- data/lib/droonga/plugin/{distributor → planner}/groonga.rb +11 -32
- data/lib/droonga/plugin/{distributor → planner}/search.rb +5 -5
- data/lib/droonga/plugin/{distributor → planner}/watch.rb +15 -6
- data/lib/droonga/plugin_loader.rb +10 -0
- data/lib/droonga/plugin_registerable.rb +34 -10
- data/lib/droonga/plugin_registry.rb +58 -0
- data/lib/droonga/plugins/crud.rb +124 -0
- data/lib/droonga/plugins/error.rb +50 -0
- data/lib/droonga/{output_adapter_plugin.rb → plugins/groonga.rb} +9 -13
- data/lib/droonga/plugins/groonga/column_create.rb +123 -0
- data/lib/droonga/plugins/groonga/generic_command.rb +65 -0
- data/lib/droonga/{plugin/output_adapter/groonga.rb → plugins/groonga/generic_response.rb} +16 -15
- data/lib/droonga/plugins/groonga/select.rb +124 -0
- data/lib/droonga/plugins/groonga/table_create.rb +106 -0
- data/lib/droonga/plugins/groonga/table_remove.rb +57 -0
- data/lib/droonga/plugins/search.rb +40 -0
- data/lib/droonga/plugins/watch.rb +156 -0
- data/lib/droonga/processor.rb +8 -10
- data/lib/droonga/searcher.rb +14 -4
- data/lib/droonga/searcher/mecab_filter.rb +67 -0
- data/lib/droonga/session.rb +5 -5
- data/lib/droonga/test.rb +1 -1
- data/lib/droonga/test/stub_handler_message.rb +1 -1
- data/lib/droonga/test/{stub_distributor.rb → stub_planner.rb} +1 -1
- data/lib/droonga/worker.rb +7 -8
- data/lib/fluent/plugin/out_droonga.rb +0 -1
- data/sample/cluster/catalog.json +2 -4
- data/sample/mecab_filter/data.grn +7 -0
- data/sample/mecab_filter/ddl.grn +7 -0
- data/sample/mecab_filter/search_with_mecab_filter.json +21 -0
- data/sample/mecab_filter/search_without_mecab_filter.json +21 -0
- data/test/command/config/default/catalog.json +2 -5
- data/test/command/suite/search/error/no-query.expected +13 -0
- data/test/command/suite/search/error/no-query.test +7 -0
- data/test/command/suite/search/error/unknown-source.expected +26 -0
- data/test/command/suite/watch/subscribe.expected +3 -3
- data/test/command/suite/watch/unsubscribe.expected +3 -3
- data/test/unit/catalog/test_dataset.rb +385 -0
- data/test/unit/catalog/test_version1.rb +111 -45
- data/test/unit/fixtures/catalog/version1.json +0 -3
- data/test/unit/helper.rb +2 -1
- data/test/unit/helper/distributed_search_planner_helper.rb +83 -0
- data/test/unit/plugin/collector/test_basic.rb +233 -376
- data/test/unit/plugin/collector/test_search.rb +8 -17
- data/test/unit/plugin/planner/search_planner/test_basic.rb +120 -0
- data/test/unit/plugin/planner/search_planner/test_group_by.rb +573 -0
- data/test/unit/plugin/planner/search_planner/test_output.rb +388 -0
- data/test/unit/plugin/planner/search_planner/test_sort_by.rb +938 -0
- data/test/unit/plugin/{distributor → planner}/test_search.rb +20 -75
- data/test/unit/{plugin/handler → plugins/crud}/test_add.rb +11 -11
- data/test/unit/plugins/groonga/select/test_adapter_input.rb +213 -0
- data/test/unit/{plugin/output_adapter/groonga/test_select.rb → plugins/groonga/select/test_adapter_output.rb} +12 -13
- data/test/unit/{plugin/handler → plugins}/groonga/test_column_create.rb +20 -5
- data/test/unit/{plugin/handler → plugins}/groonga/test_table_create.rb +5 -0
- data/test/unit/{plugin/handler → plugins}/groonga/test_table_remove.rb +8 -1
- data/test/unit/{plugin/handler → plugins}/test_groonga.rb +5 -5
- data/test/unit/{plugin/handler → plugins}/test_search.rb +21 -5
- data/test/unit/{plugin/handler → plugins}/test_watch.rb +29 -10
- data/{lib/droonga/command_mapper.rb → test/unit/test_command_repository.rb} +16 -22
- data/test/unit/{test_plugin.rb → test_legacy_plugin.rb} +3 -3
- data/test/unit/{test_plugin_repository.rb → test_legacy_plugin_repository.rb} +3 -3
- data/test/unit/test_message_matcher.rb +137 -0
- metadata +86 -66
- data/bin/grn2jsons +0 -82
- data/lib/droonga/distribution_planner.rb +0 -76
- data/lib/droonga/distributor_plugin.rb +0 -95
- data/lib/droonga/output_adapter.rb +0 -53
- data/lib/droonga/plugin/collector/groonga.rb +0 -83
- data/lib/droonga/plugin/distributor/crud.rb +0 -84
- data/lib/droonga/plugin/handler/add.rb +0 -109
- data/lib/droonga/plugin/handler/forward.rb +0 -75
- data/lib/droonga/plugin/handler/groonga.rb +0 -99
- data/lib/droonga/plugin/handler/groonga/column_create.rb +0 -106
- data/lib/droonga/plugin/handler/groonga/table_create.rb +0 -91
- data/lib/droonga/plugin/handler/watch.rb +0 -108
- data/lib/droonga/plugin/input_adapter/groonga.rb +0 -49
- data/lib/droonga/plugin/input_adapter/groonga/select.rb +0 -63
- data/lib/droonga/plugin/output_adapter/crud.rb +0 -51
- data/lib/droonga/plugin/output_adapter/groonga/select.rb +0 -54
- data/lib/groonga_command_converter.rb +0 -143
- data/sample/fluentd.conf +0 -8
- data/test/unit/plugin/distributor/test_search_planner.rb +0 -1102
- data/test/unit/plugin/input_adapter/groonga/test_select.rb +0 -248
- data/test/unit/test_command_mapper.rb +0 -44
- data/test/unit/test_groonga_command_converter.rb +0 -242
data/lib/droonga/distributor.rb
CHANGED
|
@@ -15,35 +15,61 @@
|
|
|
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 "
|
|
19
|
-
require "droonga/distributor_plugin"
|
|
20
|
-
require "droonga/distribution_planner"
|
|
18
|
+
require "tsort"
|
|
21
19
|
|
|
22
20
|
module Droonga
|
|
23
21
|
class Distributor
|
|
24
|
-
|
|
22
|
+
class UndefinedInputError < StandardError
|
|
23
|
+
attr_reader :input
|
|
24
|
+
def initialize(input)
|
|
25
|
+
@input = input
|
|
26
|
+
super("undefined input assigned: <#{input}>")
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
class CyclicStepsError < StandardError
|
|
31
|
+
attr_reader :steps
|
|
32
|
+
def initialize(steps)
|
|
33
|
+
@steps = steps
|
|
34
|
+
super("cyclic steps found: <#{steps}>")
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
include TSort
|
|
25
39
|
|
|
26
|
-
def initialize(dispatcher
|
|
40
|
+
def initialize(dispatcher)
|
|
27
41
|
@dispatcher = dispatcher
|
|
28
|
-
@plugins = []
|
|
29
|
-
@options = options
|
|
30
|
-
# TODO: don't put the default distributions
|
|
31
|
-
load_plugins(options[:distributors] || ["search", "crud", "groonga", "watch"])
|
|
32
42
|
end
|
|
33
43
|
|
|
34
|
-
def distribute(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
44
|
+
def distribute(plan)
|
|
45
|
+
@dependency = {}
|
|
46
|
+
plan.each do |step|
|
|
47
|
+
@dependency[step] = step["inputs"]
|
|
48
|
+
next unless step["outputs"]
|
|
49
|
+
step["outputs"].each do |output|
|
|
50
|
+
@dependency[output] = [step]
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
steps = []
|
|
54
|
+
each_strongly_connected_component do |cs|
|
|
55
|
+
raise CyclicStepsError.new(cs) if cs.size > 1
|
|
56
|
+
steps.concat(cs) unless cs.first.is_a? String
|
|
57
|
+
end
|
|
58
|
+
@dispatcher.dispatch_steps(steps)
|
|
38
59
|
end
|
|
39
60
|
|
|
40
61
|
private
|
|
41
|
-
def
|
|
42
|
-
|
|
62
|
+
def tsort_each_node(&block)
|
|
63
|
+
@dependency.each_key(&block)
|
|
43
64
|
end
|
|
44
65
|
|
|
45
|
-
def
|
|
46
|
-
|
|
66
|
+
def tsort_each_child(node, &block)
|
|
67
|
+
if node.is_a? String and @dependency[node].nil?
|
|
68
|
+
raise UndefinedInputError.new(node)
|
|
69
|
+
end
|
|
70
|
+
if @dependency[node]
|
|
71
|
+
@dependency[node].each(&block)
|
|
72
|
+
end
|
|
47
73
|
end
|
|
48
74
|
end
|
|
49
75
|
end
|
data/lib/droonga/handler.rb
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
#
|
|
2
|
-
#
|
|
3
|
-
# Copyright (C) 2013 Droonga Project
|
|
1
|
+
# Copyright (C) 2014 Droonga Project
|
|
4
2
|
#
|
|
5
3
|
# This library is free software; you can redistribute it and/or
|
|
6
4
|
# modify it under the terms of the GNU Lesser General Public
|
|
@@ -15,87 +13,30 @@
|
|
|
15
13
|
# License along with this library; if not, write to the Free Software
|
|
16
14
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17
15
|
|
|
18
|
-
require "groonga"
|
|
19
|
-
|
|
20
|
-
require "droonga/forwarder"
|
|
21
|
-
require "droonga/handler_message"
|
|
22
|
-
require "droonga/handler_messenger"
|
|
23
16
|
require "droonga/pluggable"
|
|
24
|
-
require "droonga/
|
|
17
|
+
require "droonga/plugin/metadata/input_message"
|
|
18
|
+
require "droonga/plugin/metadata/handler_action"
|
|
25
19
|
|
|
26
20
|
module Droonga
|
|
27
21
|
class Handler
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
attr_reader :context, :name
|
|
31
|
-
|
|
32
|
-
def initialize(loop, options={})
|
|
33
|
-
@loop = loop
|
|
34
|
-
@options = options
|
|
35
|
-
@name = options[:name]
|
|
36
|
-
@database_name = options[:database]
|
|
37
|
-
prepare
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def start
|
|
41
|
-
$log.trace("#{log_tag}: start: start")
|
|
42
|
-
@forwarder.start
|
|
43
|
-
$log.trace("#{log_tag}: start: done")
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def shutdown
|
|
47
|
-
$log.trace("#{log_tag}: shutdown: start")
|
|
48
|
-
super
|
|
49
|
-
@forwarder.shutdown
|
|
50
|
-
if @database
|
|
51
|
-
@database.close
|
|
52
|
-
@context.close
|
|
53
|
-
@database = @context = nil
|
|
54
|
-
end
|
|
55
|
-
$log.trace("#{log_tag}: shutdown: done")
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def prefer_synchronous?(command)
|
|
59
|
-
find_plugin(command).prefer_synchronous?(command)
|
|
60
|
-
end
|
|
22
|
+
extend Pluggable
|
|
61
23
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
plugin = find_plugin(command)
|
|
66
|
-
if plugin.nil?
|
|
67
|
-
$log.trace("#{log_tag}: process: done: no plugin: <#{command}>")
|
|
68
|
-
return
|
|
24
|
+
class << self
|
|
25
|
+
def message
|
|
26
|
+
Plugin::Metadata::InputMessage.new(self)
|
|
69
27
|
end
|
|
70
|
-
process_command(plugin, command, message)
|
|
71
|
-
$log.trace("#{log_tag}: process: done: <#{command}>",
|
|
72
|
-
:plugin => plugin.class)
|
|
73
|
-
end
|
|
74
28
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if @database_name && !@database_name.empty?
|
|
78
|
-
@context = Groonga::Context.new
|
|
79
|
-
@database = @context.open_database(@database_name)
|
|
29
|
+
def action
|
|
30
|
+
Plugin::Metadata::HandlerAction.new(self)
|
|
80
31
|
end
|
|
81
|
-
load_plugins(@options[:handlers] || [])
|
|
82
|
-
@forwarder = Forwarder.new(@loop)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def instantiate_plugin(name)
|
|
86
|
-
HandlerPlugin.repository.instantiate(name, self)
|
|
87
32
|
end
|
|
88
33
|
|
|
89
|
-
def
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
messenger = HandlerMessenger.new(@forwarder, handler_message, @options)
|
|
94
|
-
plugin.process(command, handler_message, messenger)
|
|
34
|
+
def initialize(name, context)
|
|
35
|
+
@name = name
|
|
36
|
+
@context = context
|
|
95
37
|
end
|
|
96
38
|
|
|
97
|
-
def
|
|
98
|
-
"[#{Process.ppid}][#{Process.pid}] handler"
|
|
39
|
+
def handle(message, messenger)
|
|
99
40
|
end
|
|
100
41
|
end
|
|
101
42
|
end
|
|
@@ -25,8 +25,8 @@ module Droonga
|
|
|
25
25
|
raise "<task> value isn't object: <#{@raw.inspect}>"
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
unless
|
|
29
|
-
raise "<task/
|
|
28
|
+
unless step.is_a?(Hash)
|
|
29
|
+
raise "<task/step> value isn't object: <#{@raw.inspect}>"
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
@@ -42,12 +42,12 @@ module Droonga
|
|
|
42
42
|
@task ||= body["task"]
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
def
|
|
46
|
-
@
|
|
45
|
+
def step
|
|
46
|
+
@step ||= task["step"]
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def request
|
|
50
|
-
@request ||=
|
|
50
|
+
@request ||= step["body"]
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def id
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright (C) 2013 Droonga Project
|
|
1
|
+
# Copyright (C) 2013-2014 Droonga Project
|
|
2
2
|
#
|
|
3
3
|
# This library is free software; you can redistribute it and/or
|
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
|
@@ -63,6 +63,9 @@ module Droonga
|
|
|
63
63
|
"body" => body)
|
|
64
64
|
@replier.reply(response)
|
|
65
65
|
else
|
|
66
|
+
#XXX This is just a temporary solution. We should rewrite this,
|
|
67
|
+
# to put errors outside of the message body. Otherwise
|
|
68
|
+
# plugins cannot use the name "errors" for their message body.
|
|
66
69
|
body = {
|
|
67
70
|
"id" => @message.id,
|
|
68
71
|
"input" => "errors",
|
|
@@ -15,11 +15,11 @@
|
|
|
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/
|
|
18
|
+
require "droonga/legacy_plugin"
|
|
19
19
|
require "droonga/message_processing_error"
|
|
20
20
|
|
|
21
21
|
module Droonga
|
|
22
|
-
class HandlerPlugin <
|
|
22
|
+
class HandlerPlugin < LegacyPlugin
|
|
23
23
|
extend PluginRegisterable
|
|
24
24
|
|
|
25
25
|
def initialize(handler)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Copyright (C) 2013-2014 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 "groonga"
|
|
17
|
+
|
|
18
|
+
require "droonga/forwarder"
|
|
19
|
+
require "droonga/handler_message"
|
|
20
|
+
require "droonga/handler_messenger"
|
|
21
|
+
require "droonga/handler"
|
|
22
|
+
|
|
23
|
+
module Droonga
|
|
24
|
+
class HandlerRunner
|
|
25
|
+
def initialize(loop, options={})
|
|
26
|
+
@loop = loop
|
|
27
|
+
@options = options
|
|
28
|
+
@name = options[:name]
|
|
29
|
+
@database_name = options[:database]
|
|
30
|
+
prepare
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def start
|
|
34
|
+
$log.trace("#{log_tag}: start: start")
|
|
35
|
+
@forwarder.start
|
|
36
|
+
$log.trace("#{log_tag}: start: done")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def shutdown
|
|
40
|
+
$log.trace("#{log_tag}: shutdown: start")
|
|
41
|
+
@forwarder.shutdown
|
|
42
|
+
if @database
|
|
43
|
+
@database.close
|
|
44
|
+
@context.close
|
|
45
|
+
@database = @context = nil
|
|
46
|
+
end
|
|
47
|
+
$log.trace("#{log_tag}: shutdown: done")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def prefer_synchronous?(command)
|
|
51
|
+
find_handler_class(command).action.synchronous?
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def processable?(command)
|
|
55
|
+
not find_handler_class(command).nil?
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def process(message)
|
|
59
|
+
$log.trace("#{log_tag}: process: start")
|
|
60
|
+
command = message["type"]
|
|
61
|
+
handler_class = find_handler_class(command)
|
|
62
|
+
if handler_class.nil?
|
|
63
|
+
$log.trace("#{log_tag}: process: done: no handler: <#{command}>")
|
|
64
|
+
return
|
|
65
|
+
end
|
|
66
|
+
process_command(handler_class, command, message)
|
|
67
|
+
$log.trace("#{log_tag}: process: done: <#{command}>",
|
|
68
|
+
:handler => handler_class)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
def prepare
|
|
73
|
+
if @database_name && !@database_name.empty?
|
|
74
|
+
@context = Groonga::Context.new
|
|
75
|
+
@database = @context.open_database(@database_name)
|
|
76
|
+
end
|
|
77
|
+
@handler_classes = Handler.find_sub_classes(@options[:plugins] || [])
|
|
78
|
+
@forwarder = Forwarder.new(@loop)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def find_handler_class(command)
|
|
82
|
+
@handler_classes.find do |handler_class|
|
|
83
|
+
handler_class.message.type == command
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def process_command(handler_class, command, raw_message)
|
|
88
|
+
handler_message = HandlerMessage.new(raw_message)
|
|
89
|
+
handler_message.validate
|
|
90
|
+
|
|
91
|
+
messenger = HandlerMessenger.new(@forwarder, handler_message, @options)
|
|
92
|
+
handler = handler_class.new(@name, @context)
|
|
93
|
+
begin
|
|
94
|
+
handler.handle(handler_message, messenger)
|
|
95
|
+
rescue MessageProcessingError => error
|
|
96
|
+
messenger.error(error.status_code, error.response_body)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def log_tag
|
|
101
|
+
"[#{Process.ppid}][#{Process.pid}] handler"
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -28,10 +28,6 @@ module Droonga
|
|
|
28
28
|
@raw_message
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
def add_route(route)
|
|
32
|
-
@raw_message["via"].push(route)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
31
|
def body
|
|
36
32
|
@raw_message["body"]
|
|
37
33
|
end
|
|
@@ -45,6 +41,10 @@ module Droonga
|
|
|
45
41
|
end
|
|
46
42
|
|
|
47
43
|
def command=(command)
|
|
44
|
+
original_command = @raw_message["type"]
|
|
45
|
+
return if original_command == command
|
|
46
|
+
@raw_message["originalTypes"] ||= []
|
|
47
|
+
@raw_message["originalTypes"] << original_command
|
|
48
48
|
@raw_message["type"] = command
|
|
49
49
|
end
|
|
50
50
|
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Copyright (C) 2013-2014 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
|
+
module LegacyPluggable
|
|
18
|
+
class UnknownPlugin < StandardError
|
|
19
|
+
attr_reader :command
|
|
20
|
+
|
|
21
|
+
def initialize(command)
|
|
22
|
+
@command = command
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def shutdown
|
|
27
|
+
$log.trace("#{log_tag}: shutdown: plugin: start")
|
|
28
|
+
@plugins.each do |plugin|
|
|
29
|
+
plugin.shutdown
|
|
30
|
+
end
|
|
31
|
+
$log.trace("#{log_tag}: shutdown: plugin: done")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def processable?(command)
|
|
35
|
+
not find_plugin(command).nil?
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def process(command, *arguments)
|
|
39
|
+
plugin = find_plugin(command)
|
|
40
|
+
$log.trace("#{log_tag}: process: start: <#{command}>",
|
|
41
|
+
:plugin => plugin.class)
|
|
42
|
+
raise UnknownPlugin.new(command) if plugin.nil?
|
|
43
|
+
result = plugin.process(command, *arguments)
|
|
44
|
+
$log.trace("#{log_tag}: process: done: <#{command}>",
|
|
45
|
+
:plugin => plugin.class)
|
|
46
|
+
result
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
def load_plugins(names)
|
|
51
|
+
@plugins = names.collect do |name|
|
|
52
|
+
plugin = instantiate_plugin(name)
|
|
53
|
+
if plugin.nil?
|
|
54
|
+
raise "unknown plugin: <#{name}>: TODO: improve error handling"
|
|
55
|
+
end
|
|
56
|
+
plugin
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def find_plugin(command)
|
|
61
|
+
@plugins.find do |plugin|
|
|
62
|
+
plugin.processable?(command)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -15,38 +15,43 @@
|
|
|
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/input_adapter_plugin"
|
|
20
|
-
require "droonga/input_message"
|
|
18
|
+
require "droonga/plugin_registerable"
|
|
21
19
|
|
|
22
20
|
module Droonga
|
|
23
|
-
class
|
|
24
|
-
|
|
21
|
+
class LegacyPlugin
|
|
22
|
+
def initialize
|
|
23
|
+
end
|
|
25
24
|
|
|
26
|
-
def
|
|
27
|
-
@dispatcher = dispatcher
|
|
28
|
-
load_plugins(options[:plugins] || [])
|
|
25
|
+
def start
|
|
29
26
|
end
|
|
30
27
|
|
|
31
|
-
def
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
def shutdown
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def processable?(command)
|
|
32
|
+
self.class.processable?(command)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def process(command, *arguments)
|
|
36
|
+
run_command(command, *arguments)
|
|
37
|
+
rescue => exception
|
|
38
|
+
process_error(command, exception, arguments)
|
|
41
39
|
end
|
|
42
40
|
|
|
43
41
|
private
|
|
44
|
-
def
|
|
45
|
-
|
|
42
|
+
def run_command(command, *arguments)
|
|
43
|
+
if command.is_a?(Command)
|
|
44
|
+
method_name = command.method_name
|
|
45
|
+
else
|
|
46
|
+
method_name = self.class.method_name(command)
|
|
47
|
+
end
|
|
48
|
+
__send__(method_name, *arguments)
|
|
46
49
|
end
|
|
47
50
|
|
|
48
|
-
def
|
|
49
|
-
"
|
|
51
|
+
def process_error(command, error, arguments)
|
|
52
|
+
Logger.error("error while processing: <#{command}>",
|
|
53
|
+
error,
|
|
54
|
+
:arguments => arguments)
|
|
50
55
|
end
|
|
51
56
|
end
|
|
52
57
|
end
|