15
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/rack/handler/jetty.rb', line 15
def self.run(app, options)
if options.fetch(:replace_jetty_logger, true)
@logger = Rack::Handler::JettyLogAdapter.new(options[:logger], options[:log_prefix] ||
'JETTY: ')
org.mortbay.log.Log.setLog(@logger)
end
jetty = org.mortbay.jetty.Server.new options[:Port]
if options.fetch(:with_jmx, true)
m_bean_server = java.lang.management.ManagementFactory.getPlatformMBeanServer
container = org.mortbay.management.MBeanContainer.new(m_bean_server)
jetty.container.add_event_listener(container)
container.start
end
max_threads = options[:max_threads] || DEFAULT_MAX_THREADS
thread_pool = org.mortbay.thread.QueuedThreadPool.new(max_threads)
thread_pool.setName("http")
log("created thread pool #{thread_pool} with #{max_threads} max threads")
jetty.setThreadPool(thread_pool)
context_path = options[:context_path] || "/"
context = org.mortbay.jetty.servlet.Context.new(nil, context_path,
org.mortbay.jetty.servlet.Context::NO_SESSIONS)
servlet_pattern = options[:servlet_pattern] || "/*"
context.add_filter(
filter_holder(app),
servlet_pattern,
org.mortbay.jetty.Handler::ALL)
context.set_resource_base(File.dirname(__FILE__))
context.add_servlet(org.mortbay.jetty.servlet.ServletHolder.new(
org.mortbay.jetty.servlet.DefaultServlet.new), servlet_pattern)
jetty.set_handler(context)
jetty.start
jetty.join
end
|