Kouhei Sutou
null+****@clear*****
Tue May 27 13:13:17 JST 2014
Kouhei Sutou 2014-05-27 13:13:17 +0900 (Tue, 27 May 2014) New Revision: 72e1b3d58efbf9f89d9c38164e6595fd809fa750 https://github.com/droonga/droonga-engine/commit/72e1b3d58efbf9f89d9c38164e6595fd809fa750 Message: Extract common protocol messages Added files: lib/droonga/service_control_protocol.rb Modified files: lib/droonga/command/droonga_engine.rb lib/droonga/command/droonga_engine_service.rb Modified: lib/droonga/command/droonga_engine.rb (+7 -4) =================================================================== --- lib/droonga/command/droonga_engine.rb 2014-05-27 13:05:54 +0900 (94ca4f0) +++ lib/droonga/command/droonga_engine.rb 2014-05-27 13:13:17 +0900 (36e55a9) @@ -22,6 +22,7 @@ require "coolio" require "droonga/path" require "droonga/serf" +require "droonga/service_control_protocol" module Droonga module Command @@ -293,6 +294,8 @@ module Droonga end class ServiceRunner + include ServiceControlProtocol + def initialize(raw_loop, configuration) @raw_loop = raw_loop @configuration = configuration @@ -337,11 +340,11 @@ module Droonga end def stop_graceful - @control_write_out.write("stop-graceful\n") + @control_write_out.write(Messages::STOP_GRACEFUL) end def stop_immediately - @control_write_out.write("stop-immediately\n") + @control_write_out.write(Messages::STOP_IMMEDIATELY) end def success? @@ -371,9 +374,9 @@ module Droonga # TODO: should buffer data to handle half line received case data.each_line do |line| case line - when "ready\n" + when Messages::READY on_ready - when "finish\n" + when Messages::FINISH on_finish end end Modified: lib/droonga/command/droonga_engine_service.rb (+6 -4) =================================================================== --- lib/droonga/command/droonga_engine_service.rb 2014-05-27 13:05:54 +0900 (48638bc) +++ lib/droonga/command/droonga_engine_service.rb 2014-05-27 13:13:17 +0900 (661b455) @@ -17,6 +17,7 @@ require "optparse" require "coolio" +require "droonga/service_control_protocol" require "droonga/engine" require "droonga/fluent_message_receiver" require "droonga/internal_fluent_message_receiver" @@ -32,6 +33,7 @@ module Droonga end include Loggable + include ServiceControlProtocol def initialize @engine_name = nil @@ -55,7 +57,7 @@ module Droonga logger.exception("failed to run services", $!) ensure unless @control_write_closed - control_write_io.write("finish\n") + control_write_io.write(Messages::FINISH) control_write_io.close end end @@ -161,9 +163,9 @@ module Droonga # TODO: should buffer data to handle half line received case data.each_line do |line| case line - when "stop-graceful\n" + when Messages::STOP_GRACEFUL stop_graceful - when "stop-immediately\n" + when Messages::STOP_IMMEDIATELY stop_immediately end end @@ -196,7 +198,7 @@ module Droonga end @loop.attach(@control_write) - @control_write.write("ready\n") + @control_write.write(Messages::READY) end def shutdown_control_io Added: lib/droonga/service_control_protocol.rb (+26 -0) 100644 =================================================================== --- /dev/null +++ lib/droonga/service_control_protocol.rb 2014-05-27 13:13:17 +0900 (dbb9518) @@ -0,0 +1,26 @@ +# 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 ServiceControlProtocol + module Messages + STOP_GRACEFUL = "stop-graceful\n" + STOP_IMMEDIATELY = "stop-immediately\n" + + READY = "ready\n" + FINISH = "finish\n" + end + end +end -------------- next part -------------- HTML����������������������������... Download