class DRbQS::Manage

Constants

WAIT_MAX_NUMBER
WAIT_SERVER_TIME

Public Class Methods

new(opts = {}) click to toggle source

opts has keys :home and :uri.

# File lib/drbqs/manage/manage.rb, line 19
def initialize(opts = {})
  @opts = opts
  @config = nil
  @signal_sender = nil
end

Public Instance Methods

clear_process() click to toggle source
# File lib/drbqs/manage/manage.rb, line 106
def clear_process
  config.list.clear_process_not_exist
end
create_config() click to toggle source
# File lib/drbqs/manage/manage.rb, line 56
def create_config
  config.save_sample
end
list_process() click to toggle source
# File lib/drbqs/manage/manage.rb, line 102
def list_process
  { :server => config.list.server.list, :node => config.list.node.list }
end
server_respond?() click to toggle source
# File lib/drbqs/manage/manage.rb, line 65
def server_respond?
  ret = nil
  begin
    if get_response
      ret = true
    end
  rescue DRbQS::Manage::NotSetURI
    raise
  rescue
  end
  ret
end
set_home_directory(dir) click to toggle source
# File lib/drbqs/manage/manage.rb, line 29
def set_home_directory(dir)
  @opts[:home] = dir
end
set_uri(uri) click to toggle source
# File lib/drbqs/manage/manage.rb, line 25
def set_uri(uri)
  @opts[:uri] = uri
end
wait_server_process(pid = nil) click to toggle source

If the server responds, this method returns true. If the server process does not exist, this method return nil. If the server process exists and there is no response, this method raises error.

# File lib/drbqs/manage/manage.rb, line 82
def wait_server_process(pid = nil)
  i = 0
  begin
    sleep(WAIT_SERVER_TIME)
    if pid
      unless DRbQS::Misc.process_running_normally?(pid)
        return nil
      end
    elsif server_data = config.list.server.get(@opts[:uri])
      pid = server_data[:pid]
    end
    i += 1
    if i > WAIT_MAX_NUMBER
      raise DRbQS::Manage::NoServerRespond,
      "We are waiting for #{WAIT_SERVER_TIME * WAIT_MAX_NUMBER} seconds, but the server of #{@opts[:uri]} does not respond."
    end
  end while !server_respond?
  true
end

Private Instance Methods

config() click to toggle source
# File lib/drbqs/manage/manage.rb, line 33
def config
  unless @config
    if @opts[:home]
      DRbQS::Config.set_home_directory(@opts[:home])
    end
    @config = DRbQS::Config.new
  end
  @config
end
signal_sender() click to toggle source
# File lib/drbqs/manage/manage.rb, line 44
def signal_sender
  unless @signal_sender
    unless @opts[:uri]
      raise DRbQS::Manage::NotSetURI, "The uri of server to connect has not set."
    end
    obj = DRbObject.new_with_uri(@opts[:uri])
    @signal_sender = DRbQS::Manage::SendSignal.new(obj[:message])
  end
  @signal_sender
end