kirk 0.1.8-java → 0.2.0.beta.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/kirk.rb +24 -26
- data/lib/kirk/cli.rb +1 -1
- data/lib/kirk/client.rb +57 -18
- data/lib/kirk/client/exchange.rb +146 -26
- data/lib/kirk/client/group.rb +94 -0
- data/lib/kirk/client/request.rb +42 -6
- data/lib/kirk/client/response.rb +20 -4
- data/lib/kirk/jetty.rb +22 -14
- data/lib/kirk/jetty/{jetty-client-7.2.2.v20101205.jar → jetty-client-7.3.0.v20110203.jar} +0 -0
- data/lib/kirk/jetty/jetty-continuation-7.3.0.v20110203.jar +0 -0
- data/lib/kirk/jetty/jetty-http-7.3.0.v20110203.jar +0 -0
- data/lib/kirk/jetty/jetty-io-7.3.0.v20110203.jar +0 -0
- data/lib/kirk/jetty/jetty-server-7.3.0.v20110203.jar +0 -0
- data/lib/kirk/jetty/jetty-util-7.3.0.v20110203.jar +0 -0
- data/lib/kirk/native.jar +0 -0
- data/lib/kirk/native.rb +12 -0
- data/lib/kirk/server.rb +11 -1
- data/lib/kirk/server/application_config.rb +56 -0
- data/lib/kirk/server/bootstrap.rb +59 -0
- data/lib/kirk/server/builder.rb +145 -0
- data/lib/kirk/{applications → server}/deploy_watcher.rb +1 -1
- data/lib/kirk/server/handler.rb +140 -0
- data/lib/kirk/server/hot_deployable.rb +63 -0
- data/lib/kirk/server/input_stream.rb +114 -0
- data/lib/kirk/{applications → server}/redeploy_client.rb +1 -1
- data/lib/kirk/version.rb +1 -1
- metadata +19 -16
- data/lib/kirk/applications/config.rb +0 -50
- data/lib/kirk/applications/hot_deployable.rb +0 -65
- data/lib/kirk/applications/rack.rb +0 -21
- data/lib/kirk/bootstrap.rb +0 -59
- data/lib/kirk/builder.rb +0 -143
- data/lib/kirk/client/connection.rb +0 -18
- data/lib/kirk/client/session.rb +0 -40
- data/lib/kirk/handler.rb +0 -129
- data/lib/kirk/input_stream.rb +0 -264
- data/lib/kirk/jetty/jetty-server-7.2.2.v20101205.jar +0 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
|
3
|
+
module Kirk
|
4
|
+
# This class extends a native Java class
|
5
|
+
class Server::HotDeployable < Native::HotDeployableApplication
|
6
|
+
|
7
|
+
def initialize(config)
|
8
|
+
super(config)
|
9
|
+
deploy
|
10
|
+
end
|
11
|
+
|
12
|
+
def key
|
13
|
+
gemfile = "#{application_path}/Gemfile"
|
14
|
+
lockfile = "#{application_path}/Gemfile.lock"
|
15
|
+
|
16
|
+
if File.exist?(gemfile) && File.exist?(lockfile)
|
17
|
+
str = File.read(gemfile) + File.read(lockfile)
|
18
|
+
Digest::SHA1.hexdigest(str)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_watcher(watcher)
|
23
|
+
add_life_cycle_listener(watcher)
|
24
|
+
end
|
25
|
+
|
26
|
+
def application_path
|
27
|
+
config.application_path
|
28
|
+
end
|
29
|
+
|
30
|
+
def rackup_path
|
31
|
+
config.rackup
|
32
|
+
end
|
33
|
+
|
34
|
+
def last_modified
|
35
|
+
mtimes = config.watch.map do |path|
|
36
|
+
path = File.expand_path(path, application_path)
|
37
|
+
File.exist?(path) ? File.mtime(path).to_i : 0
|
38
|
+
end
|
39
|
+
|
40
|
+
mtimes.max
|
41
|
+
end
|
42
|
+
|
43
|
+
def deploy(deploy = nil)
|
44
|
+
deploy ||= build_deploy
|
45
|
+
|
46
|
+
if deploy
|
47
|
+
deploy.prepare
|
48
|
+
super(deploy)
|
49
|
+
true
|
50
|
+
end
|
51
|
+
rescue Exception => e
|
52
|
+
Kirk.logger.warning "Deploying `#{application_path}` failed: #{e.message}"
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
|
56
|
+
def build_deploy
|
57
|
+
super
|
58
|
+
rescue Exception => e
|
59
|
+
Kirk.logger.warning "Warming up `#{application_path}` failed: #{e.message}"
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module Kirk
|
2
|
+
class Server
|
3
|
+
class InputStream
|
4
|
+
Native # Trigger the autoload
|
5
|
+
READL_SIZE = 1_024
|
6
|
+
CHUNK_SIZE = 8_192
|
7
|
+
BUFFER_SIZE = 1_024 * 50
|
8
|
+
BUFFER_POOL = LinkedBlockingQueue.new
|
9
|
+
|
10
|
+
def initialize(io)
|
11
|
+
@io, @buffer = init_rewindable_input(io)
|
12
|
+
end
|
13
|
+
|
14
|
+
def read(size = nil, buffer = nil)
|
15
|
+
one_loop = nil
|
16
|
+
read_all = size.nil?
|
17
|
+
|
18
|
+
buffer ? buffer.slice!(0..-1) : buffer = ''
|
19
|
+
|
20
|
+
raise ArgumentError, "negative length #{size} given" if size && size < 0
|
21
|
+
|
22
|
+
loop do
|
23
|
+
limit = size && size < CHUNK_SIZE ? size : CHUNK_SIZE
|
24
|
+
data = @io.read(limit)
|
25
|
+
|
26
|
+
break unless data
|
27
|
+
|
28
|
+
one_loop = true
|
29
|
+
|
30
|
+
buffer << String.from_java_bytes(data)
|
31
|
+
|
32
|
+
break if size && ( size -= data.length ) <= 0
|
33
|
+
end
|
34
|
+
|
35
|
+
return "" if read_all && !one_loop
|
36
|
+
|
37
|
+
one_loop && buffer
|
38
|
+
end
|
39
|
+
|
40
|
+
def gets(sep = $/)
|
41
|
+
return read unless sep
|
42
|
+
|
43
|
+
sep = "#{$/}#{$/}" if sep == ""
|
44
|
+
buffer = ''
|
45
|
+
curpos = pos
|
46
|
+
|
47
|
+
while chunk = read(READL_SIZE)
|
48
|
+
buffer << chunk
|
49
|
+
|
50
|
+
if i = buffer.index(sep, 0)
|
51
|
+
i += sep.bytesize
|
52
|
+
buffer.slice!(i..-1)
|
53
|
+
seek(curpos + buffer.bytesize)
|
54
|
+
break
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
buffer
|
59
|
+
end
|
60
|
+
|
61
|
+
def each
|
62
|
+
while chunk = read(CHUNK_SIZE)
|
63
|
+
yield chunk
|
64
|
+
end
|
65
|
+
|
66
|
+
self
|
67
|
+
end
|
68
|
+
|
69
|
+
def pos
|
70
|
+
@io.position
|
71
|
+
end
|
72
|
+
|
73
|
+
def seek(pos)
|
74
|
+
raise Errno::EINVAL, "Invalid argument - invalid seek value" if pos < 0
|
75
|
+
@io.seek(pos)
|
76
|
+
end
|
77
|
+
|
78
|
+
def rewind
|
79
|
+
@io.rewind
|
80
|
+
end
|
81
|
+
|
82
|
+
def close
|
83
|
+
@io.close
|
84
|
+
end
|
85
|
+
|
86
|
+
def recycle
|
87
|
+
@io.close
|
88
|
+
|
89
|
+
BUFFER_POOL.put(@buffer)
|
90
|
+
|
91
|
+
@buffer, @io = nil, nil
|
92
|
+
end
|
93
|
+
|
94
|
+
def to_inputstream
|
95
|
+
@io
|
96
|
+
end
|
97
|
+
|
98
|
+
def to_raw_inputstream
|
99
|
+
@io.unbuffered_input_stream
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def grab_buffer
|
105
|
+
BUFFER_POOL.poll || ByteBuffer.allocate(BUFFER_SIZE)
|
106
|
+
end
|
107
|
+
|
108
|
+
def init_rewindable_input(io)
|
109
|
+
buf = grab_buffer
|
110
|
+
[ Native::RewindableInputStream.new(io, buf), buf ]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/lib/kirk/version.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kirk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version: 0.1
|
4
|
+
prerelease: 6
|
5
|
+
version: 0.2.0.beta.1
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Carl Lerche
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-23 00:00:00 -08:00
|
14
14
|
default_executable: kirk
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -29,29 +29,32 @@ extra_rdoc_files: []
|
|
29
29
|
|
30
30
|
files:
|
31
31
|
- lib/kirk.rb
|
32
|
-
- lib/kirk/bootstrap.rb
|
33
|
-
- lib/kirk/builder.rb
|
34
32
|
- lib/kirk/cli.rb
|
35
33
|
- lib/kirk/client.rb
|
36
|
-
- lib/kirk/handler.rb
|
37
|
-
- lib/kirk/input_stream.rb
|
38
34
|
- lib/kirk/jetty.rb
|
35
|
+
- lib/kirk/native.rb
|
39
36
|
- lib/kirk/server.rb
|
40
37
|
- lib/kirk/version.rb
|
41
|
-
- lib/kirk/applications/config.rb
|
42
|
-
- lib/kirk/applications/deploy_watcher.rb
|
43
|
-
- lib/kirk/applications/hot_deployable.rb
|
44
|
-
- lib/kirk/applications/rack.rb
|
45
|
-
- lib/kirk/applications/redeploy_client.rb
|
46
|
-
- lib/kirk/client/connection.rb
|
47
38
|
- lib/kirk/client/exchange.rb
|
39
|
+
- lib/kirk/client/group.rb
|
48
40
|
- lib/kirk/client/request.rb
|
49
41
|
- lib/kirk/client/response.rb
|
50
|
-
- lib/kirk/
|
42
|
+
- lib/kirk/server/application_config.rb
|
43
|
+
- lib/kirk/server/bootstrap.rb
|
44
|
+
- lib/kirk/server/builder.rb
|
45
|
+
- lib/kirk/server/deploy_watcher.rb
|
46
|
+
- lib/kirk/server/handler.rb
|
47
|
+
- lib/kirk/server/hot_deployable.rb
|
48
|
+
- lib/kirk/server/input_stream.rb
|
49
|
+
- lib/kirk/server/redeploy_client.rb
|
51
50
|
- lib/rack/handler/kirk.rb
|
52
51
|
- lib/kirk/native.jar
|
53
|
-
- lib/kirk/jetty/jetty-client-7.
|
54
|
-
- lib/kirk/jetty/jetty-
|
52
|
+
- lib/kirk/jetty/jetty-client-7.3.0.v20110203.jar
|
53
|
+
- lib/kirk/jetty/jetty-continuation-7.3.0.v20110203.jar
|
54
|
+
- lib/kirk/jetty/jetty-http-7.3.0.v20110203.jar
|
55
|
+
- lib/kirk/jetty/jetty-io-7.3.0.v20110203.jar
|
56
|
+
- lib/kirk/jetty/jetty-server-7.3.0.v20110203.jar
|
57
|
+
- lib/kirk/jetty/jetty-util-7.3.0.v20110203.jar
|
55
58
|
- lib/kirk/jetty/servlet-api-2.5.jar
|
56
59
|
- bin/kirk
|
57
60
|
- README.md
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module Kirk
|
2
|
-
module Applications
|
3
|
-
class Config
|
4
|
-
include Native::ApplicationConfig
|
5
|
-
|
6
|
-
attr_accessor :env,
|
7
|
-
:hosts,
|
8
|
-
:listen,
|
9
|
-
:watch,
|
10
|
-
:rackup,
|
11
|
-
:application_path,
|
12
|
-
:bootstrap_path
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
@env = {}
|
16
|
-
@hosts = []
|
17
|
-
@listen = listen
|
18
|
-
end
|
19
|
-
|
20
|
-
def application_path
|
21
|
-
@application_path || File.dirname(rackup)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Handle the java interface
|
25
|
-
alias getApplicationPath application_path
|
26
|
-
alias getRackupPath rackup
|
27
|
-
alias getBootstrapPath bootstrap_path
|
28
|
-
|
29
|
-
def getEnvironment
|
30
|
-
map = java.util.HashMap.new
|
31
|
-
env = ENV.dup
|
32
|
-
|
33
|
-
self.env.each do |key, val|
|
34
|
-
env[key.to_s] = val
|
35
|
-
end
|
36
|
-
|
37
|
-
env.each do |key, val|
|
38
|
-
next unless val
|
39
|
-
|
40
|
-
key = key.to_java_string
|
41
|
-
val = val.to_s.to_java_string
|
42
|
-
|
43
|
-
map.put(key, val)
|
44
|
-
end
|
45
|
-
|
46
|
-
map
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'digest/sha1'
|
2
|
-
|
3
|
-
module Kirk
|
4
|
-
module Applications
|
5
|
-
# This class extends a native Java class
|
6
|
-
class HotDeployable < Native::HotDeployableApplication
|
7
|
-
|
8
|
-
def initialize(config)
|
9
|
-
super(config)
|
10
|
-
deploy
|
11
|
-
end
|
12
|
-
|
13
|
-
def key
|
14
|
-
gemfile = "#{application_path}/Gemfile"
|
15
|
-
lockfile = "#{application_path}/Gemfile.lock"
|
16
|
-
|
17
|
-
if File.exist?(gemfile) && File.exist?(lockfile)
|
18
|
-
str = File.read(gemfile) + File.read(lockfile)
|
19
|
-
Digest::SHA1.hexdigest(str)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def add_watcher(watcher)
|
24
|
-
add_life_cycle_listener(watcher)
|
25
|
-
end
|
26
|
-
|
27
|
-
def application_path
|
28
|
-
config.application_path
|
29
|
-
end
|
30
|
-
|
31
|
-
def rackup_path
|
32
|
-
config.rackup
|
33
|
-
end
|
34
|
-
|
35
|
-
def last_modified
|
36
|
-
mtimes = config.watch.map do |path|
|
37
|
-
path = File.expand_path(path, application_path)
|
38
|
-
File.exist?(path) ? File.mtime(path).to_i : 0
|
39
|
-
end
|
40
|
-
|
41
|
-
mtimes.max
|
42
|
-
end
|
43
|
-
|
44
|
-
def deploy(deploy = nil)
|
45
|
-
deploy ||= build_deploy
|
46
|
-
|
47
|
-
if deploy
|
48
|
-
deploy.prepare
|
49
|
-
super(deploy)
|
50
|
-
true
|
51
|
-
end
|
52
|
-
rescue Exception => e
|
53
|
-
Kirk.logger.warning "Deploying `#{application_path}` failed: #{e.message}"
|
54
|
-
nil
|
55
|
-
end
|
56
|
-
|
57
|
-
def build_deploy
|
58
|
-
super
|
59
|
-
rescue Exception => e
|
60
|
-
Kirk.logger.warning "Warming up `#{application_path}` failed: #{e.message}"
|
61
|
-
nil
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
gem "rack", ">= 1.0.0"
|
2
|
-
require "rack"
|
3
|
-
|
4
|
-
module Kirk
|
5
|
-
module Applications
|
6
|
-
# This class extends a native Java class
|
7
|
-
class Rack < Jetty::AbstractHandler
|
8
|
-
def self.new(app)
|
9
|
-
inst = super()
|
10
|
-
inst.app = Handler.new(app)
|
11
|
-
inst
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_accessor :app
|
15
|
-
|
16
|
-
def handle(target, base_request, request, response)
|
17
|
-
app.handle(target, base_request, request, response)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/kirk/bootstrap.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'java'
|
2
|
-
|
3
|
-
module Kirk
|
4
|
-
class Bootstrap
|
5
|
-
def warmup(application_path)
|
6
|
-
Dir.chdir File.expand_path(application_path)
|
7
|
-
|
8
|
-
load_rubygems
|
9
|
-
|
10
|
-
load_bundle.tap do
|
11
|
-
add_kirk_to_load_path
|
12
|
-
|
13
|
-
load_rack
|
14
|
-
load_kirk
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def run(rackup)
|
19
|
-
app, options = Rack::Builder.parse_file(rackup)
|
20
|
-
|
21
|
-
Kirk::Handler.new(app)
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def load_rubygems
|
27
|
-
require 'rubygems'
|
28
|
-
end
|
29
|
-
|
30
|
-
def load_bundle
|
31
|
-
if File.exist?('Gemfile')
|
32
|
-
require 'bundler/setup'
|
33
|
-
|
34
|
-
if File.exist?('Gemfile.lock')
|
35
|
-
require 'digest/sha1'
|
36
|
-
str = File.read('Gemfile') + File.read('Gemfile.lock')
|
37
|
-
Digest::SHA1.hexdigest(str)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def add_kirk_to_load_path
|
43
|
-
$:.unshift File.expand_path('../..', __FILE__)
|
44
|
-
end
|
45
|
-
|
46
|
-
def load_rack
|
47
|
-
gem "rack", ">= 1.0.0"
|
48
|
-
require 'rack'
|
49
|
-
end
|
50
|
-
|
51
|
-
def load_kirk
|
52
|
-
require 'kirk/version'
|
53
|
-
require 'kirk/input_stream'
|
54
|
-
require 'kirk/handler'
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
Kirk::Bootstrap.new
|