Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added https, statistics and request log support #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 88 additions & 10 deletions lib/rack/handler/jetty.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
end
Binary file added lib/rack_jetty/jars/ant-1.6.5.jar
Binary file not shown.
Binary file removed lib/rack_jetty/jars/jetty-6.1.14.jar
Binary file not shown.
Binary file added lib/rack_jetty/jars/jetty-6.1.26.jar
Binary file not shown.
Binary file added lib/rack_jetty/jars/jetty-management-6.1.26.jar
Binary file not shown.
Binary file added lib/rack_jetty/jars/jetty-plus-6.1.26.jar
Binary file not shown.
Binary file removed lib/rack_jetty/jars/jetty-util-6.1.14.jar
Binary file not shown.
Binary file added lib/rack_jetty/jars/jetty-util-6.1.26.jar
Binary file not shown.
Binary file not shown.
Binary file added lib/rack_jetty/jars/jsp-2.1-jetty-6.1.26.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
14 changes: 9 additions & 5 deletions rack-jetty.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down