Sha256: f2b63ecceb4e09b96fe2b2c22b69b7b4b76175b22ad92fbcc2a1cf4045c9e115
Contents?: true
Size: 1.9 KB
Versions: 1
Compression:
Stored size: 1.9 KB
Contents
# NOTE: require 'rack/handler/trinidad' might get invoked 2 ways : # 1. Rack::Handler.try_require('rack/handler', 'trinidad') during rackup # in this case trinidad.rb might not yet been loaded # 2. a user require (after trinidad.rb booted) - need to load rack first require 'trinidad' require 'rack/handler' require 'rack/handler/servlet' module Rack module Handler class Trinidad < Rack::Handler::Servlet def self.run(app, options={}) opts = parse_options(options) servlet = create_servlet(app) opts[:servlet] = {:instance => servlet, :name => 'RackServlet'} ::Trinidad::CommandLineParser.new.load_configuration(opts) ::Trinidad::Server.new.start end def self.valid_options { "Host=HOST" => "Hostname to listen on (default: localhost)", "Port=PORT" => "Port to listen on (default: 8080)", "Threads=MIN:MAX" => "min:max threads to use (default 1:1, threadsafe)", } end def self.parse_options(options = {}) # some libs use :Port, :port and :Host, :host, unify this opts = {} options.each {|k, v| opts[k.to_s.downcase.to_sym] = v} # this is rack's configuration file but also the trinidad's configuration. # Removing it we allow to load trinidad's default configuration. opts.delete(:config) threads = (opts[:threads] || '1:1').split(':') opts[:port] ||= 3000 opts[:address] ||= opts[:host] || 'localhost' opts[:jruby_min_runtimes], opts[:jruby_max_runtimes] = threads[0].to_i, threads[1].to_i opts end def self.create_servlet(app) context = org.jruby.rack.embed.Context.new('Trinidad') dispatcher = org.jruby.rack.embed.Dispatcher.new(context, self.new(app)) org.jruby.rack.embed.Servlet.new(dispatcher, context) end end register :trinidad, Trinidad end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
trinidad-1.3.4 | lib/rack/handler/trinidad.rb |