Class JettyRails::Server
In: lib/jetty_rails/server.rb
Parent: Object

Methods

add_app   new   start  

Classes and Modules

Module JettyRails::Server::ContextPath

Attributes

app_contexts  [R] 
config  [R] 
server  [R] 

Public Class methods

[Source]

# File lib/jetty_rails/server.rb, line 22
    def initialize(config = {})
      @config = config.symbolize_keys!.reverse_merge!(@@defaults)
    
      @server = Jetty::Server.new
      # setup the thread pool for the server
      thread_pool = Jetty::Thread::QueuedThreadPool.new
      thread_pool.set_max_threads(config[:thread_pool_max])
      thread_pool.set_min_threads(config[:thread_pool_min])
      @server.set_thread_pool(thread_pool)
    
      connector = Jetty::SelectChannelConnector.new
      connector.set_acceptors(config[:acceptor_size])
      connector.port = config[:port]
      @server.add_connector(connector)

      if config[:apps].nil?
        add_app(config)
      else
        config[:apps].each do |app_config|
          app_config.reverse_merge!(config)
          app_config.delete(:apps)
          add_app(app_config)
        end
      end
    end

Public Instance methods

[Source]

# File lib/jetty_rails/server.rb, line 48
    def add_app(config) 
      raise 'Base dir to be run must be provided' unless config[:base]
      config[:context_path].extend ContextPath
      
      @server.add_handler(JettyRails::Handler::PublicDirectoryHandler.new(config))
      web_app_handler = JettyRails::Handler::WebAppHandler.new(config)
      (@app_contexts ||= []) << web_app_handler
      @server.add_handler(web_app_handler)
    end

[Source]

# File lib/jetty_rails/server.rb, line 58
    def start
      @server.start
      @server.join
    end

[Validate]