Navigation Menu

Skip to content

Commit

Permalink
Remove listen gem dependency
Browse files Browse the repository at this point in the history
Because listen gem is implemented based on celluloid gem and thread. It
is poor compatibility with Droonga. Droonga uses another event loop
system, cool.io.
  • Loading branch information
kou committed Jun 24, 2014
1 parent 5ff7623 commit 6027204
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 87 deletions.
1 change: 0 additions & 1 deletion droonga-engine.gemspec
Expand Up @@ -41,7 +41,6 @@ Gem::Specification.new do |gem|
gem.add_dependency "cool.io"
gem.add_dependency "serverengine"
gem.add_dependency "droonga-message-pack-packer", ">= 1.0.1"
gem.add_dependency "listen", "~> 2.7"
gem.add_dependency "faraday"
gem.add_dependency "faraday_middleware"
gem.add_dependency "archive-zip"
Expand Down
4 changes: 2 additions & 2 deletions lib/droonga/command/droonga_engine.rb
Expand Up @@ -23,7 +23,7 @@

require "droonga/path"
require "droonga/serf"
require "droonga/catalog_observer"
require "droonga/file_observer"
require "droonga/service_control_protocol"
require "droonga/line_buffer"

Expand Down Expand Up @@ -324,7 +324,7 @@ def run_serf
end

def run_catalog_observer
catalog_observer = CatalogObserver.new(@loop)
catalog_observer = FileObserver.new(@loop, Path.catalog)
catalog_observer.on_change = lambda do
restart_graceful
end
Expand Down
4 changes: 2 additions & 2 deletions lib/droonga/command/serf_event_handler.rb
Expand Up @@ -21,7 +21,7 @@

require "droonga/path"
require "droonga/serf"
require "droonga/live_nodes_list_observer"
require "droonga/file_observer"

module Droonga
module Command
Expand Down Expand Up @@ -70,7 +70,7 @@ def live_nodes
end

def output_live_nodes
list_path = LiveNodesListObserver.path
list_path = Path.live_nodes
nodes = live_nodes
file_contents = JSON.pretty_generate(nodes)
# Don't output the file directly to prevent loading of incomplete file!
Expand Down
19 changes: 15 additions & 4 deletions lib/droonga/engine.rb
Expand Up @@ -22,7 +22,7 @@
require "droonga/engine_state"
require "droonga/catalog_loader"
require "droonga/dispatcher"
require "droonga/live_nodes_list_observer"
require "droonga/file_observer"

module Droonga
class Engine
Expand All @@ -36,9 +36,9 @@ def initialize(loop, name, internal_name)
@catalog = load_catalog
@live_nodes = @catalog.all_nodes
@dispatcher = create_dispatcher
@live_nodes_list_observer = LiveNodesListObserver.new
@live_nodes_list_observer.on_update = lambda do |live_nodes|
@live_nodes = live_nodes
@live_nodes_list_observer = FileObserver.new(loop, Path.live_nodes)
@live_nodes_list_observer.on_change = lambda do
@live_nodes = load_live_nodes
@dispatcher.live_nodes = live_nodes if @dispatcher
end
end
Expand Down Expand Up @@ -95,13 +95,24 @@ def load_catalog
catalog
end

def load_live_nodes
path = Path.live_nodes
loader = LiveNodesListLoader.new(path)
live_nodes = loader.load
logger.info("live-nodes loaded",
:path => path,
:mtime => path.mtime)
live_nodes
end

def create_dispatcher
dispatcher = Dispatcher.new(@state, @catalog)
dispatcher.live_nodes = @live_nodes
dispatcher
end

def output_last_processed_timestamp
FileUtils.mkdir_p(File.dirname(last_processed_timestamp_file))
File.open(last_processed_timestamp_file, "w") do |file|
file.write(@last_processed_timestamp)
end
Expand Down
16 changes: 10 additions & 6 deletions lib/droonga/catalog_observer.rb → lib/droonga/file_observer.rb
Expand Up @@ -21,17 +21,21 @@
require "droonga/loggable"

module Droonga
class CatalogObserver
class FileObserver
include Loggable

CHECK_INTERVAL = 1

attr_accessor :on_change

def initialize(loop)
def initialize(loop, path)
@loop = loop
@path = Path.catalog
@mtime = @path.mtime
@path = path
if @path.exist?
@mtime = @path.mtime
else
@mtime = nil
end
@on_change = nil
end

Expand All @@ -55,11 +59,11 @@ def stop

private
def updated?
@path.mtime > @mtime
@path.exist? and @path.mtime > @mtime
end

def log_tag
"catalog-observer"
"file-observer"
end
end
end
72 changes: 0 additions & 72 deletions lib/droonga/live_nodes_list_observer.rb

This file was deleted.

4 changes: 4 additions & 0 deletions lib/droonga/path.rb
Expand Up @@ -38,6 +38,10 @@ def state
base + "state"
end

def live_nodes
state + "live-nodes.json"
end

def catalog
base_file_name = ENV["DROONGA_CATALOG"] || "catalog.json"
Pathname.new(base_file_name).expand_path(base)
Expand Down

0 comments on commit 6027204

Please sign in to comment.