mizuno 0.6.1 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mizuno.rb CHANGED
@@ -4,23 +4,36 @@
4
4
  # Written by Don Werve <don@madwombat.com>
5
5
  #
6
6
 
7
+ require 'java'
8
+
7
9
  # Save our launch environment for spawning children later.
8
10
  module Mizuno
9
11
  LAUNCH_ENV = $LOAD_PATH.map { |i| "-I#{i}" }.push($0)
10
- end
11
12
 
12
- # Load up Java dependencies.
13
- require 'java'
14
- jars = File.join(File.dirname(__FILE__), 'java', '*.jar')
15
- Dir[jars].each { |j| require j }
13
+ HOME = File.expand_path(File.dirname(__FILE__))
14
+
15
+ #
16
+ # Tell log4j not to complain to the console about a missing
17
+ # log4j.properties file, as we configure it programmatically in
18
+ # Mizuno::Server (http://stackoverflow.com/questions/6849887)
19
+ #
20
+ def Mizuno.initialize_logger
21
+ require_jars(%w(log4j slf4j-api slf4j-log4j12))
22
+ Java.org.apache.log4j.Logger.getRootLogger.setLevel( \
23
+ Java.org.apache.log4j.Level::INFO)
24
+ end
16
25
 
17
- # Tell log4j not to complain to the console about a missing
18
- # log4j.properties file, as we configure it programmatically in
19
- # Mizuno::HttpServer (http://stackoverflow.com/questions/6849887)
20
- Java.org.apache.log4j.Logger.getRootLogger.setLevel( \
21
- Java.org.apache.log4j.Level::INFO)
26
+ #
27
+ # Loads jarfiles independent of versions.
28
+ #
29
+ def Mizuno.require_jars(*names)
30
+ names.flatten.each do |name|
31
+ file = Dir[File.join(HOME, 'java', "#{name}-*.jar")].first
32
+ file ||= Dir[File.join(HOME, 'java', "#{name}.jar")].first
33
+ raise("Unknown or missing jar: #{name}") unless file
34
+ require file
35
+ end
36
+ end
37
+ end
22
38
 
23
- require 'rack'
24
- require 'mizuno/rack/chunked'
25
- require 'mizuno/rack_servlet'
26
- require 'mizuno/http_server'
39
+ Mizuno.initialize_logger
@@ -155,7 +155,7 @@ Choice.options do
155
155
  long '--version'
156
156
  desc 'Show version'
157
157
  action do
158
- $stderr.puts Mizuno::HttpServer.version
158
+ $stderr.puts Mizuno::Server.version
159
159
  exit
160
160
  end
161
161
  end
@@ -0,0 +1,62 @@
1
+ require 'thread'
2
+ require 'mizuno'
3
+ Mizuno.require_jars(%w(jetty-client jetty-http jetty-io jetty-util))
4
+ require 'mizuno/client_exchange'
5
+
6
+ module Mizuno
7
+ class Client
8
+ java_import 'org.eclipse.jetty.client.HttpClient'
9
+ java_import 'org.eclipse.jetty.util.thread.QueuedThreadPool'
10
+
11
+ @lock = Mutex.new
12
+
13
+ def Client.request(*args, &block)
14
+ @lock.synchronize { @root ||= new }
15
+ @root.request(*args, &block)
16
+ end
17
+
18
+ def Client.stop
19
+ @lock.synchronize do
20
+ return unless @root
21
+ @root.stop
22
+ @root = nil
23
+ end
24
+ end
25
+
26
+ def initialize(options = {})
27
+ defaults = { :timeout => 60 }
28
+ options = defaults.merge(options)
29
+ @client = HttpClient.new
30
+ @client.setConnectorType(HttpClient::CONNECTOR_SELECT_CHANNEL)
31
+ @client.setMaxConnectionsPerAddress(100)
32
+ @client.setThreadPool(QueuedThreadPool.new(50))
33
+ @client.setTimeout(options[:timeout] * 1000)
34
+ @client.start
35
+ @lock = Mutex.new
36
+ @exchanges = []
37
+ end
38
+
39
+ def stop(wait = true)
40
+ wait and @lock.synchronize do
41
+ @exchanges.each { |e| e.waitForDone }
42
+ @exchanges.clear
43
+ end
44
+ @client.stop
45
+ end
46
+
47
+ def clear(exchange)
48
+ return unless @lock.try_lock
49
+ @exchanges.delete(exchange)
50
+ @lock.unlock
51
+ end
52
+
53
+ def request(url, options = {}, &block)
54
+ exchange = ClientExchange.new(self)
55
+ @lock.synchronize { @exchanges << exchange }
56
+ exchange.setup(url, options, &block)
57
+ @client.send(exchange)
58
+ return(exchange)
59
+ end
60
+ end
61
+ end
62
+
@@ -0,0 +1,72 @@
1
+ require 'stringio'
2
+ require 'mizuno/client_response'
3
+
4
+ module Mizuno
5
+ java_import 'org.eclipse.jetty.client.ContentExchange'
6
+
7
+ # what do I want to happen on a timeout or error?
8
+
9
+ class ClientExchange < ContentExchange
10
+ def initialize(client)
11
+ super(false)
12
+ @client = client
13
+ end
14
+
15
+ def setup(url, options = {}, &block)
16
+ @callback = block
17
+ @response = ClientResponse.new(url)
18
+ setURL(url)
19
+ @response.ssl = (getScheme == 'https')
20
+ setMethod((options[:method] or "GET").upcase)
21
+ headers = options[:headers] and headers.each_pair { |k, v|
22
+ setRequestHeader(k, v) }
23
+ return unless options[:body]
24
+ body = StringIO.new(options[:body].read)
25
+ setRequestContentSource(body.to_inputstream)
26
+ end
27
+
28
+ def onResponseHeader(name, value)
29
+ @response[name.to_s] = value.to_s
30
+ end
31
+
32
+ def onResponseComplete
33
+ @client.clear(self)
34
+ @response.status = getResponseStatus
35
+ @response.body = getResponseContent
36
+ run_callback
37
+ end
38
+
39
+ def onExpire
40
+ @client.clear(self)
41
+ @response.timeout = true
42
+ @response.status = -1
43
+ @response.body = nil
44
+ run_callback
45
+ end
46
+
47
+ def onException(error)
48
+ @exception ||= error
49
+ end
50
+
51
+ def onConnectionFailed(error)
52
+ @exception ||= error
53
+ end
54
+
55
+ def run_callback
56
+ begin
57
+ @callback.call(@response)
58
+ rescue => error
59
+ onException(error)
60
+ end
61
+ end
62
+
63
+ def waitForDone
64
+ super
65
+ throw(@exception) if @exception
66
+ end
67
+ #
68
+ # def finished?
69
+ # #FIXME: Implement.
70
+ # end
71
+ end
72
+ end
@@ -0,0 +1,34 @@
1
+ require 'rack/response'
2
+
3
+ module Mizuno
4
+ class ClientResponse
5
+ include Rack::Response::Helpers
6
+
7
+ attr_accessor :url, :status, :headers, :body, :ssl, :timeout
8
+
9
+ def initialize(url)
10
+ @url = url
11
+ @headers = Rack::Utils::HeaderHash.new
12
+ end
13
+
14
+ def [](key)
15
+ @headers[key]
16
+ end
17
+
18
+ def []=(key, value)
19
+ @headers[key] = value
20
+ end
21
+
22
+ def ssl?
23
+ @ssl == true
24
+ end
25
+
26
+ def timeout?
27
+ (@timeout == true) or (@status == 408)
28
+ end
29
+
30
+ def success?
31
+ successful? or redirect?
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,87 @@
1
+ require 'logger'
2
+
3
+ module Mizuno
4
+ class Logger < ::Logger
5
+ java_import 'java.io.ByteArrayInputStream'
6
+ java_import 'java.util.Properties'
7
+ java_import 'org.apache.log4j.PropertyConfigurator'
8
+
9
+ LEVELS = {
10
+ ::Logger::DEBUG => Java.org.apache.log4j.Level::DEBUG,
11
+ ::Logger::INFO => Java.org.apache.log4j.Level::INFO,
12
+ ::Logger::WARN => Java.org.apache.log4j.Level::WARN,
13
+ ::Logger::ERROR => Java.org.apache.log4j.Level::ERROR,
14
+ ::Logger::FATAL => Java.org.apache.log4j.Level::FATAL }
15
+
16
+ #
17
+ # Configure Log4J.
18
+ #
19
+ def Logger.configure(options = {})
20
+ return if @options
21
+ @options = options
22
+
23
+ # Default logging threshold.
24
+ limit = options[:warn] ? "WARN" : "ERROR"
25
+ limit = "DEBUG" if ($DEBUG or options[:debug])
26
+
27
+ # Base logging configuration.
28
+ config = <<-END
29
+ log4j.rootCategory = #{limit}, default
30
+ log4j.logger.org.eclipse.jetty.util.log = #{limit}, default
31
+ log4j.appender.default.Threshold = #{limit}
32
+ log4j.appender.default.layout = org.apache.log4j.PatternLayout
33
+ END
34
+
35
+ # Should we log to the console?
36
+ config.concat(<<-END) unless options[:log]
37
+ log4j.appender.default = org.apache.log4j.ConsoleAppender
38
+ log4j.appender.default.layout.ConversionPattern = %m\\n
39
+ END
40
+
41
+ # Are we logging to a file?
42
+ config.concat(<<-END) if options[:log]
43
+ log4j.appender.default = org.apache.log4j.FileAppender
44
+ log4j.appender.default.Append = true
45
+ log4j.appender.default.File = #{options[:log]}
46
+ log4j.appender.default.layout.ConversionPattern = %d %p %m\\n
47
+ END
48
+
49
+ # Set up Log4J via Properties.
50
+ properties = Properties.new
51
+ properties.load(ByteArrayInputStream.new(config.to_java_bytes))
52
+ PropertyConfigurator.configure(properties)
53
+
54
+ # Create the default logger that gets used everywhere.
55
+ @logger = new
56
+ end
57
+
58
+ def Logger.logger
59
+ @logger
60
+ end
61
+
62
+ def initialize
63
+ @log4j = Java.org.apache.log4j.Logger.getLogger('ruby')
64
+ end
65
+
66
+ def add(severity, message = nil, progname = nil)
67
+ content = (message or (block_given? and yield) or progname)
68
+ @log4j.log(LEVELS[severity], content)
69
+ end
70
+
71
+ def puts(message)
72
+ write(message.to_s)
73
+ end
74
+
75
+ def write(message)
76
+ add(INFO, message)
77
+ end
78
+
79
+ def flush
80
+ # No-op.
81
+ end
82
+
83
+ def close
84
+ # No-op.
85
+ end
86
+ end
87
+ end
@@ -11,16 +11,21 @@ require 'rack/response'
11
11
  # /servlet/http/HttpServlet.html
12
12
  #
13
13
  module Mizuno
14
- include_class javax.servlet.http.HttpServlet
14
+ java_import 'javax.servlet.http.HttpServlet'
15
15
 
16
16
  class RackServlet < HttpServlet
17
- include_class java.io.FileInputStream
18
- include_class org.eclipse.jetty.continuation.ContinuationSupport
19
- include_class org.jruby.rack.servlet.RewindableInputStream
17
+ java_import 'java.io.FileInputStream'
18
+ java_import 'org.eclipse.jetty.continuation.ContinuationSupport'
19
+ java_import 'org.jruby.rack.servlet.RewindableInputStream'
20
20
 
21
21
  # Regex for splitting on newlines.
22
22
  NEWLINE = /\n/
23
23
 
24
+ def initialize(server)
25
+ @server = server
26
+ super()
27
+ end
28
+
24
29
  #
25
30
  # Sets the Rack application that handles requests sent to this
26
31
  # servlet container.
@@ -67,7 +72,7 @@ module Mizuno
67
72
 
68
73
  # Add an callback that can be used to add results to the
69
74
  # response asynchronously.
70
- env['async.callback'] = lambda do |rack_response|
75
+ env['async.callback'] = Proc.new do |rack_response|
71
76
  servlet_response = continuation.getServletResponse
72
77
  rack_to_servlet(rack_response, servlet_response) \
73
78
  and continuation.complete
@@ -117,7 +122,7 @@ module Mizuno
117
122
  env['SCRIPT_NAME'] = ""
118
123
 
119
124
  # Rack says URI, but it hands off a URL.
120
- env['REQUEST_URI'] = request.getRequestURL.toString
125
+ env['REQUEST_URI'] = request.getRequestURL.to_s
121
126
 
122
127
  # Java chops off the query string, but a Rack application will
123
128
  # expect it, so we'll add it back if present
@@ -151,8 +156,8 @@ module Mizuno
151
156
  if env["HTTP_CONTENT_LENGTH"]
152
157
 
153
158
  # Route errors through the logger.
154
- env['rack.errors'] ||= HttpServer.logger
155
- env['rack.logger'] ||= HttpServer.logger
159
+ env['rack.errors'] ||= @server.logger
160
+ env['rack.logger'] ||= @server.logger
156
161
 
157
162
  # All done, hand back the Rack request.
158
163
  return(env)
@@ -244,7 +249,7 @@ module Mizuno
244
249
  message = "Exception: #{error}"
245
250
  message << "\n#{error.backtrace.join("\n")}" \
246
251
  if (error.respond_to?(:backtrace))
247
- HttpServer.logger.error(message)
252
+ Server.logger.error(message)
248
253
  return if response.isCommitted
249
254
  response.reset
250
255
  response.setStatus(500)
@@ -12,6 +12,10 @@ module Mizuno
12
12
  # by sending a SIGHUP to the process.
13
13
  #
14
14
  class Reloader
15
+ @reloaders = []
16
+
17
+ @trigger = 'tmp/restart.txt'
18
+
15
19
  class << self
16
20
  attr_accessor :logger, :trigger, :reloaders
17
21
  end
@@ -20,14 +24,15 @@ module Mizuno
20
24
  reloaders.each { |r| r.reload!(true) }
21
25
  end
22
26
 
23
- def initialize(app, interval = 1)
27
+ def Reloader.add(reloader)
24
28
  Thread.exclusive do
25
- self.class.reloaders ||= []
26
- self.class.reloaders << self
27
- self.class.logger ||= Mizuno::HttpServer.logger
28
- self.class.trigger ||= "tmp/restart.txt"
29
+ @logger ||= Mizuno::Server.logger
30
+ @reloaders << reloader
29
31
  end
32
+ end
30
33
 
34
+ def initialize(app, interval = 1)
35
+ Reloader.add(self)
31
36
  @app = app
32
37
  @interval = interval
33
38
  @trigger = self.class.trigger
data/lib/mizuno/runner.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  require 'ffi'
2
2
  require 'net/http'
3
3
  require 'choice'
4
- require 'mizuno/choices'
5
4
  require 'childprocess'
6
5
  require 'fileutils'
7
6
  require 'etc'
8
7
  require 'rack'
8
+ require 'mizuno'
9
+ require 'mizuno/choices'
10
+ require 'mizuno/server'
11
+ require 'rack/handler/mizuno'
9
12
 
10
13
  module Mizuno
11
14
  require 'rbconfig'
@@ -99,7 +102,7 @@ module Mizuno
99
102
 
100
103
  # Fire up Mizuno as if it was called from Rackup.
101
104
  Dir.chdir(options[:root])
102
- HttpServer.configure_logging(options)
105
+ Logger.configure(options)
103
106
  ENV['RACK_ENV'] = options[:env]
104
107
  server = Rack::Server.new
105
108
  server.options = options.merge(:server => 'mizuno',
@@ -260,7 +263,7 @@ module Mizuno
260
263
  #
261
264
  # Exit with a message and a status value.
262
265
  #
263
- # FIXME: Dump these in the logfile if called from HttpServer?
266
+ # FIXME: Dump these in the logfile if called from Server?
264
267
  #
265
268
  def Runner.die(message, success = false)
266
269
  $stderr.puts(message)
@@ -268,3 +271,6 @@ module Mizuno
268
271
  end
269
272
  end
270
273
  end
274
+
275
+ # Ensure that we shutdown the server on exit.
276
+ at_exit { Mizuno::Server.stop }
@@ -0,0 +1,138 @@
1
+ # FIXME: mizuno/http_server needs to still work, but we will throw out a
2
+ # deprecation notice and remove it in later versions.
3
+
4
+ require 'rack'
5
+ require 'mizuno'
6
+ Mizuno.require_jars(%w(jetty-continuation jetty-http jetty-io jetty-jmx
7
+ jetty-security jetty-server jetty-servlet jetty-servlets jetty-util
8
+ servlet-api rewindable-input-stream))
9
+ require 'mizuno/version'
10
+ require 'mizuno/rack/chunked'
11
+ require 'mizuno/rack_servlet'
12
+ require 'mizuno/logger'
13
+ require 'mizuno/reloader'
14
+
15
+ module Mizuno
16
+ class Server
17
+ java_import 'org.eclipse.jetty.servlet.ServletContextHandler'
18
+ java_import 'org.eclipse.jetty.servlet.ServletHolder'
19
+ java_import 'org.eclipse.jetty.server.nio.SelectChannelConnector'
20
+ java_import 'org.eclipse.jetty.util.thread.QueuedThreadPool'
21
+
22
+ attr_accessor :logger
23
+
24
+ @lock ||= Mutex.new
25
+
26
+ def Server.run(app, options = {})
27
+ @lock.synchronize do
28
+ return if @server
29
+ @server = new
30
+ @server.run(app, options)
31
+ end
32
+ end
33
+
34
+ def Server.stop
35
+ @lock.synchronize do
36
+ return unless @server
37
+ @server.stop
38
+ @server = nil
39
+ end
40
+ end
41
+
42
+ def Server.logger
43
+ Logger.logger
44
+ end
45
+
46
+ #
47
+ # Start up an instance of Jetty, running a Rack application.
48
+ # Options can be any of the follwing, and are not
49
+ # case-sensitive:
50
+ #
51
+ # :host::
52
+ # String specifying the IP address to bind to; defaults
53
+ # to 0.0.0.0.
54
+ #
55
+ # :port::
56
+ # String or integer with the port to bind to; defaults
57
+ # to 9292.
58
+ #
59
+ def run(app, options = {})
60
+ # Symbolize and downcase keys.
61
+ @options = options = Hash[options.map { |k, v|
62
+ [ k.to_s.downcase.to_sym, v ] }]
63
+ options[:quiet] ||= true if options[:embedded]
64
+
65
+ # The Jetty server
66
+ Logger.configure(options)
67
+ @logger = Logger.logger
68
+ @server = Java.org.eclipse.jetty.server.Server.new
69
+ @server.setSendServerVersion(false)
70
+
71
+ # Thread pool
72
+ threads = options[:threads] || 50
73
+ thread_pool = QueuedThreadPool.new
74
+ thread_pool.min_threads = [ threads.to_i / 10, 5 ].max
75
+ thread_pool.max_threads = [ threads.to_i, 10 ].max
76
+ @server.set_thread_pool(thread_pool)
77
+
78
+ # Connector
79
+ connector = SelectChannelConnector.new
80
+ connector.setPort(options[:port].to_i)
81
+ connector.setHost(options[:host])
82
+ @server.addConnector(connector)
83
+
84
+ # Switch to a different user or group if we were asked to.
85
+ Runner.setgid(options) if options[:group]
86
+ Runner.setuid(options) if options[:user]
87
+
88
+ # Servlet handler.
89
+ app_handler = ServletContextHandler.new(nil, "/",
90
+ ServletContextHandler::NO_SESSIONS)
91
+
92
+ # Optionally wrap with Mizuno::Reloader.
93
+ threshold = (ENV['RACK_ENV'] == 'production' ? 10 : 1)
94
+ app = Mizuno::Reloader.new(app, threshold) \
95
+ if options[:reloadable]
96
+
97
+ # The servlet itself.
98
+ rack_servlet = RackServlet.new(self)
99
+ rack_servlet.rackup(app)
100
+ holder = ServletHolder.new(rack_servlet)
101
+ app_handler.addServlet(holder, "/")
102
+
103
+ # Add the context to the server and start.
104
+ @server.set_handler(app_handler)
105
+ @server.start
106
+ $stderr.printf("%s listening on %s:%s\n", version,
107
+ connector.host, connector.port) unless options[:quiet]
108
+
109
+ # If we're embeded, we're done.
110
+ return if options[:embedded]
111
+
112
+ # Stop the server when we get The Signal.
113
+ trap("SIGINT") { @server.stop and exit }
114
+
115
+ # Join with the server thread, so that currently open file
116
+ # descriptors don't get closed by accident.
117
+ # http://www.ruby-forum.com/topic/209252
118
+ @server.join
119
+ end
120
+
121
+ #
122
+ # Shuts down an embedded Jetty instance.
123
+ #
124
+ def stop
125
+ return unless @server
126
+ $stderr.print "Stopping Jetty..." unless @options[:quiet]
127
+ @server.stop
128
+ $stderr.puts "done." unless @options[:quiet]
129
+ end
130
+
131
+ #
132
+ # Returns the full version string.
133
+ #
134
+ def version
135
+ "Mizuno #{Mizuno::VERSION} (Jetty #{Java.org.eclipse.jetty.server.Server.getVersion})"
136
+ end
137
+ end
138
+ end
@@ -1,3 +1,3 @@
1
1
  module Mizuno
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.3"
3
3
  end
@@ -1,4 +1,4 @@
1
- require 'mizuno'
1
+ require 'mizuno/server'
2
2
 
3
3
  # Register ourselves with Rack when this file gets loaded.
4
- Rack::Handler.register 'mizuno', 'Mizuno::HttpServer'
4
+ Rack::Handler.register 'mizuno', 'Mizuno::Server'
metadata CHANGED
@@ -1,171 +1,169 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mizuno
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.6.1
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.6.3
6
6
  platform: ruby
7
- authors:
8
- - Don Werve
9
- autorequire:
7
+ authors:
8
+ - Don Werve
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-04-23 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rack
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.0.0
24
- type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: ffi
28
- prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
30
- none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: 1.0.0
35
- type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: choice
39
- prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: 0.1.0
46
- type: :runtime
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: childprocess
50
- prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: 0.2.6
57
- type: :runtime
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
60
- name: rspec
61
- prerelease: false
62
- requirement: &id005 !ruby/object:Gem::Requirement
63
- none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: 2.7.0
68
- type: :development
69
- version_requirements: *id005
70
- - !ruby/object:Gem::Dependency
71
- name: rspec-core
72
- prerelease: false
73
- requirement: &id006 !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: 2.7.0
79
- type: :development
80
- version_requirements: *id006
81
- - !ruby/object:Gem::Dependency
82
- name: json_pure
83
- prerelease: false
84
- requirement: &id007 !ruby/object:Gem::Requirement
85
- none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: 1.6.0
90
- type: :development
91
- version_requirements: *id007
92
- - !ruby/object:Gem::Dependency
93
- name: nokogiri
94
- prerelease: false
95
- requirement: &id008 !ruby/object:Gem::Requirement
96
- none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- version: "0"
101
- type: :development
102
- version_requirements: *id008
12
+ date: 2012-04-29 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
16
+ version_requirements: &2056 !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: 1.0.0
21
+ none: false
22
+ requirement: *2056
23
+ prerelease: false
24
+ type: :runtime
25
+ - !ruby/object:Gem::Dependency
26
+ name: ffi
27
+ version_requirements: &2074 !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: 1.0.0
32
+ none: false
33
+ requirement: *2074
34
+ prerelease: false
35
+ type: :runtime
36
+ - !ruby/object:Gem::Dependency
37
+ name: choice
38
+ version_requirements: &2090 !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: 0.1.0
43
+ none: false
44
+ requirement: *2090
45
+ prerelease: false
46
+ type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: childprocess
49
+ version_requirements: &2106 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.2.6
54
+ none: false
55
+ requirement: *2106
56
+ prerelease: false
57
+ type: :runtime
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ version_requirements: &2122 !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: 2.7.0
65
+ none: false
66
+ requirement: *2122
67
+ prerelease: false
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-core
71
+ version_requirements: &2140 !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 2.7.0
76
+ none: false
77
+ requirement: *2140
78
+ prerelease: false
79
+ type: :development
80
+ - !ruby/object:Gem::Dependency
81
+ name: json_pure
82
+ version_requirements: &2156 !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: 1.6.0
87
+ none: false
88
+ requirement: *2156
89
+ prerelease: false
90
+ type: :development
91
+ - !ruby/object:Gem::Dependency
92
+ name: nokogiri
93
+ version_requirements: &2172 !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ none: false
99
+ requirement: *2172
100
+ prerelease: false
101
+ type: :development
103
102
  description: Jetty-powered running shoes for JRuby/Rack.
104
103
  email: don@madwombat.com
105
- executables:
106
- - mizuno
104
+ executables:
105
+ - mizuno
107
106
  extensions: []
108
-
109
107
  extra_rdoc_files: []
110
-
111
- files:
112
- - .gitignore
113
- - README.markdown
114
- - LICENSE
115
- - Rakefile
116
- - Gemfile
117
- - mizuno.gemspec
118
- - bin/mizuno
119
- - lib/mizuno.rb
120
- - lib/mizuno/choices.rb
121
- - lib/mizuno/http_server.rb
122
- - lib/mizuno/java_logger.rb
123
- - lib/mizuno/rack_servlet.rb
124
- - lib/mizuno/reloader.rb
125
- - lib/mizuno/runner.rb
126
- - lib/mizuno/version.rb
127
- - lib/mizuno/rack/chunked.rb
128
- - lib/rack/handler/mizuno.rb
129
- - lib/java/jetty-continuation-8.1.2.v20120308.jar
130
- - lib/java/jetty-http-8.1.2.v20120308.jar
131
- - lib/java/jetty-io-8.1.2.v20120308.jar
132
- - lib/java/jetty-jmx-8.1.2.v20120308.jar
133
- - lib/java/jetty-security-8.1.2.v20120308.jar
134
- - lib/java/jetty-server-8.1.2.v20120308.jar
135
- - lib/java/jetty-servlet-8.1.2.v20120308.jar
136
- - lib/java/jetty-servlets-8.1.2.v20120308.jar
137
- - lib/java/jetty-util-8.1.2.v20120308.jar
138
- - lib/java/log4j-1.2.16.jar
139
- - lib/java/rewindable-input-stream.jar
140
- - lib/java/servlet-api-3.0.jar
141
- - lib/java/slf4j-api-1.6.4.jar
142
- - lib/java/slf4j-log4j12-1.6.4.jar
108
+ files:
109
+ - .gitignore
110
+ - README.markdown
111
+ - LICENSE
112
+ - Rakefile
113
+ - Gemfile
114
+ - mizuno.gemspec
115
+ - bin/mizuno
116
+ - lib/mizuno.rb
117
+ - lib/mizuno/choices.rb
118
+ - lib/mizuno/client.rb
119
+ - lib/mizuno/client_exchange.rb
120
+ - lib/mizuno/client_response.rb
121
+ - lib/mizuno/logger.rb
122
+ - lib/mizuno/rack_servlet.rb
123
+ - lib/mizuno/reloader.rb
124
+ - lib/mizuno/runner.rb
125
+ - lib/mizuno/server.rb
126
+ - lib/mizuno/version.rb
127
+ - lib/mizuno/rack/chunked.rb
128
+ - lib/rack/handler/mizuno.rb
129
+ - lib/java/jetty-client-8.1.3.v20120416.jar
130
+ - lib/java/jetty-continuation-8.1.3.v20120416.jar
131
+ - lib/java/jetty-http-8.1.3.v20120416.jar
132
+ - lib/java/jetty-io-8.1.3.v20120416.jar
133
+ - lib/java/jetty-jmx-8.1.3.v20120416.jar
134
+ - lib/java/jetty-security-8.1.3.v20120416.jar
135
+ - lib/java/jetty-server-8.1.3.v20120416.jar
136
+ - lib/java/jetty-servlet-8.1.3.v20120416.jar
137
+ - lib/java/jetty-servlets-8.1.3.v20120416.jar
138
+ - lib/java/jetty-util-8.1.3.v20120416.jar
139
+ - lib/java/log4j-1.2.16.jar
140
+ - lib/java/rewindable-input-stream.jar
141
+ - lib/java/servlet-api-3.0.jar
142
+ - lib/java/slf4j-api-1.6.4.jar
143
+ - lib/java/slf4j-log4j12-1.6.4.jar
143
144
  homepage: http://github.com/matadon/mizuno
144
145
  licenses: []
145
-
146
- post_install_message:
146
+ post_install_message:
147
147
  rdoc_options: []
148
-
149
- require_paths:
150
- - lib
151
- required_ruby_version: !ruby/object:Gem::Requirement
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
152
155
  none: false
153
- requirements:
154
- - - ">="
155
- - !ruby/object:Gem::Version
156
- version: "0"
157
- required_rubygems_version: !ruby/object:Gem::Requirement
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ! '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '1.2'
158
161
  none: false
159
- requirements:
160
- - - ">="
161
- - !ruby/object:Gem::Version
162
- version: "1.2"
163
162
  requirements: []
164
-
165
- rubyforge_project:
163
+ rubyforge_project:
166
164
  rubygems_version: 1.8.15
167
- signing_key:
165
+ signing_key:
168
166
  specification_version: 3
169
167
  summary: Rack handler for Jetty 8 on JRuby. Features multithreading, event-driven I/O, and async support.
170
168
  test_files: []
171
-
169
+ ...
@@ -1,185 +0,0 @@
1
- require 'mizuno/version'
2
- require 'mizuno/java_logger'
3
- require 'mizuno/reloader'
4
-
5
- module Mizuno
6
- class HttpServer
7
- include_class 'java.util.Properties'
8
- include_class 'java.io.ByteArrayInputStream'
9
- include_class 'org.apache.log4j.PropertyConfigurator'
10
- include_class 'org.eclipse.jetty.server.Server'
11
- include_class 'org.eclipse.jetty.servlet.ServletContextHandler'
12
- include_class 'org.eclipse.jetty.servlet.ServletHolder'
13
- include_class 'org.eclipse.jetty.server.nio.SelectChannelConnector'
14
- include_class 'org.eclipse.jetty.util.thread.QueuedThreadPool'
15
- # include_class 'org.eclipse.jetty.servlet.DefaultServlet'
16
- # include_class 'org.eclipse.jetty.server.handler.HandlerCollection'
17
- # include_class 'org.eclipse.jetty.server.handler.RequestLogHandler'
18
- # include_class 'org.eclipse.jetty.server.NCSARequestLog'
19
-
20
- #
21
- # Provide accessors so we can set a custom logger and a location
22
- # for static assets.
23
- #
24
- class << self
25
- attr_accessor :logger
26
- end
27
-
28
- #
29
- # Start up an instance of Jetty, running a Rack application.
30
- # Options can be any of the follwing, and are not
31
- # case-sensitive:
32
- #
33
- # :host::
34
- # String specifying the IP address to bind to; defaults
35
- # to 0.0.0.0.
36
- #
37
- # :port::
38
- # String or integer with the port to bind to; defaults
39
- # to 9292.
40
- #
41
- # http://wiki.eclipse.org/Jetty/Tutorial/RequestLog
42
- #
43
- # FIXME: Add SSL suport.
44
- #
45
- def HttpServer.run(app, options = {})
46
- # Symbolize and downcase keys.
47
- @options = options = Hash[options.map { |k, v|
48
- [ k.to_s.downcase.to_sym, v ] }]
49
- options[:quiet] ||= true if options[:embedded]
50
-
51
- # The Jetty server
52
- configure_logging(options)
53
- @server = Server.new
54
- @server.setSendServerVersion(false)
55
-
56
- # Thread pool
57
- threads = options[:threads] || 50
58
- thread_pool = QueuedThreadPool.new
59
- thread_pool.min_threads = [ threads.to_i / 10, 5 ].max
60
- thread_pool.max_threads = [ threads.to_i, 10 ].max
61
- @server.set_thread_pool(thread_pool)
62
-
63
- # Connector
64
- connector = SelectChannelConnector.new
65
- connector.setPort(options[:port].to_i)
66
- connector.setHost(options[:host])
67
- @server.addConnector(connector)
68
-
69
- # Switch to a different user or group if we were asked to.
70
- Runner.setgid(options) if options[:group]
71
- Runner.setuid(options) if options[:user]
72
-
73
- # Servlet handler.
74
- app_handler = ServletContextHandler.new(nil, "/",
75
- ServletContextHandler::NO_SESSIONS)
76
-
77
- # Optionally wrap with Mizuno::Reloader.
78
- threshold = (ENV['RACK_ENV'] == 'production' ? 10 : 1)
79
- app = Mizuno::Reloader.new(app, threshold) \
80
- if options[:reloadable]
81
-
82
- # The servlet itself.
83
- rack_servlet = RackServlet.new
84
- rack_servlet.rackup(app)
85
- holder = ServletHolder.new(rack_servlet)
86
- app_handler.addServlet(holder, "/")
87
-
88
- # # Our request log.
89
- # request_log = NCSARequestLog.new
90
- # request_log.setLogTimeZone("GMT")
91
- # request_log_handler = RequestLogHandler.new
92
- # request_log_handler.setRequestLog(request_log)
93
- #
94
- # # Add handlers in order.
95
- # handlers = HandlerCollection.new
96
- # handlers.addHandler(request_log_handler)
97
- # handlers.addHandler(app_handler)
98
-
99
- # Add the context to the server and start.
100
- @server.set_handler(app_handler)
101
- @server.start
102
- $stderr.printf("%s listening on %s:%s\n", version,
103
- connector.host, connector.port) unless options[:quiet]
104
-
105
- # If we're embeded, we're done.
106
- return if options[:embedded]
107
-
108
- # Stop the server when we get The Signal.
109
- trap("SIGINT") { @server.stop and exit }
110
-
111
- # Join with the server thread, so that currently open file
112
- # descriptors don't get closed by accident.
113
- # http://www.ruby-forum.com/topic/209252
114
- @server.join
115
- end
116
-
117
- #
118
- # Shuts down an embedded Jetty instance.
119
- #
120
- def HttpServer.stop
121
- return unless @server
122
- $stderr.print "Stopping Jetty..." unless @options[:quiet]
123
- @server.stop
124
- $stderr.puts "done." unless @options[:quiet]
125
- end
126
-
127
- #
128
- # Returns the full version string.
129
- #
130
- def HttpServer.version
131
- "Mizuno #{Mizuno::VERSION} (Jetty #{Server.getVersion})"
132
- end
133
-
134
- #
135
- # Configure Log4J.
136
- #
137
- def HttpServer.configure_logging(options)
138
- return if @logger
139
-
140
- # Default logging threshold.
141
- limit = options[:warn] ? "WARN" : "ERROR"
142
- limit = "DEBUG" if ($DEBUG or options[:debug])
143
-
144
- # Base logging configuration.
145
- config = <<-END
146
- log4j.rootCategory = #{limit}, default
147
- log4j.logger.org.eclipse.jetty.util.log = #{limit}, default
148
- log4j.logger.ruby = INFO, ruby
149
- log4j.appender.default.Threshold = #{limit}
150
- log4j.appender.default.layout = org.apache.log4j.PatternLayout
151
- log4j.appender.default.layout.ConversionPattern = %d %p %m
152
- log4j.appender.ruby.Threshold = INFO
153
- log4j.appender.ruby.layout = org.apache.log4j.PatternLayout
154
- log4j.appender.ruby.layout.ConversionPattern = %m
155
- END
156
-
157
- # Should we log to the console?
158
- config.concat(<<-END) unless options[:log]
159
- log4j.appender.default = org.apache.log4j.ConsoleAppender
160
- log4j.appender.ruby = org.apache.log4j.ConsoleAppender
161
- END
162
-
163
- # Are we logging to a file?
164
- config.concat(<<-END) if options[:log]
165
- log4j.appender.default = org.apache.log4j.FileAppender
166
- log4j.appender.default.File = #{options[:log]}
167
- log4j.appender.default.Append = true
168
- log4j.appender.ruby = org.apache.log4j.FileAppender
169
- log4j.appender.ruby.File = #{options[:log]}
170
- log4j.appender.ruby.Append = true
171
- END
172
-
173
- # Set up Log4J via Properties.
174
- properties = Properties.new
175
- properties.load(ByteArrayInputStream.new(config.to_java_bytes))
176
- PropertyConfigurator.configure(properties)
177
-
178
- # Use log4j for our logging as well.
179
- @logger = JavaLogger.new
180
- end
181
- end
182
- end
183
-
184
- # Ensure that we shutdown the server on exit.
185
- at_exit { Mizuno::HttpServer.stop }
@@ -1,37 +0,0 @@
1
- require 'logger'
2
-
3
- module Mizuno
4
- class JavaLogger < Logger
5
- LEVELS = {
6
- Logger::DEBUG => Java.org.apache.log4j.Level::DEBUG,
7
- Logger::INFO => Java.org.apache.log4j.Level::INFO,
8
- Logger::WARN => Java.org.apache.log4j.Level::WARN,
9
- Logger::ERROR => Java.org.apache.log4j.Level::ERROR,
10
- Logger::FATAL => Java.org.apache.log4j.Level::FATAL }
11
-
12
- def initialize
13
- @log4j = Java.org.apache.log4j.Logger.getLogger('ruby')
14
- end
15
-
16
- def add(severity, message = nil, progname = nil)
17
- content = (message or (block_given? and yield) or progname)
18
- @log4j.log(LEVELS[severity], content)
19
- end
20
-
21
- def puts(message)
22
- write(message.to_s)
23
- end
24
-
25
- def write(message)
26
- add(INFO, message)
27
- end
28
-
29
- def flush
30
- # No-op.
31
- end
32
-
33
- def close
34
- # No-op.
35
- end
36
- end
37
- end