Class: StompServer::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/stomp_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigurator

Returns a new instance of Configurator.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/stomp_server.rb', line 20

def initialize
  @opts = nil
  @defaults = {
    :port => 61613,
    :host => "127.0.0.1",
    :debug => false,
    :queue => 'memory',
    :auth => false,
    :working_dir => Dir.getwd,
    :storage => ".stompserver",
    :logdir => 'log',
    :configfile => 'stompserver.conf',
    :logfile => 'stompserver.log',
    :pidfile => 'stompserver.pid',
    :checkpoint => 0
  }
  @opts = getopts
  if opts[:debug]
    $DEBUG=true
  end

end

Instance Attribute Details

#optsObject

Returns the value of attribute opts.



18
19
20
# File 'lib/stomp_server.rb', line 18

def opts
  @opts
end

Instance Method Details

#getoptsObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/stomp_server.rb', line 43

def getopts
  copts = OptionParser.new
  copts.on("-C", "--config=CONFIGFILE", String, "Configuration File (default: stompserver.conf)") {|c| @defaults[:configfile] = c}
  copts.on("-p", "--port=PORT", Integer, "Change the port (default: 61613)") {|p| @defaults[:port] = p}
  copts.on("-b", "--host=ADDR", String, "Change the host (default: localhost)") {|a| @defaults[:host] = a}
  copts.on("-q", "--queuetype=QUEUETYPE", String, "Queue type (memory|dbm|activerecord|file) (default: memory)") {|q| @defaults[:queue] = q}
  copts.on("-w", "--working_dir=DIR", String, "Change the working directory (default: current directory)") {|s| @defaults[:working_dir] = s}
  copts.on("-s", "--storage=DIR", String, "Change the storage directory (default: .stompserver, relative to working_dir)") {|s| @defaults[:storage] = s}
  copts.on("-d", "--debug", String, "Turn on debug messages") {|d| @defaults[:debug] = true}
  copts.on("-a", "--auth", String, "Require client authorization") {|a| @defaults[:auth] = true}
  copts.on("-c", "--checkpoint=SECONDS", Integer, "Time between checkpointing the queues in seconds (default: 0)") {|c| @defaults[:checkpoint] = c}
  copts.on("-h", "--help", "Show this message") do
    puts copts
    exit
  end
  puts copts.parse(ARGV)

  if File.exists?(@defaults[:configfile])
    opts = @defaults.merge(YAML.load_file(@defaults[:configfile]))
  else
    opts = @defaults
  end

  opts[:etcdir] = File.join(opts[:working_dir],'etc')
  opts[:storage] = File.join(opts[:working_dir],opts[:storage])
  opts[:logdir] = File.join(opts[:working_dir],opts[:logdir])
  opts[:logfile] = File.join(opts[:logdir],opts[:logfile])
  opts[:pidfile] = File.join(opts[:logdir],opts[:pidfile])
  if opts[:auth]
    opts[:passwd] = File.join(opts[:etcdir],'.passwd')
  end

  return opts
end