[Groonga-commit] droonga/fluent-plugin-droonga at ee8d8a2 [master] Move catalog observer to engine

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Apr 11 11:41:36 JST 2014


Kouhei Sutou	2014-04-11 11:41:36 +0900 (Fri, 11 Apr 2014)

  New Revision: ee8d8a2b1c048136a2a1845fb3af8eb82f829174
  https://github.com/droonga/fluent-plugin-droonga/commit/ee8d8a2b1c048136a2a1845fb3af8eb82f829174

  Message:
    Move catalog observer to engine
    
    Fluentd plugin layer should not know about Droonga engine details.

  Modified files:
    lib/droonga/engine.rb
    lib/fluent/plugin/out_droonga.rb

  Modified: lib/droonga/engine.rb (+28 -4)
===================================================================
--- lib/droonga/engine.rb    2014-04-10 18:45:08 +0900 (6eddd35)
+++ lib/droonga/engine.rb    2014-04-11 11:41:36 +0900 (6c36d1b)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2013 Droonga Project
+# Copyright (C) 2013-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
@@ -16,24 +16,32 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 require "droonga/loggable"
+require "droonga/catalog_observer"
 require "droonga/dispatcher"
 
 module Droonga
   class Engine
     include Loggable
 
-    def initialize(catalog, options={})
-      @catalog = catalog
+    def initialize(options={})
       @options = options
-      @dispatcher = Dispatcher.new(@catalog, @options)
+      @catalog_observer = Droonga::CatalogObserver.new
+      @catalog_observer.on_reload = lambda do |catalog|
+        graceful_restart(catalog)
+        logger.info("restarted")
+      end
     end
 
     def start
+      @catalog_observer.start
+      catalog = @catalog_observer.catalog
+      @dispatcher = create_dispatcher(catalog)
       @dispatcher.start
     end
 
     def shutdown
       logger.trace("shutdown: start")
+      @catalog_observer.stop
       @dispatcher.shutdown
       logger.trace("shutdown: done")
     end
@@ -43,6 +51,22 @@ module Droonga
     end
 
     private
+    def create_dispatcher(catalog)
+      Dispatcher.new(catalog, @options)
+    end
+
+    def graceful_restart(catalog)
+      logger.trace("graceful_restart: start")
+      old_dispatcher = @dispatcher
+      logger.trace("graceful_restart: creating new dispatcher")
+      new_dispatcher = create_dispatcher(catalog)
+      new_dispatcher.start
+      @dispatcher = new_dispatcher
+      logger.trace("graceful_restart: shutdown old dispatcher")
+      old_dispatcher.shutdown
+      logger.trace("graceful_restart: done")
+    end
+
     def log_tag
       "engine"
     end

  Modified: lib/fluent/plugin/out_droonga.rb (+2 -27)
===================================================================
--- lib/fluent/plugin/out_droonga.rb    2014-04-10 18:45:08 +0900 (2af61bd)
+++ lib/fluent/plugin/out_droonga.rb    2014-04-11 11:41:36 +0900 (e7e94b9)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2013 Droonga Project
+# Copyright (C) 2013-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
@@ -17,7 +17,6 @@
 
 require "droonga/engine"
 require "droonga/plugin_loader"
-require "droonga/catalog_observer"
 
 module Fluent
   class DroongaOutput < Output
@@ -28,20 +27,12 @@ module Fluent
     def start
       super
       Droonga::PluginLoader.load_all
-      @catalog_observer = Droonga::CatalogObserver.new
-      @catalog_observer.on_reload = lambda do |catalog|
-        graceful_engine_restart(catalog)
-        $log.info("engine restarted")
-      end
-      @catalog_observer.start
-      catalog = @catalog_observer.catalog
-      @engine = create_engine(catalog)
+      @engine = Droonga::Engine.new(:name => @name)
       @engine.start
     end
 
     def shutdown
       @engine.shutdown
-      @catalog_observer.stop
       super
     end
 
@@ -53,22 +44,6 @@ module Fluent
     end
 
     private
-    def create_engine(catalog)
-      Droonga::Engine.new(catalog, :name => @name)
-    end
-
-    def graceful_engine_restart(catalog)
-      $log.trace("out_droonga: start: graceful_engine_restart")
-      old_engine = @engine
-      $log.trace("out_droonga: creating new engine")
-      new_engine = create_engine(catalog)
-      new_engine.start
-      @engine = new_engine
-      $log.trace("out_droonga: shutdown old engine")
-      old_engine.shutdown
-      $log.trace("out_droonga: done: graceful_engine_restart")
-    end
-
     def process_event(tag, record)
       $log.trace("out_droonga: tag: <#{tag}>")
       @engine.process(parse_record(tag, record))
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index