diff --git a/lib/rack/handler/jetty.rb b/lib/rack/handler/jetty.rb index 2bf7cb7..5ecdeeb 100755 --- a/lib/rack/handler/jetty.rb +++ b/lib/rack/handler/jetty.rb @@ -1,5 +1,21 @@ require 'rack_jetty/java_input' require 'rack_jetty/servlet_handler' +require 'java' + +java_import 'org.mortbay.jetty.NCSARequestLog' +java_import 'org.mortbay.jetty.Server' +java_import 'org.mortbay.jetty.bio.SocketConnector' +java_import 'org.mortbay.jetty.handler.DefaultHandler' +java_import 'org.mortbay.jetty.handler.HandlerCollection' +java_import 'org.mortbay.jetty.handler.ContextHandlerCollection' +java_import 'org.mortbay.jetty.handler.RequestLogHandler' +java_import 'org.mortbay.jetty.handler.StatisticsHandler' +java_import 'org.mortbay.jetty.nio.SelectChannelConnector' +java_import 'org.mortbay.jetty.security.SslSocketConnector' +java_import 'org.mortbay.management.MBeanContainer' +java_import 'org.mortbay.thread.QueuedThreadPool' +java_import 'java.lang.management.ManagementFactory' + module Rack module Handler @@ -17,31 +33,93 @@ def self.run(app, options = {}) end def run() - @connector = Java::org.mortbay.jetty.bio.SocketConnector.new - @connector.set_host(options[:Host]) - @connector.set_port(options[:Port].to_i) + thread_pool = QueuedThreadPool.new + thread_pool.setMinThreads((options[:Min_threads] || 10).to_i) + thread_pool.setMaxThreads((options[:Max_threads] || 200).to_i) + thread_pool.setLowThreads((options[:Low_threads] || 50).to_i) + thread_pool.setSpawnOrShrinkAt(2) @jetty = Java::org.mortbay.jetty.Server.new - @jetty.addConnector(@connector) - + @jetty.setThreadPool(thread_pool) + @jetty.setGracefulShutdown(1000) + + stats_on = options[:With_Stats] || true + + if options[:Use_NIO] || true + http_connector = SelectChannelConnector.new + http_connector.setLowResourcesConnections(20000) + else + http_connector = SocketConnector.new + end + http_connector.setHost(options[:Host] || 'localhost') + http_connector.setPort(options[:Port].to_i) + http_connector.setMaxIdleTime(30000) + http_connector.setAcceptors(2) + http_connector.setStatsOn(stats_on) + http_connector.setLowResourceMaxIdleTime(5000) + http_connector.setAcceptQueueSize((options[:Accept_queue_size] || thread_pool.getMaxThreads).to_i) + http_connector.setName("HttpListener") + @jetty.addConnector(http_connector) + + if options[:Ssl_Port] && options[:Keystore] && options[:Key_password] + https_connector = SslSocketConnector.new + + https_connector.setKeystore(options[:Keystore]) + https_connector.setKeystoreType(options[:Keystore_type] || 'JKS') + https_connector.setKeyPassword(options[:Key_password]) + https_connector.setHost(http_connector.getHost) + https_connector.setPort(options[:Ssl_Port].to_i) + https_connector.setMaxIdleTime(30000) + https_connector.setAcceptors(2) + https_connector.setStatsOn(stats_on) + https_connector.setLowResourceMaxIdleTime(5000) + https_connector.setAcceptQueueSize(http_connector.getAcceptQueueSize) + https_connector.setName("HttpsListener") + @jetty.addConnector(http_connector) + end + bridge = RackJetty::ServletHandler.new bridge.handler = self - - @jetty.set_handler(bridge) + + handlers = HandlerCollection.new + handlers.addHandler(bridge) + + if options[:Request_log] || options[:Request_log_path] + request_log_handler = RequestLogHandler.new + + request_log_handler.setRequestLog(options[:Request_log] || NCSARequestLog.new(options[:Request_log_path])) + handlers.addHandler(request_log_handler) + end + if stats_on + mbean_container = MBeanContainer.new(ManagementFactory.getPlatformMBeanServer) + + @jetty.getContainer.addEventListener(mbean_container) + mbean_container.start + + stats_handler = StatisticsHandler.new + stats_handler.addHandler(handlers) + @jetty.addHandler(stats_handler) + else + @jetty.addHandler(handlers) + end @jetty.start end def running? - @jetty && @jetty.is_started + @jetty && @jetty.isStarted end def stopped? - !@jetty || @jetty.is_stopped + !@jetty || @jetty.isStopped end def stop() @jetty && @jetty.stop end + + def destroy() + @jetty && @jetty.destroy + end end end -end \ No newline at end of file +end diff --git a/lib/rack_jetty/jars/ant-1.6.5.jar b/lib/rack_jetty/jars/ant-1.6.5.jar new file mode 100644 index 0000000..3beb3b8 Binary files /dev/null and b/lib/rack_jetty/jars/ant-1.6.5.jar differ diff --git a/lib/rack_jetty/jars/jetty-6.1.14.jar b/lib/rack_jetty/jars/jetty-6.1.14.jar deleted file mode 100644 index 3e67d1e..0000000 Binary files a/lib/rack_jetty/jars/jetty-6.1.14.jar and /dev/null differ diff --git a/lib/rack_jetty/jars/jetty-6.1.26.jar b/lib/rack_jetty/jars/jetty-6.1.26.jar new file mode 100644 index 0000000..2cbe07a Binary files /dev/null and b/lib/rack_jetty/jars/jetty-6.1.26.jar differ diff --git a/lib/rack_jetty/jars/jetty-management-6.1.26.jar b/lib/rack_jetty/jars/jetty-management-6.1.26.jar new file mode 100644 index 0000000..b5eeecb Binary files /dev/null and b/lib/rack_jetty/jars/jetty-management-6.1.26.jar differ diff --git a/lib/rack_jetty/jars/jetty-plus-6.1.26.jar b/lib/rack_jetty/jars/jetty-plus-6.1.26.jar new file mode 100644 index 0000000..5230fa0 Binary files /dev/null and b/lib/rack_jetty/jars/jetty-plus-6.1.26.jar differ diff --git a/lib/rack_jetty/jars/jetty-util-6.1.14.jar b/lib/rack_jetty/jars/jetty-util-6.1.14.jar deleted file mode 100644 index 7acc988..0000000 Binary files a/lib/rack_jetty/jars/jetty-util-6.1.14.jar and /dev/null differ diff --git a/lib/rack_jetty/jars/jetty-util-6.1.26.jar b/lib/rack_jetty/jars/jetty-util-6.1.26.jar new file mode 100644 index 0000000..cd23752 Binary files /dev/null and b/lib/rack_jetty/jars/jetty-util-6.1.26.jar differ diff --git a/lib/rack_jetty/jars/jsp-2.1.jar b/lib/rack_jetty/jars/jsp-2.1-glassfish-2.1.v20091210.jar similarity index 84% rename from lib/rack_jetty/jars/jsp-2.1.jar rename to lib/rack_jetty/jars/jsp-2.1-glassfish-2.1.v20091210.jar index bfdb566..3d36b54 100644 Binary files a/lib/rack_jetty/jars/jsp-2.1.jar and b/lib/rack_jetty/jars/jsp-2.1-glassfish-2.1.v20091210.jar differ diff --git a/lib/rack_jetty/jars/jsp-2.1-jetty-6.1.26.jar b/lib/rack_jetty/jars/jsp-2.1-jetty-6.1.26.jar new file mode 100644 index 0000000..a382381 Binary files /dev/null and b/lib/rack_jetty/jars/jsp-2.1-jetty-6.1.26.jar differ diff --git a/lib/rack_jetty/jars/jsp-api-2.1.jar b/lib/rack_jetty/jars/jsp-api-2.1-glassfish-2.1.v20091210.jar similarity index 83% rename from lib/rack_jetty/jars/jsp-api-2.1.jar rename to lib/rack_jetty/jars/jsp-api-2.1-glassfish-2.1.v20091210.jar index ac3a7a8..2318d27 100644 Binary files a/lib/rack_jetty/jars/jsp-api-2.1.jar and b/lib/rack_jetty/jars/jsp-api-2.1-glassfish-2.1.v20091210.jar differ diff --git a/lib/rack_jetty/jars/servlet-api-2.5-6.1.14.jar b/lib/rack_jetty/jars/servlet-api-2.5-20081211.jar similarity index 90% rename from lib/rack_jetty/jars/servlet-api-2.5-6.1.14.jar rename to lib/rack_jetty/jars/servlet-api-2.5-20081211.jar index fbb5a04..b0537c4 100644 Binary files a/lib/rack_jetty/jars/servlet-api-2.5-6.1.14.jar and b/lib/rack_jetty/jars/servlet-api-2.5-20081211.jar differ diff --git a/rack-jetty.gemspec b/rack-jetty.gemspec index d607a6e..fb5f4c1 100644 --- a/rack-jetty.gemspec +++ b/rack-jetty.gemspec @@ -23,13 +23,17 @@ Gem::Specification.new do |s| "Rakefile", "Gemfile", "lib/rack/handler/jetty.rb", + "lib/rack_jetty/jars/jetty-management-6.1.26.jar", "lib/rack_jetty/jars/core-3.1.1.jar", - "lib/rack_jetty/jars/jetty-6.1.14.jar", + "lib/rack_jetty/jars/jetty-6.1.26.jar", "lib/rack_jetty/jars/jetty-plus-6.1.14.jar", - "lib/rack_jetty/jars/jetty-util-6.1.14.jar", - "lib/rack_jetty/jars/jsp-2.1.jar", - "lib/rack_jetty/jars/jsp-api-2.1.jar", - "lib/rack_jetty/jars/servlet-api-2.5-6.1.14.jar", + "lib/rack_jetty/jars/ant-1.6.5.jar", + "lib/rack_jetty/jars/jsp-2.1-jetty-6.1.26.jar", + "lib/rack_jetty/jars/jetty-util-6.1.26.jar", + "lib/rack_jetty/jars/servlet-api-2.5-20081211.jar", + "lib/rack_jetty/jars/jsp-api-2.1-glassfish-2.1.v20091210.jar", + "lib/rack_jetty/jars/jsp-2.1-glassfish-2.1.v20091210.jar", + "lib/rack_jetty/jars/jetty-plus-6.1.26.jar", "lib/rack_jetty/java_input.rb", "lib/rack_jetty/servlet_handler.rb", "lib/rack_jetty/version.rb",