Kouhei Sutou
null+****@clear*****
Fri Nov 22 15:56:53 JST 2013
Kouhei Sutou 2013-11-22 15:56:53 +0900 (Fri, 22 Nov 2013) New Revision: d11e270b01a2c44d73ccdecd036b9b7336cd00d0 https://github.com/droonga/fluent-plugin-droonga/commit/d11e270b01a2c44d73ccdecd036b9b7336cd00d0 Message: Introduce Farm that manages partitions Added files: lib/droonga/farm.rb Modified files: lib/droonga/dispatcher.rb Modified: lib/droonga/dispatcher.rb (+5 -11) =================================================================== --- lib/droonga/dispatcher.rb 2013-11-22 15:49:01 +0900 (37b0602) +++ lib/droonga/dispatcher.rb 2013-11-22 15:56:53 +0900 (4f7766e) @@ -20,18 +20,14 @@ require "droonga/handler" require "droonga/adapter" require "droonga/catalog" require "droonga/collector" -require "droonga/partition" +require "droonga/farm" module Droonga class Dispatcher attr_reader :collectors def initialize(worker, name) - @partitions = {} - Droonga.catalog.get_partitions(name).each do |name, options| - partition = Droonga::Partition.new(options) - partition.start - @partitions[name] = partition - end + @farm = Farm.new(name) + @farm.start @worker = worker @name = name @collectors = {} @@ -44,9 +40,7 @@ module Droonga end def shutdown - @partitions.each do |name, partition| - partition.shutdown - end + @farm.shutdown end def handle(message, arguments) @@ -97,7 +91,7 @@ module Droonga post(message, "type" => type, "synchronous"=> synchronous) else envelope =****@worke*****("body" => message, "type" => type) - @partitions[route].emit('', Time.now.to_f, envelope, synchronous) + @farm.emit(route, envelope, synchronous) end end Added: lib/droonga/farm.rb (+48 -0) 100644 =================================================================== --- /dev/null +++ lib/droonga/farm.rb 2013-11-22 15:56:53 +0900 (2e6206c) @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2013 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/partition" + +module Droonga + class Farm + def initialize(name) + @name = name + @partitions = {} + Droonga.catalog.get_partitions(name).each do |partition_name, options| + partition = Droonga::Partition.new(options) + @partitions[partition_name] = partition + end + end + + def start + @partitions.each_value do |partition| + partition.start + end + end + + def shutdown + @partitions.each_value do |partition| + partition.shutdown + end + end + + # TODO: fix method name + def emit(partition_name, envelope, synchronous) + @partitions[partition_name].emit('', Time.now.to_f, envelope, synchronous) + end + end +end -------------- next part -------------- HTML����������������������������...Download