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

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



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/webmachine/adapters/ring.rb', line 16

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

  req_handler = Handler.new(dispatcher)

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

  @server = Java::OrgHttpkitServer::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



43
44
45
46
# File 'lib/webmachine/adapters/ring.rb', line 43

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