Kouhei Sutou
null+****@clear*****
Fri Feb 28 15:41:52 JST 2014
Kouhei Sutou 2014-02-28 15:41:52 +0900 (Fri, 28 Feb 2014) New Revision: e75f578bd23325971f7db223c7c762af0e3a10be https://github.com/droonga/droonga.org/commit/e75f578bd23325971f7db223c7c762af0e3a10be Message: Use f-p-d's logger Modified files: _po/ja/reference/plugin/adapter/index.po _po/ja/tutorial/plugin-development/adapter/index.po _po/ja/tutorial/plugin-development/handler/index.po ja/reference/plugin/adapter/index.md ja/tutorial/plugin-development/adapter/index.md ja/tutorial/plugin-development/handler/index.md tutorial/plugin-development/adapter/index.md Modified: _po/ja/reference/plugin/adapter/index.po (+2 -1) =================================================================== --- _po/ja/reference/plugin/adapter/index.po 2014-02-28 15:22:06 +0900 (5fd580e) +++ _po/ja/reference/plugin/adapter/index.po 2014-02-28 15:41:52 +0900 (ad2d28c) @@ -47,7 +47,8 @@ msgstr "" msgid "" "module Droonga::Plugins::FooPlugin\n" -" Plugin.registry.register(\"foo\", self)" +" extend Plugin\n" +" register(\"foo\")" msgstr "" msgid "" Modified: _po/ja/tutorial/plugin-development/adapter/index.po (+20 -16) =================================================================== --- _po/ja/tutorial/plugin-development/adapter/index.po 2014-02-28 15:22:06 +0900 (59927c7) +++ _po/ja/tutorial/plugin-development/adapter/index.po 2014-02-28 15:41:52 +0900 (ee27d73) @@ -112,10 +112,8 @@ msgid "" "module Droonga\n" " module Plugins\n" " module SampleLoggerPlugin\n" -" extend Plugin" -msgstr "" - -msgid " registry.register(\"sample-logger\", self)" +" extend Plugin\n" +" register(\"sample-logger\")" msgstr "" msgid "" @@ -283,7 +281,8 @@ msgid "" "~~~ruby\n" "(snip)\n" " module SampleLoggerPlugin\n" -" Plugin.registry.register(\"sample-logger\", self)" +" extend Plugin\n" +" register(\"sample-logger\")" msgstr "" msgid "" @@ -293,7 +292,8 @@ msgstr "" msgid "" " def adapt_input(input_message)\n" -" $log.info(\"SampleLoggerPlugin::Adapter\", :message => input_message)\n" +" logger.info(\"SampleLoggerPlugin::Adapter\", :message => input_message" +")\n" " end\n" " end\n" " end\n" @@ -392,7 +392,8 @@ msgid "" "~~~ruby\n" "(snip)\n" " def adapt_input(input_message)\n" -" $log.info(\"SampleLoggerPlugin::Adapter\", :message => input_message)\n" +" logger.info(\"SampleLoggerPlugin::Adapter\", :message => input_message" +")\n" " input_message.body[\"queries\"][\"stores\"][\"output\"][\"limit\"] = 1\n" " end\n" "(snip)\n" @@ -483,8 +484,8 @@ msgstr "" msgid "" " def adapt_output(output_message)\n" -" $log.info(\"SampleLoggerPlugin::Adapter\", :message => output_message)" -"\n" +" logger.info(\"SampleLoggerPlugin::Adapter\", :message => output_messag" +"e)\n" " end\n" " end\n" " end\n" @@ -570,8 +571,8 @@ msgid "" "~~~ruby\n" "(snip)\n" " def adapt_output(output_message)\n" -" $log.info(\"SampleLoggerPlugin::Adapter\", :message => output_message)" -"\n" +" logger.info(\"SampleLoggerPlugin::Adapter\", :message => output_messag" +"e)\n" " output_message.body[\"stores\"][\"completedAt\"] = Time.now\n" " end\n" "(snip)\n" @@ -668,7 +669,8 @@ msgid "" "module Droonga\n" " module Plugins\n" " module StoreSearchPlugin\n" -" Plugin.registry.register(\"store-search\", self)" +" extend Plugin\n" +" register(\"store-search\")" msgstr "" msgid "" @@ -678,12 +680,12 @@ msgstr "" msgid "" " def adapt_input(input_message)\n" -" $log.info(\"StoreSearchPlugin::Adapter\", :message => input_message)" +" logger.info(\"StoreSearchPlugin::Adapter\", :message => input_message)" msgstr "" msgid "" " query = input_message.body[\"query\"]\n" -" $log.info(\"storeSearch\", :query => query)" +" logger.info(\"storeSearch\", :query => query)" msgstr "" msgid "" @@ -836,12 +838,14 @@ msgid "" "~~~ruby\n" "(snip)\n" " module StoreSearchPlugin\n" -" Plugin.registry.register(\"store-search\", self)" +" extend Plugin\n" +" register(\"store-search\")" msgstr "" msgid "" " def adapt_output(output_message)\n" -" $log.info(\"StoreSearchPlugin::Adapter\", :message => output_message)" +" logger.info(\"StoreSearchPlugin::Adapter\", :message => output_message" +")" msgstr "" msgid "" Modified: _po/ja/tutorial/plugin-development/handler/index.po (+40 -18) =================================================================== --- _po/ja/tutorial/plugin-development/handler/index.po 2014-02-28 15:22:06 +0900 (e782344) +++ _po/ja/tutorial/plugin-development/handler/index.po 2014-02-28 15:41:52 +0900 (f71a639) @@ -175,7 +175,8 @@ msgid "" "module Droonga\n" " module Plugins\n" " module CountRecordsPlugin\n" -" Plugin.registry.register(\"count-records\", self)\n" +" extend Plugin\n" +" register(\"count-records\")\n" " end\n" " end\n" "end\n" @@ -192,7 +193,8 @@ msgid "" "module Droonga\n" " module Plugins\n" " module CountRecordsPlugin\n" -" Plugin.registry.register(\"count-records\", self)" +" extend Plugin\n" +" register(\"count-records\")" msgstr "" msgid "" @@ -248,7 +250,8 @@ msgid "" msgstr "" msgid "" -"Currently the handler does nothing and returns an array of a number.\n" +"Currently the handler does nothing and returns an result including an array of" +" a number.\n" "The returned value is used to construct the response body." msgstr "" @@ -272,14 +275,14 @@ msgid "" " define_single_step do |step|\n" " step.name = \"countRecords\"\n" " step.handler = :Handler\n" -" step.collector = SumCollector\n" +" step.collector = Collectors::Sum\n" " end\n" "(snip)\n" "~~~" msgstr "" msgid "" -"The `SumCollector` is one of built-in collectors.\n" +"The `Collectors::Sum` is one of built-in collectors.\n" "It merges results retuned from handler instances for each partition to one res" "ult." msgstr "" @@ -318,7 +321,9 @@ msgid "" "luentd.pid" msgstr "" -msgid "Then, send a message for the `countRecords` command to the Droonga Engine." +msgid "" +"Then, send a request message for the `countRecords` command to the Droonga Eng" +"ine." msgstr "" msgid "" @@ -357,23 +362,23 @@ msgid "" " * Remember that we have configured the `Starbucks` dataset to use 3 partition" "s (and each has 2 replicas) in the `catalog.json` of [the basic tutorial][basi" "c].\n" -" * Because it is a read-only command, an incoming message is distributed only " -"to paritions, not to replicas.\n" +" * Because it is a read-only command, a request is delivered only to paritions" +", not to replicas.\n" " So there are only 3 results, not 6.\n" " (TODO: I have to add a figure to indicate active nodes: [000, 001, 010, 011" ", 020, 021] => [000, 011, 020])\n" -" * The `SumCollector` collects them.\n" +" * The `Collectors::Sum` collects them.\n" " Those 3 results are joined to just one array by the collector." msgstr "" -msgid "As the result, just one array with 3 elements appears in the response message." +msgid "As the result, just one array with 3 elements appears in the final response." msgstr "" msgid "### Read-only access to the storage" msgstr "" msgid "" -"Now, each instance of the handler class always returns `[0]` as its result.\n" +"Now, each instance of the handler class always returns `0` as its result.\n" "Let's implement codes to count up the number of records from the actual storag" "e." msgstr "" @@ -383,7 +388,8 @@ msgid "" "(snip)\n" " class Handler < Droonga::Handler\n" " def handle(message)\n" -" table_name = message[\"body\"][\"table\"]\n" +" request = message.request\n" +" table_name = request[\"body\"][\"table\"]\n" " table = @context[table_name]\n" " count = table.size\n" " [count]\n" @@ -394,6 +400,14 @@ msgid "" msgstr "" msgid "" +"Look at the argument of the `handle` method.\n" +"It is different from the one an adapter receives.\n" +"A handler receives a message meaning a distributed task.\n" +"So you have to extract the request message from the distributed task by the co" +"de `request = message.request`." +msgstr "" + +msgid "" "The instance variable `@context` is an instance of `Groonga::Context` for the " "storage of the partition.\n" "See the [class reference of Rroonga][Groonga::Context].\n" @@ -512,7 +526,8 @@ msgid "" "module Droonga\n" " module Plugins\n" " module DeleteStoresPlugin\n" -" Plugin.registry.register(\"delete-stores\", self)\n" +" extend Plugin\n" +" register(\"delete-stores\")\n" " end\n" " end\n" "end\n" @@ -526,7 +541,8 @@ msgid "" "module Droonga\n" " module Plugins\n" " module DeleteStoresPlugin\n" -" Plugin.registry.register(\"delete-stores\", self)" +" extend Plugin\n" +" register(\"delete-stores\")" msgstr "" msgid "" @@ -553,14 +569,15 @@ msgid "" " step.name = \"deleteStores\"\n" " step.write = true\n" " step.handler = :Handler\n" -" step.collector = AndCollector\n" +" step.collector = Collectors::And\n" " end" msgstr "" msgid "" " class Handler < Droonga::Handler\n" " def handle(message)\n" -" keyword = message[\"body\"][\"keyword\"]\n" +" request = message.request\n" +" keyword = request[\"body\"][\"keyword\"]\n" " table = @context[\"Store\"]\n" " table.delete do |record|\n" " record.key @ keyword\n" @@ -575,13 +592,18 @@ msgid "" msgstr "" msgid "" +"Remember, you have to extract the request message from the received task messa" +"ge." +msgstr "" + +msgid "" "The handler finds and deletes existing records which have the given keyword in" " its \"key\", by the [API of Rroonga][Groonga::Table_delete]." msgstr "" msgid "" -"And, the `AndCollector` is bound to the step by the configuration `step.collec" -"tor`.\n" +"And, the `Collectors::And` is bound to the step by the configuration `step.col" +"lector`.\n" "It is is also one of built-in collectors, and merges boolean values retuned fr" "om handler instances for each partition and replica, to one boolean value." msgstr "" Modified: ja/reference/plugin/adapter/index.md (+2 -1) =================================================================== --- ja/reference/plugin/adapter/index.md 2014-02-28 15:22:06 +0900 (9fb7be3) +++ ja/reference/plugin/adapter/index.md 2014-02-28 15:41:52 +0900 (d31766b) @@ -29,7 +29,8 @@ For example, here is a sample plugin named "foo" with an adapter: require "droonga/plugin" module Droonga::Plugins::FooPlugin - Plugin.registry.register("foo", self) + extend Plugin + register("foo") class Adapter < Droonga::Adapter # operations to configure this adapter Modified: ja/tutorial/plugin-development/adapter/index.md (+16 -13) =================================================================== --- ja/tutorial/plugin-development/adapter/index.md 2014-02-28 15:22:06 +0900 (9f5a856) +++ ja/tutorial/plugin-development/adapter/index.md 2014-02-28 15:41:52 +0900 (6495fa2) @@ -73,8 +73,7 @@ module Droonga module Plugins module SampleLoggerPlugin extend Plugin - - registry.register("sample-logger", self) + register("sample-logger") class Adapter < Droonga::Adapter # You'll put codes to modify messages here. @@ -200,13 +199,14 @@ lib/droonga/plugins/sample-logger.rb: ~~~ruby (snip) module SampleLoggerPlugin - Plugin.registry.register("sample-logger", self) + extend Plugin + register("sample-logger") class Adapter < Droonga::Adapter input_message.pattern = ["type", :equal, "search"] def adapt_input(input_message) - $log.info("SampleLoggerPlugin::Adapter", :message => input_message) + logger.info("SampleLoggerPlugin::Adapter", :message => input_message) end end end @@ -277,7 +277,7 @@ lib/droonga/plugins/sample-logger.rb: ~~~ruby (snip) def adapt_input(input_message) - $log.info("SampleLoggerPlugin::Adapter", :message => input_message) + logger.info("SampleLoggerPlugin::Adapter", :message => input_message) input_message.body["queries"]["stores"]["output"]["limit"] = 1 end (snip) @@ -347,13 +347,14 @@ lib/droonga/plugins/sample-logger.rb: ~~~ruby (snip) module SampleLoggerPlugin - Plugin.registry.register("sample-logger", self) + extend Plugin + register("sample-logger") class Adapter < Droonga::Adapter (snip) def adapt_output(output_message) - $log.info("SampleLoggerPlugin::Adapter", :message => output_message) + logger.info("SampleLoggerPlugin::Adapter", :message => output_message) end end end @@ -421,7 +422,7 @@ lib/droonga/plugins/sample-logger.rb: ~~~ruby (snip) def adapt_output(output_message) - $log.info("SampleLoggerPlugin::Adapter", :message => output_message) + logger.info("SampleLoggerPlugin::Adapter", :message => output_message) output_message.body["stores"]["completedAt"] = Time.now end (snip) @@ -495,16 +496,17 @@ require "droonga/plugin" module Droonga module Plugins module StoreSearchPlugin - Plugin.registry.register("store-search", self) + extend Plugin + register("store-search") class Adapter < Droonga::Adapter input_message.pattern = ["type", :equal, "storeSearch"] def adapt_input(input_message) - $log.info("StoreSearchPlugin::Adapter", :message => input_message) + logger.info("StoreSearchPlugin::Adapter", :message => input_message) query = input_message.body["query"] - $log.info("storeSearch", :query => query) + logger.info("storeSearch", :query => query) body = { "queries" => { @@ -629,13 +631,14 @@ lib/droonga/plugins/store-search.rb: ~~~ruby (snip) module StoreSearchPlugin - Plugin.registry.register("store-search", self) + extend Plugin + register("store-search") class Adapter < Droonga::Adapter (snip) def adapt_output(output_message) - $log.info("StoreSearchPlugin::Adapter", :message => output_message) + logger.info("StoreSearchPlugin::Adapter", :message => output_message) records = output_message.body["stores"]["records"] simplified_results = records.flatten Modified: ja/tutorial/plugin-development/handler/index.md (+33 -18) =================================================================== --- ja/tutorial/plugin-development/handler/index.md 2014-02-28 15:22:06 +0900 (2af5cfb) +++ ja/tutorial/plugin-development/handler/index.md 2014-02-28 15:41:52 +0900 (9faa2cc) @@ -114,7 +114,8 @@ require "droonga/plugin" module Droonga module Plugins module CountRecordsPlugin - Plugin.registry.register("count-records", self) + extend Plugin + register("count-records") end end end @@ -132,7 +133,8 @@ require "droonga/plugin" module Droonga module Plugins module CountRecordsPlugin - Plugin.registry.register("count-records", self) + extend Plugin + register("count-records") define_single_step do |step| step.name = "countRecords" @@ -159,7 +161,8 @@ require "droonga/plugin" module Droonga module Plugins module CountRecordsPlugin - Plugin.registry.register("count-records", self) + extend Plugin + register("count-records") define_single_step do |step| step.name = "countRecords" @@ -182,7 +185,7 @@ The class `Handler` is a handler class for our new command. * It implements the logic to handle requests. Its instance method `#handle` actually handles requests. -Currently the handler does nothing and returns an array of a number. +Currently the handler does nothing and returns an result including an array of a number. The returned value is used to construct the response body. The handler is bound to the step with the configuration `step.handler`. @@ -199,12 +202,12 @@ lib/droonga/plugins/count-records.rb: define_single_step do |step| step.name = "countRecords" step.handler = :Handler - step.collector = SumCollector + step.collector = Collectors::Sum end (snip) ~~~ -The `SumCollector` is one of built-in collectors. +The `Collectors::Sum` is one of built-in collectors. It merges results retuned from handler instances for each partition to one result. @@ -230,7 +233,7 @@ Note that you need to specify ./lib directory in RUBYLIB environment variable in # kill $(cat fluentd.pid) # RUBYLIB=./lib fluentd --config fluentd.conf --log fluentd.log --daemon fluentd.pid -Then, send a message for the `countRecords` command to the Droonga Engine. +Then, send a request message for the `countRecords` command to the Droonga Engine. ~~~ # droonga-request --tag starbucks count-records.json @@ -257,17 +260,17 @@ Look at these points: There are 3 elements in the array. Why? * Remember that we have configured the `Starbucks` dataset to use 3 partitions (and each has 2 replicas) in the `catalog.json` of [the basic tutorial][basic]. - * Because it is a read-only command, an incoming message is distributed only to paritions, not to replicas. + * Because it is a read-only command, a request is delivered only to paritions, not to replicas. So there are only 3 results, not 6. (TODO: I have to add a figure to indicate active nodes: [000, 001, 010, 011, 020, 021] => [000, 011, 020]) - * The `SumCollector` collects them. + * The `Collectors::Sum` collects them. Those 3 results are joined to just one array by the collector. -As the result, just one array with 3 elements appears in the response message. +As the result, just one array with 3 elements appears in the final response. ### Read-only access to the storage -Now, each instance of the handler class always returns `[0]` as its result. +Now, each instance of the handler class always returns `0` as its result. Let's implement codes to count up the number of records from the actual storage. lib/droonga/plugins/count-records.rb: @@ -276,7 +279,8 @@ lib/droonga/plugins/count-records.rb: (snip) class Handler < Droonga::Handler def handle(message) - table_name = message["body"]["table"] + request = message.request + table_name = request["body"]["table"] table = @context[table_name] count = table.size [count] @@ -285,6 +289,11 @@ lib/droonga/plugins/count-records.rb: (snip) ~~~ +Look at the argument of the `handle` method. +It is different from the one an adapter receives. +A handler receives a message meaning a distributed task. +So you have to extract the request message from the distributed task by the code `request = message.request`. + The instance variable `@context` is an instance of `Groonga::Context` for the storage of the partition. See the [class reference of Rroonga][Groonga::Context]. You can use any feature of Rroonga via `@context`. @@ -378,7 +387,8 @@ require "droonga/plugin" module Droonga module Plugins module DeleteStoresPlugin - Plugin.registry.register("delete-stores", self) + extend Plugin + register("delete-stores") end end end @@ -397,7 +407,8 @@ require "droonga/plugin" module Droonga module Plugins module DeleteStoresPlugin - Plugin.registry.register("delete-stores", self) + extend Plugin + register("delete-stores") define_single_step do |step| step.name = "deleteStores" @@ -423,18 +434,20 @@ require "droonga/plugin" module Droonga module Plugins module DeleteStoresPlugin - Plugin.registry.register("delete-stores", self) + extend Plugin + register("delete-stores") define_single_step do |step| step.name = "deleteStores" step.write = true step.handler = :Handler - step.collector = AndCollector + step.collector = Collectors::And end class Handler < Droonga::Handler def handle(message) - keyword = message["body"]["keyword"] + request = message.request + keyword = request["body"]["keyword"] table = @context["Store"] table.delete do |record| record.key @ keyword @@ -447,9 +460,11 @@ module Droonga end ~~~ +Remember, you have to extract the request message from the received task message. + The handler finds and deletes existing records which have the given keyword in its "key", by the [API of Rroonga][Groonga::Table_delete]. -And, the `AndCollector` is bound to the step by the configuration `step.collector`. +And, the `Collectors::And` is bound to the step by the configuration `step.collector`. It is is also one of built-in collectors, and merges boolean values retuned from handler instances for each partition and replica, to one boolean value. Modified: tutorial/plugin-development/adapter/index.md (+7 -7) =================================================================== --- tutorial/plugin-development/adapter/index.md 2014-02-28 15:22:06 +0900 (90ab200) +++ tutorial/plugin-development/adapter/index.md 2014-02-28 15:41:52 +0900 (2b326db) @@ -197,7 +197,7 @@ lib/droonga/plugins/sample-logger.rb: input_message.pattern = ["type", :equal, "search"] def adapt_input(input_message) - $log.info("SampleLoggerPlugin::Adapter", :message => input_message) + logger.info("SampleLoggerPlugin::Adapter", :message => input_message) end end end @@ -268,7 +268,7 @@ lib/droonga/plugins/sample-logger.rb: ~~~ruby (snip) def adapt_input(input_message) - $log.info("SampleLoggerPlugin::Adapter", :message => input_message) + logger.info("SampleLoggerPlugin::Adapter", :message => input_message) input_message.body["queries"]["stores"]["output"]["limit"] = 1 end (snip) @@ -345,7 +345,7 @@ lib/droonga/plugins/sample-logger.rb: (snip) def adapt_output(output_message) - $log.info("SampleLoggerPlugin::Adapter", :message => output_message) + logger.info("SampleLoggerPlugin::Adapter", :message => output_message) end end end @@ -413,7 +413,7 @@ lib/droonga/plugins/sample-logger.rb: ~~~ruby (snip) def adapt_output(output_message) - $log.info("SampleLoggerPlugin::Adapter", :message => output_message) + logger.info("SampleLoggerPlugin::Adapter", :message => output_message) output_message.body["stores"]["completedAt"] = Time.now end (snip) @@ -494,10 +494,10 @@ module Droonga input_message.pattern = ["type", :equal, "storeSearch"] def adapt_input(input_message) - $log.info("StoreSearchPlugin::Adapter", :message => input_message) + logger.info("StoreSearchPlugin::Adapter", :message => input_message) query = input_message.body["query"] - $log.info("storeSearch", :query => query) + logger.info("storeSearch", :query => query) body = { "queries" => { @@ -629,7 +629,7 @@ lib/droonga/plugins/store-search.rb: (snip) def adapt_output(output_message) - $log.info("StoreSearchPlugin::Adapter", :message => output_message) + logger.info("StoreSearchPlugin::Adapter", :message => output_message) records = output_message.body["stores"]["records"] simplified_results = records.flatten -------------- next part -------------- HTML����������������������������...Download