Navigation Menu

Skip to content

Commit

Permalink
Move catalog observer to engine
Browse files Browse the repository at this point in the history
Fluentd plugin layer should not know about Droonga engine details.
  • Loading branch information
kou committed Apr 11, 2014
1 parent 00e7210 commit ee8d8a2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
32 changes: 28 additions & 4 deletions lib/droonga/engine.rb
@@ -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
Expand All @@ -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
Expand All @@ -43,6 +51,22 @@ def process(message)
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
Expand Down
29 changes: 2 additions & 27 deletions lib/fluent/plugin/out_droonga.rb
@@ -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
Expand All @@ -17,7 +17,6 @@

require "droonga/engine"
require "droonga/plugin_loader"
require "droonga/catalog_observer"

module Fluent
class DroongaOutput < Output
Expand All @@ -28,20 +27,12 @@ class DroongaOutput < Output
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

Expand All @@ -53,22 +44,6 @@ def emit(tag, es, chain)
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))
Expand Down

0 comments on commit ee8d8a2

Please sign in to comment.