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.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -4
  3. data/benchmark/watch/benchmark-notify.rb +2 -2
  4. data/benchmark/watch/benchmark-scan.rb +3 -0
  5. data/benchmark/watch/fluentd.conf +0 -1
  6. data/fluent-plugin-droonga.gemspec +2 -3
  7. data/lib/droonga/catalog.rb +10 -124
  8. data/lib/droonga/catalog/base.rb +140 -0
  9. data/lib/droonga/catalog/version1.rb +23 -0
  10. data/lib/droonga/catalog_loader.rb +33 -0
  11. data/lib/droonga/collector.rb +2 -71
  12. data/lib/droonga/collector_plugin.rb +2 -34
  13. data/lib/droonga/dispatcher.rb +141 -196
  14. data/lib/droonga/distribution_planner.rb +76 -0
  15. data/lib/droonga/distributor.rb +5 -7
  16. data/lib/droonga/distributor_plugin.rb +23 -15
  17. data/lib/droonga/engine.rb +2 -2
  18. data/lib/droonga/event_loop.rb +46 -0
  19. data/lib/droonga/farm.rb +9 -5
  20. data/lib/droonga/fluent_message_sender.rb +84 -0
  21. data/lib/droonga/forwarder.rb +43 -53
  22. data/lib/droonga/handler.rb +20 -68
  23. data/lib/droonga/handler_message.rb +61 -0
  24. data/lib/droonga/handler_messenger.rb +92 -0
  25. data/lib/droonga/handler_plugin.rb +10 -12
  26. data/lib/droonga/input_adapter.rb +52 -0
  27. data/lib/droonga/{adapter.rb → input_adapter_plugin.rb} +7 -13
  28. data/lib/droonga/input_message.rb +11 -11
  29. data/lib/droonga/logger.rb +4 -3
  30. data/lib/droonga/message_pack_packer.rb +62 -0
  31. data/lib/droonga/message_processing_error.rb +54 -0
  32. data/lib/droonga/message_pusher.rb +60 -0
  33. data/lib/droonga/message_receiver.rb +61 -0
  34. data/lib/droonga/output_adapter.rb +53 -0
  35. data/lib/droonga/{adapter_plugin.rb → output_adapter_plugin.rb} +3 -21
  36. data/lib/droonga/output_message.rb +37 -0
  37. data/lib/droonga/partition.rb +27 -5
  38. data/lib/droonga/pluggable.rb +9 -4
  39. data/lib/droonga/plugin.rb +12 -3
  40. data/lib/droonga/plugin/collector/basic.rb +91 -18
  41. data/lib/droonga/plugin/distributor/crud.rb +9 -9
  42. data/lib/droonga/plugin/distributor/distributed_search_planner.rb +401 -0
  43. data/lib/droonga/plugin/distributor/groonga.rb +5 -5
  44. data/lib/droonga/plugin/distributor/search.rb +4 -246
  45. data/lib/droonga/plugin/distributor/watch.rb +11 -6
  46. data/lib/droonga/plugin/handler/add.rb +69 -7
  47. data/lib/droonga/plugin/handler/groonga.rb +6 -6
  48. data/lib/droonga/plugin/handler/search.rb +5 -3
  49. data/lib/droonga/plugin/handler/watch.rb +19 -13
  50. data/lib/droonga/plugin/{adapter → input_adapter}/groonga.rb +5 -11
  51. data/lib/droonga/plugin/{adapter → input_adapter}/groonga/select.rb +2 -36
  52. data/lib/droonga/plugin/output_adapter/groonga.rb +30 -0
  53. data/lib/droonga/plugin/output_adapter/groonga/select.rb +54 -0
  54. data/lib/droonga/plugin_loader.rb +2 -2
  55. data/lib/droonga/processor.rb +21 -23
  56. data/lib/droonga/replier.rb +40 -0
  57. data/lib/droonga/searcher.rb +298 -174
  58. data/lib/droonga/server.rb +0 -67
  59. data/lib/droonga/session.rb +85 -0
  60. data/lib/droonga/test.rb +21 -0
  61. data/lib/droonga/test/stub_distributor.rb +31 -0
  62. data/lib/droonga/test/stub_handler.rb +37 -0
  63. data/lib/droonga/test/stub_handler_message.rb +35 -0
  64. data/lib/droonga/test/stub_handler_messenger.rb +34 -0
  65. data/lib/droonga/time_formatter.rb +37 -0
  66. data/lib/droonga/watcher.rb +1 -0
  67. data/lib/droonga/worker.rb +16 -19
  68. data/lib/fluent/plugin/out_droonga.rb +9 -9
  69. data/lib/groonga_command_converter.rb +5 -5
  70. data/sample/cluster/catalog.json +1 -1
  71. data/test/command/config/default/catalog.json +19 -1
  72. data/test/command/fixture/event.jsons +41 -0
  73. data/test/command/fixture/user-table.jsons +9 -0
  74. data/test/command/run-test.rb +2 -2
  75. data/test/command/suite/add/error/invalid-integer.expected +20 -0
  76. data/test/command/suite/add/error/invalid-integer.test +12 -0
  77. data/test/command/suite/add/error/invalid-time.expected +20 -0
  78. data/test/command/suite/add/error/invalid-time.test +12 -0
  79. data/test/command/suite/add/error/missing-key.expected +13 -0
  80. data/test/command/suite/add/error/missing-key.test +16 -0
  81. data/test/command/suite/add/error/missing-table.expected +13 -0
  82. data/test/command/suite/add/error/missing-table.test +16 -0
  83. data/test/command/suite/add/error/unknown-column.expected +20 -0
  84. data/test/command/suite/add/error/unknown-column.test +12 -0
  85. data/test/command/suite/add/error/unknown-table.expected +13 -0
  86. data/test/command/suite/add/error/unknown-table.test +17 -0
  87. data/test/command/suite/add/minimum.expected +1 -3
  88. data/test/command/suite/add/with-values.expected +1 -3
  89. data/test/command/suite/add/without-key.expected +1 -3
  90. data/test/command/suite/message/error/missing-dataset.expected +13 -0
  91. data/test/command/suite/message/error/missing-dataset.test +5 -0
  92. data/test/command/suite/message/error/unknown-command.expected +13 -0
  93. data/test/command/suite/message/error/unknown-command.test +6 -0
  94. data/test/command/suite/message/error/unknown-dataset.expected +13 -0
  95. data/test/command/suite/message/error/unknown-dataset.test +6 -0
  96. data/test/command/suite/search/{array-attribute-label.expected → attributes/array.expected} +0 -0
  97. data/test/command/suite/search/{array-attribute-label.test → attributes/array.test} +0 -0
  98. data/test/command/suite/search/{hash-attribute-label.expected → attributes/hash.expected} +0 -0
  99. data/test/command/suite/search/{hash-attribute-label.test → attributes/hash.test} +0 -0
  100. data/test/command/suite/search/{condition-nested.expected → condition/nested.expected} +0 -0
  101. data/test/command/suite/search/{condition-nested.test → condition/nested.test} +0 -0
  102. data/test/command/suite/search/{condition-query.expected → condition/query.expected} +0 -0
  103. data/test/command/suite/search/{condition-query.test → condition/query.test} +0 -0
  104. data/test/command/suite/search/{condition-script.expected → condition/script.expected} +0 -0
  105. data/test/command/suite/search/{condition-script.test → condition/script.test} +0 -0
  106. data/test/command/suite/search/error/cyclic-source.expected +18 -0
  107. data/test/command/suite/search/error/cyclic-source.test +12 -0
  108. data/test/command/suite/search/error/deeply-cyclic-source.expected +21 -0
  109. data/test/command/suite/search/error/deeply-cyclic-source.test +15 -0
  110. data/test/command/suite/search/error/missing-source-parameter.expected +17 -0
  111. data/test/command/suite/search/error/missing-source-parameter.test +11 -0
  112. data/test/command/suite/search/error/unknown-source.expected +18 -0
  113. data/test/command/suite/search/error/unknown-source.test +12 -0
  114. data/test/command/suite/search/{minimum.expected → group/count.expected} +2 -1
  115. data/test/command/suite/search/{minimum.test → group/count.test} +5 -3
  116. data/test/command/suite/search/group/limit.expected +19 -0
  117. data/test/command/suite/search/group/limit.test +20 -0
  118. data/test/command/suite/search/group/string.expected +36 -0
  119. data/test/command/suite/search/group/string.test +44 -0
  120. data/test/command/suite/search/{chained-queries.expected → multiple/chained.expected} +0 -0
  121. data/test/command/suite/search/{chained-queries.test → multiple/chained.test} +0 -0
  122. data/test/command/suite/search/{multiple-queries.expected → multiple/parallel.expected} +0 -0
  123. data/test/command/suite/search/{multiple-queries.test → multiple/parallel.test} +0 -0
  124. data/test/command/suite/search/{output-range.expected → range/only-output.expected} +0 -0
  125. data/test/command/suite/search/{output-range.test → range/only-output.test} +0 -0
  126. data/test/command/suite/search/{sort-range.expected → range/only-sort.expected} +0 -0
  127. data/test/command/suite/search/{sort-range.test → range/only-sort.test} +0 -0
  128. data/test/command/suite/search/{sort-and-output-range.expected → range/sort-and-output.expected} +0 -0
  129. data/test/command/suite/search/{sort-and-output-range.test → range/sort-and-output.test} +0 -0
  130. data/test/command/suite/search/range/too-large-output-offset.expected +16 -0
  131. data/test/command/suite/search/range/too-large-output-offset.test +25 -0
  132. data/test/command/suite/search/range/too-large-sort-offset.expected +16 -0
  133. data/test/command/suite/search/range/too-large-sort-offset.test +28 -0
  134. data/test/command/suite/search/response/records/value/time.expected +24 -0
  135. data/test/command/suite/search/response/records/value/time.test +24 -0
  136. data/test/command/suite/search/sort/default-offset-limit.expected +43 -0
  137. data/test/command/suite/search/sort/default-offset-limit.test +26 -0
  138. data/test/command/suite/search/{sort-with-invisible-column.expected → sort/invisible-column.expected} +0 -0
  139. data/test/command/suite/search/{sort-with-invisible-column.test → sort/invisible-column.test} +0 -0
  140. data/test/command/suite/watch/subscribe.expected +12 -0
  141. data/test/command/suite/watch/subscribe.test +9 -0
  142. data/test/command/suite/watch/unsubscribe.expected +12 -0
  143. data/test/command/suite/watch/unsubscribe.test +9 -0
  144. data/test/unit/{test_catalog.rb → catalog/test_version1.rb} +12 -4
  145. data/test/unit/fixtures/{catalog.json → catalog/version1.json} +0 -0
  146. data/test/unit/helper.rb +2 -0
  147. data/test/unit/plugin/collector/test_basic.rb +289 -33
  148. data/test/unit/plugin/distributor/test_search.rb +176 -861
  149. data/test/unit/plugin/distributor/test_search_planner.rb +1102 -0
  150. data/test/unit/plugin/handler/groonga/test_column_create.rb +17 -13
  151. data/test/unit/plugin/handler/groonga/test_table_create.rb +10 -10
  152. data/test/unit/plugin/handler/test_add.rb +74 -11
  153. data/test/unit/plugin/handler/test_groonga.rb +15 -1
  154. data/test/unit/plugin/handler/test_search.rb +33 -17
  155. data/test/unit/plugin/handler/test_watch.rb +43 -27
  156. data/test/unit/run-test.rb +2 -0
  157. data/test/unit/test_message_pack_packer.rb +51 -0
  158. data/test/unit/test_time_formatter.rb +29 -0
  159. metadata +208 -110
  160. data/lib/droonga/job_queue.rb +0 -87
  161. data/lib/droonga/job_queue_schema.rb +0 -65
  162. data/test/unit/test_adapter.rb +0 -51
  163. data/test/unit/test_job_queue_schema.rb +0 -45
@@ -15,8 +15,6 @@
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/job_queue"
19
-
20
18
  module Droonga
21
19
  module Server
22
20
  def before_run
@@ -39,70 +37,5 @@ module Droonga
39
37
  def log_tag
40
38
  "[#{Process.ppid}][#{Process.pid}] server"
41
39
  end
42
-
43
- def start_worker(wid)
44
- worker = super(wid)
45
- worker.extend(WorkerStopper)
46
- worker
47
- end
48
-
49
- module WorkerStopper
50
- def send_stop(stop_graceful)
51
- in_signal_sending do
52
- open_queue do |queue|
53
- $log.trace("#{log_tag}: stop: start")
54
-
55
- $log.trace("#{log_tag}: stop: queue: unblock: start")
56
- max_n_retries = 20
57
- max_n_retries.times do |i|
58
- $log.trace("#{log_tag}: stop: queue: unblock: #{i}: start")
59
- super(stop_graceful)
60
- queue.unblock
61
- alive_p = alive?
62
- $log.trace("#{log_tag}: stop: queue: unblock: #{i}: done: " +
63
- "#{alive_p}")
64
- break unless alive_p
65
- sleep(i * 0.1)
66
- end
67
- $log.trace("#{log_tag}: stop: queue: unblock: done")
68
-
69
- $log.trace("#{log_tag}: stop: done")
70
- end
71
- end
72
- end
73
-
74
- def send_reload
75
- in_signal_sending do
76
- open_queue do |queue|
77
- $log.trace("#{log_tag}: reload: start")
78
- super
79
- queue.unblock
80
- $log.trace("#{log_tag}: reload: done")
81
- end
82
- end
83
- end
84
-
85
- private
86
- def log_tag
87
- "[#{Process.ppid}][#{Process.pid}][#{@wid}] server: worker-stopper"
88
- end
89
-
90
- def in_signal_sending
91
- Thread.new do
92
- yield
93
- end
94
- end
95
-
96
- def open_queue
97
- config = @worker.config
98
- queue = JobQueue.open(config[:database],
99
- config[:queue_name] || "DroongaQueue")
100
- begin
101
- yield(queue)
102
- ensure
103
- queue.close
104
- end
105
- end
106
- end
107
40
  end
108
41
  end
@@ -0,0 +1,85 @@
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 Session
18
+ def initialize(id, dispatcher, collector, tasks, inputs)
19
+ @id = id
20
+ @dispatcher = dispatcher
21
+ @collector = collector
22
+ @tasks = tasks
23
+ @n_dones = 0
24
+ @inputs = inputs
25
+ end
26
+
27
+ def done?
28
+ @n_dones == @tasks.size
29
+ end
30
+
31
+ def start
32
+ tasks = @inputs[nil]
33
+ tasks.each do |task|
34
+ local_message = {
35
+ "id" => @id,
36
+ "task" => task,
37
+ }
38
+ @dispatcher.process_local_message(local_message)
39
+ @n_dones += 1
40
+ end
41
+ end
42
+
43
+ def receive(name, value)
44
+ tasks = @inputs[name]
45
+ unless tasks
46
+ #TODO: result arrived before its query
47
+ return
48
+ end
49
+ tasks.each do |task|
50
+ task["n_of_inputs"] += 1
51
+ component = task["component"]
52
+ type = component["type"]
53
+ command = "collector_" + type
54
+ n_of_expects = component["n_of_expects"]
55
+ message = {
56
+ "task"=>task,
57
+ "name"=>name,
58
+ "value"=>value
59
+ }
60
+ @collector.process(command, message)
61
+ return if task["n_of_inputs"] < n_of_expects
62
+ #the task is done
63
+ result = task["values"]
64
+ post = component["post"]
65
+ @dispatcher.reply("body" => result) if post
66
+ component["descendants"].each do |name, routes|
67
+ message = {
68
+ "id" => @id,
69
+ "input" => name,
70
+ "value" => result[name]
71
+ }
72
+ routes.each do |route|
73
+ @dispatcher.dispatch(message, route)
74
+ end
75
+ end
76
+ @n_dones += 1
77
+ end
78
+ end
79
+
80
+ private
81
+ def log_tag
82
+ "session"
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,21 @@
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/test/stub_distributor"
19
+ require "droonga/test/stub_handler"
20
+ require "droonga/test/stub_handler_message"
21
+ require "droonga/test/stub_handler_messenger"
@@ -0,0 +1,31 @@
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
+ module Droonga
19
+ module Test
20
+ class StubDistributor
21
+ attr_reader :messages
22
+ def initialize
23
+ @messages = []
24
+ end
25
+
26
+ def distribute(message)
27
+ @messages << message
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,37 @@
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
+ module Droonga
19
+ module Test
20
+ class StubHandler
21
+ attr_reader :context, :envelope, :messages
22
+ def initialize
23
+ @context = Groonga::Context.default
24
+ @envelope = {}
25
+ @messages = []
26
+ end
27
+
28
+ def emit(message)
29
+ @messages << message
30
+ end
31
+
32
+ def forward(message, destination)
33
+ @messages << [message, destination]
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,35 @@
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/handler_message"
17
+
18
+ module Droonga
19
+ module Test
20
+ class StubHandlerMessage < HandlerMessage
21
+ def initialize(request, headers={})
22
+ raw = {
23
+ "body" => {
24
+ "task" => {
25
+ "component" => {
26
+ "body" => request,
27
+ },
28
+ },
29
+ },
30
+ }
31
+ super(headers.merge(raw))
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,34 @@
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
+ module Test
18
+ class StubHandlerMessenger
19
+ attr_reader :values, :messages
20
+ def initialize
21
+ @values = []
22
+ @messages = []
23
+ end
24
+
25
+ def emit(value)
26
+ @values << value
27
+ end
28
+
29
+ def forward(message, destination)
30
+ @messages << [message, destination]
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
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 "time"
17
+
18
+ module Droonga
19
+ class TimeFormatter
20
+ class << self
21
+ def format(object)
22
+ formatter = new(object)
23
+ formatter.format
24
+ end
25
+ end
26
+
27
+ MICRO_SECONDS_DECIMAL_PLACE = 6
28
+
29
+ def initialize(time)
30
+ @time = time
31
+ end
32
+
33
+ def format
34
+ @time.utc.iso8601(MICRO_SECONDS_DECIMAL_PLACE)
35
+ end
36
+ end
37
+ end
@@ -99,6 +99,7 @@ module Droonga
99
99
  targets.each do |key, target|
100
100
  scan_body(hits, target)
101
101
  end
102
+ hits.uniq! # hits may be duplicated if multiple targets are matched
102
103
 
103
104
  publish(hits, request, &block)
104
105
  end
@@ -15,44 +15,41 @@
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/job_queue"
18
+ require "droonga/event_loop"
19
19
  require "droonga/handler"
20
+ require "droonga/message_receiver"
20
21
 
21
22
  module Droonga
22
23
  module Worker
23
24
  def initialize
24
- @database_name = config[:database]
25
- @queue_name = config[:queue_name] || "DroongaQueue"
25
+ @loop = EventLoop.new
26
+ @handler = Handler.new(@loop, config.merge(:dispatcher => nil))
27
+ receiver_socket = config[:message_receiver]
28
+ @message_receiver = MessageReceiver.new(@loop, receiver_socket) do |message|
29
+ process(message)
30
+ end
26
31
  end
27
32
 
28
33
  def run
29
34
  $log.trace("#{log_tag}: run: start")
30
- handler = Handler.new(config)
31
- job_queue = JobQueue.open(@database_name, @queue_name)
32
- @running = true
33
- while @running
34
- process(handler, job_queue)
35
- end
36
- handler.shutdown
37
- job_queue.close
35
+ @handler.start
36
+ @message_receiver.start
37
+ @loop.run
38
+ @handler.shutdown
38
39
  $log.trace("#{log_tag}: run: done")
39
40
  end
40
41
 
41
42
  def stop
42
43
  $log.trace("#{log_tag}: stop: start")
43
- @running = false
44
+ @message_receiver.shutdown
45
+ @loop.stop
44
46
  $log.trace("#{log_tag}: stop: done")
45
47
  end
46
48
 
47
49
  private
48
- def process(handler, job_queue)
50
+ def process(message)
49
51
  $log.trace("#{log_tag}: process: start")
50
- envelope = job_queue.pull_message
51
- unless envelope
52
- $log.trace("#{log_tag}: process: abort: no message")
53
- return
54
- end
55
- handler.process(envelope)
52
+ @handler.process(message)
56
53
  $log.trace("#{log_tag}: process: done")
57
54
  end
58
55
 
@@ -45,30 +45,30 @@ module Fluent
45
45
 
46
46
  private
47
47
  def process_event(tag, record)
48
- $log.trace("out_droonga: tag: <#{tag}> caller: <#{caller.first}>")
48
+ $log.trace("out_droonga: tag: <#{tag}>")
49
49
  @engine.process(parse_record(tag, record))
50
50
  end
51
51
 
52
52
  def parse_record(tag, record)
53
53
  prefix, type, *arguments = tag.split(/\./)
54
- if type.nil? || type.empty? || type == 'message'
55
- envelope = record
54
+ if type.nil? || type.empty? || type == "message"
55
+ message = record
56
56
  else
57
- envelope = {
57
+ message = {
58
58
  "type" => type,
59
59
  "arguments" => arguments,
60
60
  "body" => record
61
61
  }
62
62
  end
63
- envelope["via"] ||= []
64
- reply_to = envelope["replyTo"]
63
+ message["via"] ||= []
64
+ reply_to = message["replyTo"]
65
65
  if reply_to.is_a? String
66
- envelope["replyTo"] = {
67
- "type" => envelope["type"] + ".result",
66
+ message["replyTo"] = {
67
+ "type" => "#{message["type"]}.result",
68
68
  "to" => reply_to
69
69
  }
70
70
  end
71
- envelope
71
+ message
72
72
  end
73
73
  end
74
74
  end