Class: PHPRPC::EbbServer

Inherits:
BaseServer show all
Defined in:
lib/phprpc/ebb_server.rb

Instance Attribute Summary

Attributes inherited from BaseServer

#charset, #debug

Instance Method Summary collapse

Methods inherited from BaseServer

#add, #call, #call!

Constructor Details

#initialize(options = {}) ⇒ EbbServer

Returns a new instance of EbbServer.



38
39
40
41
42
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
# File 'lib/phprpc/ebb_server.rb', line 38

def initialize(options = {})
  super()
  @options = {
    :port                 => 3000,
    :session_mode         => :file,
    :path                 => "/",
    :expire_after         => 1800,
  }.update(options)
  @opts = OptionParser.new
  @opts.banner = "Usage: #{@opts.program_name} ebb [options]"
  @opts.separator ""
  @opts.separator "Server options:"
  @opts.on('-p', '--port PORT', Integer, "Which port to bind to (default: #{@options[:port]})") { |port| @options[:port] = port }
  @opts.on('--ssl_cert FILE', String, "SSL certificate file") { |file| @options[:ssl_cert] = file }
  @opts.on('--ssl_key FILE', String, "SSL key file") { |file| @options[:ssl_key] = file }
  @opts.separator ""
  @opts.separator "Session options:"
  @opts.on('-s', '--session-mode MODE', [:file, :memcache, :pool], "Select Session mode (file, memcache, pool)", "(default: #{@options[:session_mode].to_s})") { |mode| @options[:session_mode] = mode }
  @opts.on('-e','--expire-after TIME', Integer, "Session expire after (default: #{@options[:expire_after]})") { |time| @options[:expire_after] = time }
  @opts.on('-m','--memcache_server SERVER', String, "Memcache server used by session in", "memcache mode (default: localhost:11211)") { |server| @options[:memcache_server] = server }
  @opts.on('--prefix PATH', String, "Mount the PHPRPC Server under PATH", "(start with /)") { |path| @options[:path] = path }
  @opts.separator ""
  @opts.separator "Common options:"
  @opts.on_tail("-D", "--debug", "Set debbuging on") { self.debug = true }
  @opts.on_tail('-?', '-h', '--help', "Show this help message.") { puts @opts; exit }
  @opts.on_tail('-v', '--version', "Show version") { puts Ebb::VERSION_STRING; exit }
  begin
    @opts.parse!(ARGV)
  rescue OptionParser::ParseError
    puts @opts
    exit
  end
end

Instance Method Details

#startObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/phprpc/ebb_server.rb', line 72

def start()
  app = self
  if [:memcache, :pool].include?(@options[:session_mode]) then
    begin
      require 'rack'
      if @options[:session_mode] == :memcache then
        app = Rack::Session::Memcache.new(self, @options)
      else
        app = Rack::Session::Pool.new(self, @options)
      end
    rescue Exception
      app = self
    end
  end
  Ebb.start_server(app, @options)
end