Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
planner: migrate to new plugin style
- Loading branch information
Showing
23 changed files
with
620 additions
and
583 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Copyright (C) 2014 Droonga Project | ||
| # | ||
| # This library is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU Lesser General Public | ||
| # License version 2.1 as published by the Free Software Foundation. | ||
| # | ||
| # This library is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| # Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public | ||
| # License along with this library; if not, write to the Free Software | ||
| # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
|
|
||
| require "droonga/message_matcher" | ||
| require "droonga/planner" | ||
|
|
||
| module Droonga | ||
| class PlannerRunner | ||
| def initialize(dispatcher, plugins) | ||
| @dispatcher = dispatcher | ||
| @planner_classes = Planner.find_sub_classes(plugins) | ||
| end | ||
|
|
||
| def shutdown | ||
| end | ||
|
|
||
| def plan(message) | ||
| $log.trace("#{log_tag}: plan: start", | ||
| :dataset => message["dataset"], | ||
| :type => message["type"]) | ||
| planner_class = find_planner_class(message) | ||
| if planner_class.nil? | ||
| raise UnsupportedMessageError.new(:planner, message) | ||
| end | ||
| planner = planner_class.new(@dispatcher) | ||
| plan = planner.plan(message) | ||
| $log.trace("#{log_tag}: plan: done", | ||
| :steps => plan.collect {|step| step["type"]}) | ||
| plan | ||
| end | ||
|
|
||
| private | ||
| def find_planner_class(message) | ||
| @planner_classes.find do |planner_class| | ||
| pattern = planner_class.message.pattern | ||
| if pattern | ||
| matcher = MessageMatcher.new(pattern) | ||
| matcher.match?(message) | ||
| else | ||
| false | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def log_tag | ||
| "adapter-runner" | ||
| end | ||
| end | ||
| end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Copyright (C) 2014 Droonga Project | ||
| # | ||
| # This library is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU Lesser General Public | ||
| # License version 2.1 as published by the Free Software Foundation. | ||
| # | ||
| # This library is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| # Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public | ||
| # License along with this library; if not, write to the Free Software | ||
| # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
|
|
||
| module Droonga | ||
| module Plugin | ||
| module Metadata | ||
| class PlannerMessage | ||
| def initialize(plugin_class) | ||
| @plugin_class = plugin_class | ||
| end | ||
|
|
||
| def pattern | ||
| configuration[:pattern] || fallback_pattern | ||
| end | ||
|
|
||
| def pattern=(pattern) | ||
| configuration[:pattern] = pattern | ||
| end | ||
|
|
||
| def type | ||
| configuration[:type] | ||
| end | ||
|
|
||
| def type=(type) | ||
| configuration[:type] = type | ||
| end | ||
|
|
||
| private | ||
| def configuration | ||
| @plugin_class.options[:message] ||= {} | ||
| end | ||
|
|
||
| def fallback_pattern | ||
| return nil if type.nil? | ||
| ["type", :equal, type] | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.