Parent

Class/Module Index [+]

Quicksearch

RR::ProxyRunner

This class implements the functionality of the rrproxy.rb command.

Constants

DEFAULT_OPTIONS

Default options to start a DatabaseProxy server

Public Class Methods

run(args) click to toggle source

Runs the ProxyRunner (processing of command line & starting of server) args: the array of command line options with which to start the server

# File lib/rubyrep/proxy_runner.rb, line 75
def self.run(args)
  runner = ProxyRunner.new
  
  options, status = runner.get_options(args)
  if options
    url = runner.build_url(options)
    runner.start_server(url)
  end
  status
end

Public Instance Methods

build_url(options) click to toggle source

Builds the druby URL from the given options and returns it

# File lib/rubyrep/proxy_runner.rb, line 61
def build_url(options)
  "druby://#{options[:host]}:#{options[:port]}"
end
get_options(args) click to toggle source

Parses the given command line parameter array. Returns

* the options hash or nil if command line parsing failed
* status (as per UNIX conventions: 1 if parameters were invalid, 0 otherwise)
# File lib/rubyrep/proxy_runner.rb, line 25
def get_options(args)
  options = DEFAULT_OPTIONS
  status = 0

  parser = OptionParser.new do |opts|
    opts.banner = "Usage: #{$0} proxy [options]"
    opts.separator ""
    opts.separator "Specific options:"

    opts.on("-h","--host", "=IP_ADDRESS", "IP address to listen on. Default: binds to all IP addresses of the computer") do |arg|
      options[:host] = arg
    end

    opts.on("-p","--port", "=PORT_NUMBER", Integer, "TCP port to listen on. Default port: #{DatabaseProxy::DEFAULT_PORT}") do |arg|
      options[:port] = arg
    end

    opts.on_tail("--help", "Show this message") do
      $stderr.puts opts
      options = nil
    end
  end

  begin
    parser.parse!(args)
  rescue Exception => e
    $stderr.puts "Command line parsing failed: #{e}"
    $stderr.puts parser.help
    options = nil
    status = 1
  end
  
  return options, status
end
start_server(url) click to toggle source

Starts a proxy server under the given druby URL

# File lib/rubyrep/proxy_runner.rb, line 66
def start_server(url)
  proxy = DatabaseProxy.new

  DRb.start_service(url, proxy)
  DRb.thread.join
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.