ione-rpc 1.0.0 → 1.0.1
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.
- checksums.yaml +4 -4
- data/README.md +9 -4
- data/lib/ione/rpc/client.rb +6 -2
- data/lib/ione/rpc/client_peer.rb +11 -7
- data/lib/ione/rpc/codec.rb +2 -2
- data/lib/ione/rpc/version.rb +1 -1
- data/spec/ione/rpc/client_peer_spec.rb +10 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd2dfbaf504cd8f90db14054c3f1be44a1bf6740
|
4
|
+
data.tar.gz: 4ecca4c71c9d9857c4df03a0caaecf52fb56a973
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 005b40b386819c5f9ce87398b6456981b996d7d9a82f03aa13db17f64a18db4de9117474261b7a1c7a2cf30117542db425c00165d8a5f99272441f5413ce5c5a
|
7
|
+
data.tar.gz: 336273d46b03c7cbcd15f59b2c9f3b46ce8da3de9169b583bbb9f867238af9eff73f4dc9cca227f93aa38409ed5342e1c2dd7a413cc05f37937fa712770b6cc8
|
data/README.md
CHANGED
@@ -10,11 +10,16 @@ Ione RPC is a framework for writing server and client components for your Ruby a
|
|
10
10
|
|
11
11
|
# Installing
|
12
12
|
|
13
|
-
|
13
|
+
Ione RPC is available from [Rubygems](https://rubygems.org) and can be installed with the `gem` command:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ gem install ione-rpc
|
17
|
+
```
|
18
|
+
|
19
|
+
but more commonly you will add it to your `Gemfile`:
|
14
20
|
|
15
21
|
```ruby
|
16
|
-
|
17
|
-
gem 'ione-rpc', github: 'iconara/ione-rpc'
|
22
|
+
gem 'ione-rpc'
|
18
23
|
```
|
19
24
|
|
20
25
|
# Example
|
@@ -140,7 +145,7 @@ class TranslationClient < Ione::Rpc::Client
|
|
140
145
|
end
|
141
146
|
```
|
142
147
|
|
143
|
-
If you read the part above about how the client randomly selected which server to talk to and
|
148
|
+
If you read the part above about how the client randomly selected which server to talk to and thought that that wasn't very useful, there's a way to override that, just implement `#choose_connection`:
|
144
149
|
|
145
150
|
```ruby
|
146
151
|
class TranslationClient < Ione::Rpc::Client
|
data/lib/ione/rpc/client.rb
CHANGED
@@ -141,15 +141,19 @@ module Ione
|
|
141
141
|
# client (immediately, this is mostly to be consistent with #add_host)
|
142
142
|
def remove_host(hostname, port=nil)
|
143
143
|
hostname, port = normalize_address(hostname, port)
|
144
|
+
connection = nil
|
144
145
|
@lock.synchronize do
|
145
146
|
index = @hosts.index { |h, p, _| h == hostname && p == port }
|
146
147
|
if index
|
147
148
|
@hosts.delete_at(index)
|
148
|
-
if (
|
149
|
-
connection
|
149
|
+
if (conn = @connections.find { |c| c.host == hostname && c.port == port })
|
150
|
+
connection = conn
|
150
151
|
end
|
151
152
|
end
|
152
153
|
end
|
154
|
+
if connection
|
155
|
+
connection.close
|
156
|
+
end
|
153
157
|
Future.resolved(self)
|
154
158
|
end
|
155
159
|
|
data/lib/ione/rpc/client_peer.rb
CHANGED
@@ -39,7 +39,7 @@ module Ione
|
|
39
39
|
if closed?
|
40
40
|
return Ione::Future.failed(Rpc::RequestNotSentError.new('Connection closed'))
|
41
41
|
end
|
42
|
-
promise =
|
42
|
+
promise = RequestPromise.new
|
43
43
|
channel = nil
|
44
44
|
@lock.lock
|
45
45
|
begin
|
@@ -60,12 +60,11 @@ module Ione
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
if timeout
|
63
|
-
@scheduler.schedule_timer(timeout)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
63
|
+
promise.timeout_future = @scheduler.schedule_timer(timeout)
|
64
|
+
promise.timeout_future.on_value do
|
65
|
+
error = Rpc::TimeoutError.new('No response received within %ss' % timeout.to_s)
|
66
|
+
promise.fail(error)
|
67
|
+
@timeouts += 1
|
69
68
|
end
|
70
69
|
end
|
71
70
|
promise.future
|
@@ -73,6 +72,10 @@ module Ione
|
|
73
72
|
|
74
73
|
private
|
75
74
|
|
75
|
+
class RequestPromise < Promise
|
76
|
+
attr_accessor :timeout_future
|
77
|
+
end
|
78
|
+
|
76
79
|
def handle_message(response, channel)
|
77
80
|
promise = nil
|
78
81
|
@lock.lock
|
@@ -85,6 +88,7 @@ module Ione
|
|
85
88
|
end
|
86
89
|
if promise && !promise.future.completed?
|
87
90
|
promise.fulfill(response)
|
91
|
+
@scheduler.cancel_timer(promise.timeout_future) if promise.timeout_future
|
88
92
|
end
|
89
93
|
flush_queue
|
90
94
|
end
|
data/lib/ione/rpc/codec.rb
CHANGED
data/lib/ione/rpc/version.rb
CHANGED
@@ -53,6 +53,9 @@ module Ione
|
|
53
53
|
timer_promises << Promise.new
|
54
54
|
timer_promises.last.future
|
55
55
|
end
|
56
|
+
scheduler.stub(:cancel_timer) do |timer|
|
57
|
+
timer_promises.delete(timer)
|
58
|
+
end
|
56
59
|
scheduler.stub(:timer_promises).and_return(timer_promises)
|
57
60
|
end
|
58
61
|
|
@@ -146,6 +149,13 @@ module Ione
|
|
146
149
|
expect { f.value }.to_not raise_error
|
147
150
|
end
|
148
151
|
|
152
|
+
it 'cancel the timeout timer when the response is received before the timeout passes' do
|
153
|
+
f = peer.send_message('foo', 2)
|
154
|
+
connection.data_listener.call('bar@000')
|
155
|
+
scheduler.timer_promises.first.fulfill
|
156
|
+
scheduler.should have_received(:cancel_timer).once
|
157
|
+
end
|
158
|
+
|
149
159
|
it 'fails the request when the connection is closed' do
|
150
160
|
connection.stub(:closed?).and_return(true)
|
151
161
|
f = peer.send_message('foo', 2)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ione-rpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Theo Hultberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ione
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1'
|
20
|
+
- - '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.2'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '1'
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.2'
|
27
33
|
description: A toolkit for building RPC layers using Ione
|
28
34
|
email:
|
29
35
|
- theo@iconara.net
|