Class: Webmachine::Adapters::Ring

Inherits:
Webmachine::Adapter
  • Object
show all
Defined in:
lib/webmachine/adapters/ring.rb

Defined Under Namespace

Classes: Handler, RingRequest, RingResponse

Constant Summary collapse

STATUS =
Keyword.intern("status")
HEADERS =
Keyword.intern("headers")
BODY =
Keyword.intern("body")
REQUEST_URI =
Keyword.intern("uri")
QUERY_STRING =
Keyword.intern("query-string")
METHOD =
Keyword.intern("request-method")
DEFAULT_OPTIONS =
{
  :port          => 9292,
  :host          => "0.0.0.0",
  :threads       => 50,
  :queue_size    => 1000,
  :worker_prefix => "wm-",
  :max_body_size => 8388608,
  :max_http_line => 4096
}

Instance Method Summary collapse

Instance Method Details

#runObject

Start the Rack adapter



37
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
# File 'lib/webmachine/adapters/ring.rb', line 37

def run
  options = DEFAULT_OPTIONS.merge({
    :port => configuration.port,
    :host => configuration.ip
  }).merge(configuration.adapter_options)

  req_handler = Handler.new(dispatcher)

  @ring_handler = RingHandler.new(options[:threads],
                                  req_handler,
                                  options[:worker_prefix],
                                  options[:queue_size])

  @server = HttpServer.new(options[:host],
                           options[:port].to_i,
                           @ring_handler,
                           options[:max_body_size],
                           options[:max_http_line])

  @server.start()

  $stdout.printf "Webmachine Http kit is listening on %s:%s\n\n",
    options[:host], options[:port]

  Signal.trap("INT") { shutdown }
end

#shutdownObject



64
65
66
67
# File 'lib/webmachine/adapters/ring.rb', line 64

def shutdown
  @ring_handler.close()
  @server.stop()
end