kirk 0.1.7-java → 0.1.8-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/client.rb +21 -1
- data/lib/kirk/client/connection.rb +18 -0
- data/lib/kirk/client/exchange.rb +33 -0
- data/lib/kirk/client/request.rb +12 -0
- data/lib/kirk/client/response.rb +10 -0
- data/lib/kirk/client/session.rb +40 -0
- data/lib/kirk/input_stream.rb +1 -1
- data/lib/kirk/version.rb +1 -1
- metadata +8 -3
data/lib/kirk/client.rb
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
module Kirk
|
2
2
|
class Client
|
3
|
-
|
3
|
+
import org.eclipse.jetty.client.HttpClient
|
4
|
+
import org.eclipse.jetty.client.HttpExchange
|
5
|
+
import java.net.InetSocketAddress
|
6
|
+
import java.util.concurrent.LinkedBlockingQueue
|
7
|
+
import org.eclipse.jetty.client.ContentExchange
|
8
|
+
import java.util.concurrent.AbstractExecutorService
|
9
|
+
import java.util.concurrent.TimeUnit
|
10
|
+
import java.util.concurrent.ThreadPoolExecutor
|
11
|
+
import java.util.concurrent.ExecutorCompletionService
|
12
|
+
|
13
|
+
def self.session
|
14
|
+
Session.new(&Proc.new)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
4
18
|
end
|
5
19
|
end
|
20
|
+
|
21
|
+
require 'kirk/client/session'
|
22
|
+
require 'kirk/client/response'
|
23
|
+
require 'kirk/client/request'
|
24
|
+
require 'kirk/client/connection'
|
25
|
+
require 'kirk/client/exchange'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Kirk::Client
|
2
|
+
class Connection
|
3
|
+
attr_reader :request
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@request = nil
|
7
|
+
@writing = false
|
8
|
+
@client = HttpClient.new
|
9
|
+
@client.set_connector_type(HttpClient::CONNECTOR_SELECT_CHANNEL);
|
10
|
+
@client.start
|
11
|
+
end
|
12
|
+
|
13
|
+
def process(request)
|
14
|
+
exchange = Exchange.from_request(request)
|
15
|
+
@client.send(exchange)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Kirk::Client
|
2
|
+
class Exchange < ContentExchange
|
3
|
+
include java.util.concurrent.Callable
|
4
|
+
|
5
|
+
def initialize(session, handler)
|
6
|
+
@handler = handler
|
7
|
+
@session = session
|
8
|
+
super()
|
9
|
+
end
|
10
|
+
|
11
|
+
def onException(ex)
|
12
|
+
puts ex.inspect
|
13
|
+
end
|
14
|
+
|
15
|
+
def onResponseComplete
|
16
|
+
@session.queue.offer(response)
|
17
|
+
@handler.on_response_complete(response) if @handler
|
18
|
+
end
|
19
|
+
|
20
|
+
def response
|
21
|
+
@response = begin
|
22
|
+
Response.new(get_response_content, get_response_status)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.from_request(request)
|
27
|
+
exchange = new(request.session, request.handler)
|
28
|
+
exchange.set_method(request.method)
|
29
|
+
exchange.set_url(request.url)
|
30
|
+
exchange
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class Kirk::Client
|
2
|
+
class Session
|
3
|
+
|
4
|
+
attr_reader :responses, :queue
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@queue = LinkedBlockingQueue.new
|
8
|
+
@executor = ThreadPoolExecutor.new(thread_count, thread_count, 0, TimeUnit::SECONDS, @queue)
|
9
|
+
@connection = Connection.new
|
10
|
+
@requests_count = 0
|
11
|
+
@responses = []
|
12
|
+
yield(self)
|
13
|
+
|
14
|
+
get_responses
|
15
|
+
end
|
16
|
+
|
17
|
+
def request(method, url, handler = nil, headers = nil)
|
18
|
+
request = Request.new(self, method, url, handler, headers)
|
19
|
+
yield request if block_given?
|
20
|
+
queue_request(request)
|
21
|
+
request
|
22
|
+
end
|
23
|
+
|
24
|
+
def thread_count
|
25
|
+
3
|
26
|
+
end
|
27
|
+
|
28
|
+
def queue_request(request)
|
29
|
+
@connection.process(request)
|
30
|
+
@requests_count += 1
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_responses
|
34
|
+
while @requests_count > 0
|
35
|
+
@responses << @queue.take
|
36
|
+
@requests_count -= 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/kirk/input_stream.rb
CHANGED
@@ -135,7 +135,7 @@ module Kirk
|
|
135
135
|
|
136
136
|
# Set the new buffer limit to the amount that is going
|
137
137
|
# to be read
|
138
|
-
@buffer.
|
138
|
+
@buffer.limit(@read + missing).position(@read)
|
139
139
|
|
140
140
|
# Read into the buffer
|
141
141
|
len = @io.read(@buffer)
|
data/lib/kirk/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: kirk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.8
|
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-17 00:00:00 -08:00
|
14
14
|
default_executable: kirk
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -43,6 +43,11 @@ files:
|
|
43
43
|
- lib/kirk/applications/hot_deployable.rb
|
44
44
|
- lib/kirk/applications/rack.rb
|
45
45
|
- lib/kirk/applications/redeploy_client.rb
|
46
|
+
- lib/kirk/client/connection.rb
|
47
|
+
- lib/kirk/client/exchange.rb
|
48
|
+
- lib/kirk/client/request.rb
|
49
|
+
- lib/kirk/client/response.rb
|
50
|
+
- lib/kirk/client/session.rb
|
46
51
|
- lib/rack/handler/kirk.rb
|
47
52
|
- lib/kirk/native.jar
|
48
53
|
- lib/kirk/jetty/jetty-client-7.2.2.v20101205.jar
|
@@ -75,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
80
|
requirements: []
|
76
81
|
|
77
82
|
rubyforge_project: kirk
|
78
|
-
rubygems_version: 1.5.
|
83
|
+
rubygems_version: 1.5.1
|
79
84
|
signing_key:
|
80
85
|
specification_version: 3
|
81
86
|
summary: A JRuby Rack Server Based on Jetty
|