jettr 0.2.1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/bin/jettr +7 -0
- data/features/jettr/create_simple_server.feature +42 -0
- data/features/jettr/step_definitions/create_server_steps.rb +57 -0
- data/features/jettr/support/hooks.rb +5 -0
- data/features/jettr/support/lib.rb +3 -0
- data/jettr.gemspec +80 -0
- data/lib/jettr.rb +13 -0
- data/lib/jettr/command.rb +72 -0
- data/lib/jettr/config.rb +48 -0
- data/lib/jettr/handler.rb +16 -0
- data/lib/jettr/handler/base.rb +5 -0
- data/lib/jettr/handler/rails.rb +32 -0
- data/lib/jettr/handler/simple_handler.rb +19 -0
- data/lib/jettr/handler/web_app.rb +18 -0
- data/lib/jettr/jars.rb +40 -0
- data/lib/jettr/jars/akuma-1.3-jar-with-dependencies.jar +0 -0
- data/lib/jettr/jars/core-3.1.1.jar +0 -0
- data/lib/jettr/jars/jettr-java.jar +0 -0
- data/lib/jettr/jars/jetty-6.1.14.jar +0 -0
- data/lib/jettr/jars/jetty-plus-6.1.14.jar +0 -0
- data/lib/jettr/jars/jetty-util-6.1.14.jar +0 -0
- data/lib/jettr/jars/jruby-rack-0.9.6.jar +0 -0
- data/lib/jettr/jars/jsp-2.1.jar +0 -0
- data/lib/jettr/jars/jsp-api-2.1.jar +0 -0
- data/lib/jettr/jars/servlet-api-2.5-6.1.14.jar +0 -0
- data/lib/jettr/logger.rb +5 -0
- data/lib/jettr/server.rb +134 -0
- data/spec/.gitignore +0 -0
- data/tasks/jettr.thor +6 -0
- data/tasks/jeweler.rake +19 -0
- metadata +126 -0
data/.gitignore
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir['tasks/*.rake'].each {|t| import t }
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.1
|
data/bin/jettr
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
@jettr @server
|
2
|
+
Feature: Create simple server
|
3
|
+
|
4
|
+
As a developer
|
5
|
+
I want to easily create a simple Jetty server
|
6
|
+
So that I can easily deploy a simple http handler
|
7
|
+
|
8
|
+
|
9
|
+
Scenario: Create server with no arguments
|
10
|
+
Given "0" servers exist
|
11
|
+
When I create a server "without" "arguments"
|
12
|
+
Then the server should be "stopped"
|
13
|
+
And the server should be configured to run on port "8080"
|
14
|
+
And the server should have "0" handlers
|
15
|
+
|
16
|
+
Scenario: Add a handler
|
17
|
+
Given "0" servers exist
|
18
|
+
When I create a server "without" "arguments"
|
19
|
+
And I add a handler that responds with "handler running"
|
20
|
+
Then the server should have "1" handlers
|
21
|
+
|
22
|
+
Scenario: Start with a handler
|
23
|
+
Given "0" servers exist
|
24
|
+
When I create a server "without" "arguments"
|
25
|
+
And I add a handler that responds with "handler running"
|
26
|
+
And I "start" the server
|
27
|
+
Then the server should be "running"
|
28
|
+
And the handler should respond with "handler running" on port "8080"
|
29
|
+
|
30
|
+
Scenario: Port already in use
|
31
|
+
Given "0" servers exist
|
32
|
+
When I create a server "without" "arguments"
|
33
|
+
When I add a handler that responds with "handler running"
|
34
|
+
And port "8080" is already in use
|
35
|
+
Then "BindException" should be raised when I "start" the server
|
36
|
+
|
37
|
+
Scenario: Configure port
|
38
|
+
Given I create a server "with" ":port => 9090"
|
39
|
+
When I add a handler that responds with "handler running"
|
40
|
+
When I "start" the server
|
41
|
+
Then the server should be "running"
|
42
|
+
And the handler should respond with "handler running" on port "9090"
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'jettr'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'socket'
|
4
|
+
require 'jettr/handler/simple_handler'
|
5
|
+
|
6
|
+
Given /^"([^\"]*)" servers exist$/ do |arg1|
|
7
|
+
end
|
8
|
+
|
9
|
+
When /^I create a server "([^\"]*)" "([^\"]*)"$/ do |with_without, arguments|
|
10
|
+
has_arguments = with_without == "with" ? true : false
|
11
|
+
if has_arguments
|
12
|
+
@server = eval "Jettr::Server.new(#{arguments})"
|
13
|
+
else
|
14
|
+
@server = Jettr::Server.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
When /^I "([^\"]*)" the server$/ do |cmd|
|
19
|
+
@server.should respond_to cmd.to_sym
|
20
|
+
@server.send(cmd)
|
21
|
+
end
|
22
|
+
|
23
|
+
When /^port "([^\"]*)" is already in use$/ do |port|
|
24
|
+
@open_port = TCPServer.open(port.to_i)
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
When /^I add a handler that responds with "([^\"]*)"$/ do |response|
|
29
|
+
@server.handlers << Jettr::Handler::SimpleHandler.new(response)
|
30
|
+
end
|
31
|
+
|
32
|
+
Then /^the server should be "([^\"]*)"$/ do |status|
|
33
|
+
@server.should eval("be_#{status}")
|
34
|
+
end
|
35
|
+
|
36
|
+
Then /^the server should be configured to run on port "([^\"]*)"$/ do |port|
|
37
|
+
@server.config.port.should == port.to_i
|
38
|
+
end
|
39
|
+
|
40
|
+
Then /^the server should have "([^\"]*)" handlers$/ do |num|
|
41
|
+
@server.handlers.size.should == num.to_i
|
42
|
+
end
|
43
|
+
|
44
|
+
Then /^the handler should respond with "([^\"]*)" on port "([^\"]*)"$/ do |expected, port|
|
45
|
+
open("http://localhost:#{port}") do |resp|
|
46
|
+
resp.read.strip.should == expected
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
Then /^"([^\"]*)" should be raised when I "([^\"]*)" the server$/ do |exception_name, action|
|
51
|
+
@server.should respond_to(action)
|
52
|
+
lambda {
|
53
|
+
@server.send(action)
|
54
|
+
}.should raise_error
|
55
|
+
end
|
56
|
+
|
57
|
+
|
data/jettr.gemspec
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{jettr}
|
8
|
+
s.version = "0.2.1"
|
9
|
+
s.platform = %q{java}
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.authors = ["Ryan Heimbuch"]
|
13
|
+
s.date = %q{2010-02-09}
|
14
|
+
s.default_executable = %q{jettr}
|
15
|
+
s.email = %q{rheimbuch@gmail.com}
|
16
|
+
s.executables = ["jettr"]
|
17
|
+
s.files = [
|
18
|
+
".gitignore",
|
19
|
+
"Rakefile",
|
20
|
+
"VERSION",
|
21
|
+
"bin/jettr",
|
22
|
+
"features/jettr/create_simple_server.feature",
|
23
|
+
"features/jettr/step_definitions/create_server_steps.rb",
|
24
|
+
"features/jettr/support/hooks.rb",
|
25
|
+
"features/jettr/support/lib.rb",
|
26
|
+
"jettr.gemspec",
|
27
|
+
"lib/jettr.rb",
|
28
|
+
"lib/jettr/command.rb",
|
29
|
+
"lib/jettr/config.rb",
|
30
|
+
"lib/jettr/handler.rb",
|
31
|
+
"lib/jettr/handler/base.rb",
|
32
|
+
"lib/jettr/handler/rails.rb",
|
33
|
+
"lib/jettr/handler/simple_handler.rb",
|
34
|
+
"lib/jettr/handler/web_app.rb",
|
35
|
+
"lib/jettr/jars.rb",
|
36
|
+
"lib/jettr/jars/akuma-1.3-jar-with-dependencies.jar",
|
37
|
+
"lib/jettr/jars/core-3.1.1.jar",
|
38
|
+
"lib/jettr/jars/jettr-java.jar",
|
39
|
+
"lib/jettr/jars/jetty-6.1.14.jar",
|
40
|
+
"lib/jettr/jars/jetty-plus-6.1.14.jar",
|
41
|
+
"lib/jettr/jars/jetty-util-6.1.14.jar",
|
42
|
+
"lib/jettr/jars/jruby-rack-0.9.6.jar",
|
43
|
+
"lib/jettr/jars/jsp-2.1.jar",
|
44
|
+
"lib/jettr/jars/jsp-api-2.1.jar",
|
45
|
+
"lib/jettr/jars/servlet-api-2.5-6.1.14.jar",
|
46
|
+
"lib/jettr/logger.rb",
|
47
|
+
"lib/jettr/server.rb",
|
48
|
+
"spec/.gitignore",
|
49
|
+
"tasks/jettr.thor",
|
50
|
+
"tasks/jeweler.rake"
|
51
|
+
]
|
52
|
+
s.homepage = %q{http://github.com/rheimbuch/persvr}
|
53
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
54
|
+
s.require_paths = ["lib"]
|
55
|
+
s.rubygems_version = %q{1.3.5}
|
56
|
+
s.summary = %q{Use Jetty from JRuby.}
|
57
|
+
|
58
|
+
if s.respond_to? :specification_version then
|
59
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
60
|
+
s.specification_version = 3
|
61
|
+
|
62
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
63
|
+
s.add_runtime_dependency(%q<configatron>, [">= 1.5.1"])
|
64
|
+
s.add_runtime_dependency(%q<log4r>, [">= 1.1.4"])
|
65
|
+
s.add_runtime_dependency(%q<thor>, [">= 0"])
|
66
|
+
s.add_runtime_dependency(%q<activesupport>, ["~> 2.3.5"])
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<configatron>, [">= 1.5.1"])
|
69
|
+
s.add_dependency(%q<log4r>, [">= 1.1.4"])
|
70
|
+
s.add_dependency(%q<thor>, [">= 0"])
|
71
|
+
s.add_dependency(%q<activesupport>, ["~> 2.3.5"])
|
72
|
+
end
|
73
|
+
else
|
74
|
+
s.add_dependency(%q<configatron>, [">= 1.5.1"])
|
75
|
+
s.add_dependency(%q<log4r>, [">= 1.1.4"])
|
76
|
+
s.add_dependency(%q<thor>, [">= 0"])
|
77
|
+
s.add_dependency(%q<activesupport>, ["~> 2.3.5"])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
data/lib/jettr.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$:.unshift(File.expand_path(File.dirname(__FILE__))) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'java'
|
5
|
+
require 'active_support'
|
6
|
+
|
7
|
+
module Jettr
|
8
|
+
JETTR_HOME = File.expand_path(File.join(File.dirname(__FILE__), '..')) unless defined? JETTR_HOME
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'jettr/logger'
|
12
|
+
require 'jettr/jars'
|
13
|
+
require 'jettr/server'
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'jettr'
|
3
|
+
require 'jettr/config'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
module Jettr
|
7
|
+
class Command < Thor
|
8
|
+
|
9
|
+
desc "start [PATH] [--port=, --type=, --uri=]", "Start the webapp at PATH"
|
10
|
+
method_option :port, :type => :numeric, :default => 8080, :aliases => "-p"
|
11
|
+
method_option :type, :type => :string, :default => "webapp", :aliases => "-w"
|
12
|
+
method_option :uri, :type => :string, :default => "/", :aliases => "-u"
|
13
|
+
method_option :daemon, :type => :boolean, :default => false, :aliases => "-d"
|
14
|
+
method_option :pid, :type => :string
|
15
|
+
def start(path=".")
|
16
|
+
config = nil
|
17
|
+
config_file = File.join(path,"jettr.yaml")
|
18
|
+
if File.exist?(config_file)
|
19
|
+
config = Jettr::Config.new(:config_file => config_file)
|
20
|
+
else
|
21
|
+
config = Jettr::Config.new({
|
22
|
+
:server => {
|
23
|
+
:port => options[:port]
|
24
|
+
},
|
25
|
+
:apps => [
|
26
|
+
{
|
27
|
+
:type => options[:type],
|
28
|
+
:app_path => path,
|
29
|
+
:app_uri => options[:uri]
|
30
|
+
}
|
31
|
+
]
|
32
|
+
})
|
33
|
+
end
|
34
|
+
|
35
|
+
if(options[:daemon])
|
36
|
+
d = Jettr::Akuma::Daemon.new
|
37
|
+
pid_file = File.expand_path(options[:pid] || File.join(path,'tmp','run',"jettr.pid"))
|
38
|
+
if(d.daemonized?)
|
39
|
+
if File.exist?(pid_file)
|
40
|
+
puts "Pid file alread exists at: #{pid_file}"
|
41
|
+
puts "run `jettr stop #{pid_file}` to ensure the process has been stopped."
|
42
|
+
exit 1
|
43
|
+
end
|
44
|
+
FileUtils.mkdir_p File.dirname(pid_file)
|
45
|
+
puts "PID File: #{pid_file}"
|
46
|
+
d.init(pid_file)
|
47
|
+
else
|
48
|
+
d.daemonize()
|
49
|
+
exit 0
|
50
|
+
end
|
51
|
+
end
|
52
|
+
server = config.create_server
|
53
|
+
puts "Starting Server..."
|
54
|
+
server.start
|
55
|
+
end
|
56
|
+
|
57
|
+
desc "stop PATH_TO_APP_OR_PID", "Stops the daemonized jettr instance."
|
58
|
+
def stop(path='.')
|
59
|
+
pid_file = File.directory?(path) ? File.join(path, 'tmp','run','jettr.pid') : path
|
60
|
+
unless File.exist?(pid_file)
|
61
|
+
puts "Pid file not found: #{pid_file}"
|
62
|
+
exit 1
|
63
|
+
end
|
64
|
+
File.open(pid_file) do |file|
|
65
|
+
pid = file.read.strip.to_i
|
66
|
+
res = Process.kill("SIGINT", pid)
|
67
|
+
puts "Jettr process #{pid} was killed with response #{res}"
|
68
|
+
end
|
69
|
+
FileUtils.rm_rf pid_file
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/jettr/config.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'configatron'
|
2
|
+
require 'jettr/server'
|
3
|
+
require 'jettr/handler'
|
4
|
+
|
5
|
+
module Jettr
|
6
|
+
class Config
|
7
|
+
attr_reader :config
|
8
|
+
def initialize(options={})
|
9
|
+
@config = Configatron::Store.new
|
10
|
+
if options[:config_file] && File.exist?(options[:config_file])
|
11
|
+
config.configure_from_yaml(options[:config_file])
|
12
|
+
config.base_path = File.expand_path(File.dirname(options[:config_file]))
|
13
|
+
else
|
14
|
+
config.configure_from_hash(options)
|
15
|
+
end
|
16
|
+
config.server.set_default(:port, 8080)
|
17
|
+
config.set_default(:apps, [])
|
18
|
+
end
|
19
|
+
|
20
|
+
def store
|
21
|
+
return @config
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_server
|
25
|
+
puts "Creating server..."
|
26
|
+
server = Jettr::Server.new(config.server.to_hash)
|
27
|
+
config.apps.each do |app_config|
|
28
|
+
app_config.symbolize_keys!
|
29
|
+
if app_config[:app_path] && config.exists?(:base_path)
|
30
|
+
app_config[:app_path] = File.expand_path(File.join(config.base_path, app_config[:app_path]))
|
31
|
+
elsif app_config[:app_path]
|
32
|
+
app_config[:app_path] = File.expand_path(app_config[:app_path])
|
33
|
+
end
|
34
|
+
server.handlers << create_app(app_config)
|
35
|
+
puts "Added handler: #{server.handlers.last.inspect}"
|
36
|
+
end
|
37
|
+
server
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_app(app_config)
|
41
|
+
puts "Creating app handler: #{app_config.inspect}"
|
42
|
+
app_type = app_config.delete(:type)
|
43
|
+
app_type = app_type ? app_type.to_sym : app_type
|
44
|
+
handler_class = Jettr::Handler::HANDLERS[app_type] || Jettr::Handler::HANDLERS[:default]
|
45
|
+
handler_class.new(app_config)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Jettr
|
4
|
+
module Handler
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'jettr/handler/base'
|
9
|
+
require 'jettr/handler/web_app'
|
10
|
+
require 'jettr/handler/rails'
|
11
|
+
|
12
|
+
Jettr::Handler::HANDLERS = HashWithIndifferentAccess.new({
|
13
|
+
:default => Jettr::Handler::WebApp,
|
14
|
+
:webapp => Jettr::Handler::WebApp,
|
15
|
+
:rails => Jettr::Handler::Rails
|
16
|
+
})
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'jettr/handler/web_app'
|
2
|
+
|
3
|
+
module Jettr
|
4
|
+
module Handler
|
5
|
+
class Rails < Jettr::Handler::WebApp
|
6
|
+
def initialize(options={})
|
7
|
+
super(options)
|
8
|
+
config.rails.set_default(:root, '/')
|
9
|
+
config.rails.set_default(:public, '/public')
|
10
|
+
config.rails.set_default(:min_runtimes, 1)
|
11
|
+
config.rails.set_default(:max_runtimes, 3)
|
12
|
+
config.rails.set_default(:environment, "development")
|
13
|
+
|
14
|
+
|
15
|
+
self.add_filter("org.jruby.rack.RackFilter", "/*", org.mortbay.jetty.Handler::DEFAULT)
|
16
|
+
self.resource_base = "#{config.app_path}"
|
17
|
+
self.add_event_listener(Jettr::Rack::RailsServletContextListener.new)
|
18
|
+
rack_params = java.util.HashMap.new({
|
19
|
+
'rails.env' => config.rails.environment,
|
20
|
+
'rails.root' => config.rails.root,
|
21
|
+
'public.root' => config.rails.public,
|
22
|
+
'org.mortbay.jetty.servlet.Default.relativeResourceBase' => '/public',
|
23
|
+
'jruby.min.runtimes' => config.rails.min_runtimes.to_s,
|
24
|
+
'jruby.max.runtimes' => config.rails.max_runtimes.to_s,
|
25
|
+
'jruby.initial.runtimes' => config.rails.min_runtimes.to_s
|
26
|
+
})
|
27
|
+
self.set_init_params(rack_params)
|
28
|
+
self.add_servlet(Jetty::ServletHolder.new(Jetty::DefaultServlet.new), "/")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Jettr
|
2
|
+
module Handler
|
3
|
+
class SimpleHandler < Jettr::Handler::Base
|
4
|
+
def initialize(response)
|
5
|
+
super()
|
6
|
+
@response = response
|
7
|
+
end
|
8
|
+
|
9
|
+
def handle(target, request, response, dispatch)
|
10
|
+
puts "Handling request for: #{[target,request,response,dispatch].inspect}"
|
11
|
+
response.content_type = "text/html;charset=utf-8"
|
12
|
+
response.status = 200
|
13
|
+
|
14
|
+
response.get_writer.println(@response)
|
15
|
+
request.handled = true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'configatron'
|
2
|
+
module Jettr
|
3
|
+
module Handler
|
4
|
+
class WebApp < Jetty::Handler::WebAppContext
|
5
|
+
attr_reader :config
|
6
|
+
|
7
|
+
def initialize(options={})
|
8
|
+
super()
|
9
|
+
@config = Configatron::Store.new
|
10
|
+
config.configure_from_hash(options)
|
11
|
+
config.set_default(:app_path, ".")
|
12
|
+
config.set_default(:app_uri, "/")
|
13
|
+
self.context_path = config.app_uri
|
14
|
+
self.war = config.app_path
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/jettr/jars.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Jettr
|
2
|
+
require "jettr/jars/servlet-api-2.5-6.1.14"
|
3
|
+
require "jettr/jars/jetty-6.1.14"
|
4
|
+
require "jettr/jars/jetty-util-6.1.14"
|
5
|
+
require "jettr/jars/jetty-plus-6.1.14"
|
6
|
+
require "jettr/jars/core-3.1.1"
|
7
|
+
require "jettr/jars/jsp-api-2.1"
|
8
|
+
require "jettr/jars/jsp-2.1"
|
9
|
+
require "jettr/jars/jruby-rack-0.9.6"
|
10
|
+
require "jettr/jars/jettr-java"
|
11
|
+
require "jettr/jars/akuma-1.3-jar-with-dependencies.jar"
|
12
|
+
|
13
|
+
module Jetty
|
14
|
+
include_package "org.mortbay.jetty"
|
15
|
+
include_package "org.mortbay.jetty.servlet"
|
16
|
+
include_package "org.mortbay.jetty.nio"
|
17
|
+
include_package "org.mortbay.resource"
|
18
|
+
|
19
|
+
module Handler
|
20
|
+
include_package "org.mortbay.jetty.handler"
|
21
|
+
include_package "org.mortbay.jetty.webapp"
|
22
|
+
end
|
23
|
+
|
24
|
+
module Thread
|
25
|
+
include_package "org.mortbay.thread"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module Resource
|
30
|
+
include_class 'persvr.InheritingFileResource'
|
31
|
+
end
|
32
|
+
|
33
|
+
module Rack
|
34
|
+
include_package "org.jruby.rack"
|
35
|
+
include_package "org.jruby.rack.rails"
|
36
|
+
end
|
37
|
+
module Akuma
|
38
|
+
include_package "com.sun.akuma"
|
39
|
+
end
|
40
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/jettr/logger.rb
ADDED
data/lib/jettr/server.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'configatron'
|
2
|
+
require 'jettr/handler'
|
3
|
+
module Jettr
|
4
|
+
class Server
|
5
|
+
attr_reader :config, :handlers, :server
|
6
|
+
Logger.new self.name
|
7
|
+
|
8
|
+
include_class java.net.BindException
|
9
|
+
|
10
|
+
def initialize(options={})
|
11
|
+
@server = Jetty::Server.new
|
12
|
+
@handlers = HandlerCollectionProxy.for(@server)
|
13
|
+
configure(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def configure(options_or_file,opts={})
|
17
|
+
@config ||= Configatron::Store.new
|
18
|
+
@config.set_default(:name, "ObjectId:#{self.object_id}")
|
19
|
+
@config.set_default(:port, 8080)
|
20
|
+
@config.set_default(:acceptors, 5)
|
21
|
+
@config.thread_pool.set_default(:max, 20)
|
22
|
+
@config.thread_pool.set_default(:min, 1)
|
23
|
+
@config.shutdown.set_default(:graceful, false)
|
24
|
+
@config.shutdown.set_default(:graceful_timeout, 500)
|
25
|
+
case options_or_file
|
26
|
+
when String then @config.configure_from_yaml(options_or_file,opts)
|
27
|
+
when Hash then @config.configure_from_hash(options_or_file)
|
28
|
+
end
|
29
|
+
|
30
|
+
configure_jetty
|
31
|
+
end
|
32
|
+
|
33
|
+
def start
|
34
|
+
begin
|
35
|
+
if stopped?
|
36
|
+
logger.info "Starting server..."
|
37
|
+
@server.start
|
38
|
+
end
|
39
|
+
rescue BindException => ex
|
40
|
+
stop
|
41
|
+
raise ex
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def stop
|
46
|
+
if running? || failed?
|
47
|
+
logger.info "Stopping server..."
|
48
|
+
@server.stop
|
49
|
+
else
|
50
|
+
logger.debug "#stop: Server already stopped."
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def restart
|
55
|
+
logger.info "Restarting server..."
|
56
|
+
stop
|
57
|
+
until stopped?
|
58
|
+
logger.debug "#restart: waiting for server to stop..."
|
59
|
+
sleep 0.2
|
60
|
+
end
|
61
|
+
start
|
62
|
+
end
|
63
|
+
|
64
|
+
def destroy
|
65
|
+
@server.stop unless stopped?
|
66
|
+
@server.destroy()
|
67
|
+
@destroyed = true
|
68
|
+
end
|
69
|
+
|
70
|
+
def running?
|
71
|
+
@server.isRunning
|
72
|
+
end
|
73
|
+
|
74
|
+
def stopped?
|
75
|
+
@server.isStopped
|
76
|
+
end
|
77
|
+
|
78
|
+
def failed?
|
79
|
+
@server.isFailed
|
80
|
+
end
|
81
|
+
|
82
|
+
def destroyed?
|
83
|
+
@destroyed ||=false
|
84
|
+
end
|
85
|
+
|
86
|
+
def join
|
87
|
+
logger.debug "Joining server thread..."
|
88
|
+
@server.join
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
def configure_jetty
|
93
|
+
thread_pool = Jetty::Thread::QueuedThreadPool.new
|
94
|
+
thread_pool.set_max_threads(config.thread_pool.max)
|
95
|
+
thread_pool.set_min_threads(config.thread_pool.min)
|
96
|
+
@server.set_thread_pool(thread_pool)
|
97
|
+
|
98
|
+
connector = Jetty::SelectChannelConnector.new
|
99
|
+
connector.set_acceptors(config.acceptors)
|
100
|
+
connector.port = config.port
|
101
|
+
@server.add_connector(connector)
|
102
|
+
|
103
|
+
@server.stop_at_shutdown = config.shutdown.graceful
|
104
|
+
@server.graceful_shutdown = config.shutdown.graceful_timeout
|
105
|
+
end
|
106
|
+
|
107
|
+
def logger
|
108
|
+
@logger ||= Logger.new("#{self.class.name}::#{config.name}")
|
109
|
+
end
|
110
|
+
|
111
|
+
class HandlerCollectionProxy
|
112
|
+
def initialize(server)
|
113
|
+
@server = server
|
114
|
+
@handlers = []
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.for(server)
|
118
|
+
self.new(server)
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
def method_missing(method, *args, &block)
|
123
|
+
handlers_orig = @handlers.clone
|
124
|
+
res = @handlers.send(method, *args, &block)
|
125
|
+
if @handlers != handlers_orig
|
126
|
+
@handlers.flatten! # Ensure the mutation operation didn't introduce nesting.
|
127
|
+
@server.set_handlers(@handlers.to_java(Jettr::Handler::Base))
|
128
|
+
end
|
129
|
+
return res
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
data/spec/.gitignore
ADDED
File without changes
|
data/tasks/jettr.thor
ADDED
data/tasks/jeweler.rake
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gem|
|
4
|
+
gem.name = "jettr"
|
5
|
+
gem.summary = "Use Jetty from JRuby."
|
6
|
+
gem.email = "rheimbuch@gmail.com"
|
7
|
+
gem.homepage = "http://github.com/rheimbuch/persvr"
|
8
|
+
gem.authors = ["Ryan Heimbuch"]
|
9
|
+
|
10
|
+
gem.platform = 'java'
|
11
|
+
|
12
|
+
gem.add_dependency 'configatron', ">=1.5.1"
|
13
|
+
gem.add_dependency 'log4r', '>=1.1.4'
|
14
|
+
gem.add_dependency 'thor'
|
15
|
+
gem.add_dependency 'activesupport', "~>2.3.5"
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler no available. Install with: gem install jeweler"
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jettr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- Ryan Heimbuch
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-02-09 00:00:00 -07:00
|
13
|
+
default_executable: jettr
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: configatron
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.5.1
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: log4r
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.1.4
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: thor
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: activesupport
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.3.5
|
54
|
+
version:
|
55
|
+
description:
|
56
|
+
email: rheimbuch@gmail.com
|
57
|
+
executables:
|
58
|
+
- jettr
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files: []
|
62
|
+
|
63
|
+
files:
|
64
|
+
- .gitignore
|
65
|
+
- Rakefile
|
66
|
+
- VERSION
|
67
|
+
- bin/jettr
|
68
|
+
- features/jettr/create_simple_server.feature
|
69
|
+
- features/jettr/step_definitions/create_server_steps.rb
|
70
|
+
- features/jettr/support/hooks.rb
|
71
|
+
- features/jettr/support/lib.rb
|
72
|
+
- jettr.gemspec
|
73
|
+
- lib/jettr.rb
|
74
|
+
- lib/jettr/command.rb
|
75
|
+
- lib/jettr/config.rb
|
76
|
+
- lib/jettr/handler.rb
|
77
|
+
- lib/jettr/handler/base.rb
|
78
|
+
- lib/jettr/handler/rails.rb
|
79
|
+
- lib/jettr/handler/simple_handler.rb
|
80
|
+
- lib/jettr/handler/web_app.rb
|
81
|
+
- lib/jettr/jars.rb
|
82
|
+
- lib/jettr/jars/akuma-1.3-jar-with-dependencies.jar
|
83
|
+
- lib/jettr/jars/core-3.1.1.jar
|
84
|
+
- lib/jettr/jars/jettr-java.jar
|
85
|
+
- lib/jettr/jars/jetty-6.1.14.jar
|
86
|
+
- lib/jettr/jars/jetty-plus-6.1.14.jar
|
87
|
+
- lib/jettr/jars/jetty-util-6.1.14.jar
|
88
|
+
- lib/jettr/jars/jruby-rack-0.9.6.jar
|
89
|
+
- lib/jettr/jars/jsp-2.1.jar
|
90
|
+
- lib/jettr/jars/jsp-api-2.1.jar
|
91
|
+
- lib/jettr/jars/servlet-api-2.5-6.1.14.jar
|
92
|
+
- lib/jettr/logger.rb
|
93
|
+
- lib/jettr/server.rb
|
94
|
+
- spec/.gitignore
|
95
|
+
- tasks/jettr.thor
|
96
|
+
- tasks/jeweler.rake
|
97
|
+
has_rdoc: true
|
98
|
+
homepage: http://github.com/rheimbuch/persvr
|
99
|
+
licenses: []
|
100
|
+
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options:
|
103
|
+
- --charset=UTF-8
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: "0"
|
111
|
+
version:
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: "0"
|
117
|
+
version:
|
118
|
+
requirements: []
|
119
|
+
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 1.3.5
|
122
|
+
signing_key:
|
123
|
+
specification_version: 3
|
124
|
+
summary: Use Jetty from JRuby.
|
125
|
+
test_files: []
|
126
|
+
|