Class: RR::ProxyRunner
- Inherits:
-
Object
- Object
- RR::ProxyRunner
- Defined in:
- lib/rubyrep/proxy_runner.rb
Overview
This class implements the functionality of the rrproxy.rb command.
Constant Summary collapse
- DEFAULT_OPTIONS =
Default options to start a DatabaseProxy server
{ :port => DatabaseProxy::DEFAULT_PORT, :host => '' }
Class Method Summary collapse
-
.run(args) ⇒ Object
Runs the ProxyRunner (processing of command line & starting of server) args: the array of command line options with which to start the server.
Instance Method Summary collapse
-
#build_url(options) ⇒ Object
Builds the druby URL from the given options and returns it.
-
#get_options(args) ⇒ Object
Parses the given command line parameter array.
-
#start_server(url) ⇒ Object
Starts a proxy server under the given druby URL.
Class Method Details
.run(args) ⇒ Object
Runs the ProxyRunner (processing of command line & starting of server) args: the array of command line options with which to start the server
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rubyrep/proxy_runner.rb', line 75 def self.run(args) runner = ProxyRunner.new , status = runner.(args) if url = runner.build_url() runner.start_server(url) end status end |
Instance Method Details
#build_url(options) ⇒ Object
Builds the druby URL from the given options and returns it
61 62 63 |
# File 'lib/rubyrep/proxy_runner.rb', line 61 def build_url() "druby://#{[:host]}:#{[:port]}" end |
#get_options(args) ⇒ Object
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)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rubyrep/proxy_runner.rb', line 25 def (args) = DEFAULT_OPTIONS status = 0 parser = OptionParser.new do |opts| opts. = "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| [:host] = arg end opts.on("-p","--port", "=PORT_NUMBER", Integer, "TCP port to listen on. Default port: #{DatabaseProxy::DEFAULT_PORT}") do |arg| [:port] = arg end opts.on_tail("--help", "Show this message") do $stderr.puts opts = nil end end begin parser.parse!(args) rescue Exception => e $stderr.puts "Command line parsing failed: #{e}" $stderr.puts parser.help = nil status = 1 end return , status end |
#start_server(url) ⇒ Object
Starts a proxy server under the given druby URL
66 67 68 69 70 71 |
# File 'lib/rubyrep/proxy_runner.rb', line 66 def start_server(url) proxy = DatabaseProxy.new DRb.start_service(url, proxy) DRb.thread.join end |