em-rocketio-linda-client 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +4 -0
- data/README.md +1 -1
- data/em-rocketio-linda-client.gemspec +1 -0
- data/lib/em-rocketio-linda-client.rb +1 -0
- data/lib/em-rocketio-linda-client/client.rb +17 -7
- data/lib/em-rocketio-linda-client/version.rb +1 -1
- data/sample/sample.rb +4 -2
- data/sample/sample_blocking.rb +3 -1
- data/test/test_client_disconnect.rb +4 -4
- data/test/test_em_rocketio_linda_client.rb +59 -11
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d086a2200e04156cd3d5b5ac51af52214fb327f4
|
4
|
+
data.tar.gz: c530e1da28c79b35e5b99657d5435992560e64b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 310a6c7198955a044b2c8fed74dda469981afde1877c320b707a5e0829189c83550edebfc7da75d9ed5bea2ce33fa71d65c4e410816eeea85dcc153d3968b4ca
|
7
|
+
data.tar.gz: 11b0d3acb0fffb21267b72769801b37ff29a3c5e4287d09b64194680b173d0980f6317a9e0fef4d2dfbb4b6f737e4f6800165875280c03e83cb7e0e762b8b77a
|
data/History.txt
CHANGED
data/README.md
CHANGED
@@ -5,6 +5,9 @@ module EM
|
|
5
5
|
class Error < StandardError
|
6
6
|
end
|
7
7
|
|
8
|
+
class TupleInfo < Hashie::Mash
|
9
|
+
end
|
10
|
+
|
8
11
|
include EventEmitter
|
9
12
|
attr_reader :io, :tuplespace
|
10
13
|
def initialize(io_or_url)
|
@@ -40,13 +43,15 @@ module EM
|
|
40
43
|
end
|
41
44
|
callback_id = "#{Time.now.to_i}#{Time.now.usec}_#{rand(1000000).to_i}"
|
42
45
|
if block_given?
|
43
|
-
@linda.io.once "__linda_read_callback_#{callback_id}"
|
46
|
+
@linda.io.once "__linda_read_callback_#{callback_id}" do |data|
|
47
|
+
block.call(data['tuple'], TupleInfo.new(data['info']))
|
48
|
+
end
|
44
49
|
@linda.io.push "__linda_read", [@name, tuple, callback_id]
|
45
50
|
return
|
46
51
|
end
|
47
52
|
result_tuple = nil
|
48
|
-
@linda.io.once "__linda_read_callback_#{callback_id}" do |
|
49
|
-
result_tuple = tuple
|
53
|
+
@linda.io.once "__linda_read_callback_#{callback_id}" do |data|
|
54
|
+
result_tuple = data['tuple']
|
50
55
|
end
|
51
56
|
@linda.io.push "__linda_read", [@name, tuple, callback_id]
|
52
57
|
while !result_tuple do
|
@@ -61,13 +66,15 @@ module EM
|
|
61
66
|
end
|
62
67
|
callback_id = "#{Time.now.to_i}#{Time.now.usec}_#{rand(1000000).to_i}"
|
63
68
|
if block_given?
|
64
|
-
@linda.io.once "__linda_take_callback_#{callback_id}"
|
69
|
+
@linda.io.once "__linda_take_callback_#{callback_id}" do |data|
|
70
|
+
block.call data['tuple'], TupleInfo.new(data['info'])
|
71
|
+
end
|
65
72
|
@linda.io.push "__linda_take", [@name, tuple, callback_id]
|
66
73
|
return
|
67
74
|
end
|
68
75
|
result_tuple = nil
|
69
|
-
@linda.io.once "__linda_take_callback_#{callback_id}" do |
|
70
|
-
result_tuple = tuple
|
76
|
+
@linda.io.once "__linda_take_callback_#{callback_id}" do |data|
|
77
|
+
result_tuple = data['tuple']
|
71
78
|
end
|
72
79
|
@linda.io.push "__linda_take", [@name, tuple, callback_id]
|
73
80
|
while !result_tuple do
|
@@ -80,8 +87,11 @@ module EM
|
|
80
87
|
unless [Hash, Array].include? tuple.class
|
81
88
|
raise ArgumentError, "tuple must be Array or Hash"
|
82
89
|
end
|
90
|
+
return unless block_given?
|
83
91
|
callback_id = "#{Time.now.to_i}#{Time.now.usec}_#{rand(1000000).to_i}"
|
84
|
-
@linda.io.on "__linda_watch_callback_#{callback_id}"
|
92
|
+
@linda.io.on "__linda_watch_callback_#{callback_id}" do |data|
|
93
|
+
block.call data['tuple'], TupleInfo.new(data['info'])
|
94
|
+
end
|
85
95
|
@linda.io.push "__linda_watch", [@name, tuple, callback_id]
|
86
96
|
end
|
87
97
|
|
data/sample/sample.rb
CHANGED
@@ -3,14 +3,16 @@ require "rubygems"
|
|
3
3
|
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
|
4
4
|
require 'em-rocketio-linda-client'
|
5
5
|
|
6
|
+
url = ARGV.empty? ? "http://linda.shokai.org" : ARGV.shift
|
7
|
+
|
6
8
|
EM::run do
|
7
|
-
client = EM::RocketIO::Linda::Client.new
|
9
|
+
client = EM::RocketIO::Linda::Client.new url
|
8
10
|
ts = client.tuplespace["test_spae"]
|
9
11
|
|
10
12
|
client.io.on :connect do
|
11
13
|
puts "connect #{client.io.type} (#{client.io.session})"
|
12
14
|
|
13
|
-
ts.watch [1,2] do |tuple|
|
15
|
+
ts.watch [1,2] do |tuple, info|
|
14
16
|
p tuple
|
15
17
|
end
|
16
18
|
|
data/sample/sample_blocking.rb
CHANGED
@@ -3,8 +3,10 @@ require "rubygems"
|
|
3
3
|
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
|
4
4
|
require 'em-rocketio-linda-client'
|
5
5
|
|
6
|
+
url = ARGV.empty? ? "http://linda.shokai.org" : ARGV.shift
|
7
|
+
|
6
8
|
EM::run do
|
7
|
-
client = EM::RocketIO::Linda::Client.new
|
9
|
+
client = EM::RocketIO::Linda::Client.new url
|
8
10
|
ts = client.tuplespace["test_spae"]
|
9
11
|
|
10
12
|
client.io.on :connect do
|
@@ -17,16 +17,16 @@ class TestClientDisconnect < MiniTest::Test
|
|
17
17
|
client2.io.on :connect do
|
18
18
|
ts1 = client1.tuplespace[ts_name]
|
19
19
|
ts2 = client2.tuplespace[ts_name]
|
20
|
-
ts1.read [1,2] do |tuple|
|
20
|
+
ts1.read [1,2] do |tuple, info|
|
21
21
|
_tuple1 = tuple
|
22
22
|
end
|
23
|
-
ts1.take [1,2] do |tuple|
|
23
|
+
ts1.take [1,2] do |tuple, info|
|
24
24
|
_tuple2 = tuple
|
25
25
|
end
|
26
|
-
ts1.watch [1,2] do |tuple|
|
26
|
+
ts1.watch [1,2] do |tuple, info|
|
27
27
|
_tuple3 = tuple
|
28
28
|
end
|
29
|
-
ts2.take [1,2] do |tuple|
|
29
|
+
ts2.take [1,2] do |tuple, info|
|
30
30
|
_tuple4 = tuple
|
31
31
|
end
|
32
32
|
client1.io.close
|
@@ -17,19 +17,19 @@ class TestEmRocketIOLindaClient < MiniTest::Test
|
|
17
17
|
ts.write ["rw",1,2,3]
|
18
18
|
ts.write ["rw",1,2,"a"]
|
19
19
|
ts.write ["rw",1,"a",2]
|
20
|
-
ts.take ["rw",1,2] do |tuple|
|
20
|
+
ts.take ["rw",1,2] do |tuple, info|
|
21
21
|
_tuple1 = tuple
|
22
22
|
end
|
23
|
-
ts.read ["rw",1,2] do |tuple|
|
23
|
+
ts.read ["rw",1,2] do |tuple, info|
|
24
24
|
_tuple2 = tuple
|
25
25
|
end
|
26
|
-
ts.take ["rw",1,2] do |tuple|
|
26
|
+
ts.take ["rw",1,2] do |tuple, info|
|
27
27
|
_tuple3 = tuple
|
28
28
|
end
|
29
29
|
client2 = EM::RocketIO::Linda::Client.new App.url
|
30
30
|
ts2 = client2.tuplespace[ts_name]
|
31
31
|
client2.io.on :connect do
|
32
|
-
ts2.take ["rw",1] do |tuple|
|
32
|
+
ts2.take ["rw",1] do |tuple, info|
|
33
33
|
_tuple4 = tuple
|
34
34
|
end
|
35
35
|
end
|
@@ -59,13 +59,13 @@ class TestEmRocketIOLindaClient < MiniTest::Test
|
|
59
59
|
client = EM::RocketIO::Linda::Client.new App.url
|
60
60
|
ts = client.tuplespace["ts_#{rand Time.now.to_i}"]
|
61
61
|
client.io.on :connect do
|
62
|
-
ts.take ["watch",1,2] do |tuple|
|
62
|
+
ts.take ["watch",1,2] do |tuple, info|
|
63
63
|
_tuple1 = tuple
|
64
64
|
end
|
65
|
-
ts.read ["watch",1,2] do |tuple|
|
65
|
+
ts.read ["watch",1,2] do |tuple, info|
|
66
66
|
_tuple2 = tuple
|
67
67
|
end
|
68
|
-
ts.watch ["watch",1,2] do |tuple|
|
68
|
+
ts.watch ["watch",1,2] do |tuple, info|
|
69
69
|
results.push tuple
|
70
70
|
end
|
71
71
|
ts.write ["watch",1,2,3]
|
@@ -100,10 +100,10 @@ class TestEmRocketIOLindaClient < MiniTest::Test
|
|
100
100
|
ts2 = client.tuplespace["ts2_#{rand Time.now.to_i}"]
|
101
101
|
|
102
102
|
client.io.on :connect do
|
103
|
-
ts2.take ["a"] do |tuple|
|
103
|
+
ts2.take ["a"] do |tuple, info|
|
104
104
|
_tuple2 = tuple
|
105
105
|
end
|
106
|
-
ts1.take [1] do |tuple|
|
106
|
+
ts1.take [1] do |tuple, info|
|
107
107
|
_tuple1 = tuple
|
108
108
|
end
|
109
109
|
ts1.write [1,2,3]
|
@@ -134,12 +134,12 @@ class TestEmRocketIOLindaClient < MiniTest::Test
|
|
134
134
|
ts.write ["expire",1,2,999], :expire => false
|
135
135
|
ts.write ["expire",1,2,3], :expire => 10
|
136
136
|
ts.write ["expire",1,2,"a","b"], :expire => 2
|
137
|
-
ts.read ["expire",1,2] do |tuple|
|
137
|
+
ts.read ["expire",1,2] do |tuple, info|
|
138
138
|
_tuple1 = tuple
|
139
139
|
end
|
140
140
|
sleep 3
|
141
141
|
push :check_expire, nil
|
142
|
-
ts.read ["expire",1,2] do |tuple|
|
142
|
+
ts.read ["expire",1,2] do |tuple, info|
|
143
143
|
_tuple2 = tuple
|
144
144
|
end
|
145
145
|
end
|
@@ -156,4 +156,52 @@ class TestEmRocketIOLindaClient < MiniTest::Test
|
|
156
156
|
assert_equal _tuple1, ["expire",1,2,"a","b"]
|
157
157
|
assert_equal _tuple2, ["expire",1,2,3]
|
158
158
|
end
|
159
|
+
|
160
|
+
def test_tuple_info
|
161
|
+
_tuple1 = nil
|
162
|
+
_tuple2 = nil
|
163
|
+
_tuple3 = nil
|
164
|
+
_info1 = nil
|
165
|
+
_info2 = nil
|
166
|
+
_info3 = nil
|
167
|
+
EM::run do
|
168
|
+
client = EM::RocketIO::Linda::Client.new App.url
|
169
|
+
ts = client.tuplespace["ts_#{rand Time.now.to_i}"]
|
170
|
+
|
171
|
+
client.io.on :connect do
|
172
|
+
ts.read [1,2] do |tuple, info|
|
173
|
+
_tuple1 = tuple
|
174
|
+
_info1 = info
|
175
|
+
end
|
176
|
+
ts.watch [1] do |tuple, info|
|
177
|
+
_tuple2 = tuple
|
178
|
+
_info2 = info
|
179
|
+
end
|
180
|
+
ts.take [1,2,3] do |tuple, info|
|
181
|
+
_tuple3 = tuple
|
182
|
+
_info3 = info
|
183
|
+
end
|
184
|
+
ts.write [1,2,3]
|
185
|
+
end
|
186
|
+
EM::defer do
|
187
|
+
50.times do
|
188
|
+
sleep 0.1
|
189
|
+
break if _tuple3
|
190
|
+
end
|
191
|
+
EM::add_timer 1 do
|
192
|
+
EM::stop
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
assert_equal _tuple1, [1,2,3]
|
197
|
+
assert_equal _tuple2, [1,2,3]
|
198
|
+
assert_equal _tuple3, [1,2,3]
|
199
|
+
assert_equal _info1.class, Sinatra::RocketIO::Linda::Client::TupleInfo
|
200
|
+
assert_equal _info2.class, Sinatra::RocketIO::Linda::Client::TupleInfo
|
201
|
+
assert_equal _info3.class, Sinatra::RocketIO::Linda::Client::TupleInfo
|
202
|
+
assert _info1.from =~ /^\d+\.\d+\.\d+\.\d+$/
|
203
|
+
assert _info2.from =~ /^\d+\.\d+\.\d+\.\d+$/
|
204
|
+
assert _info3.from =~ /^\d+\.\d+\.\d+\.\d+$/
|
205
|
+
end
|
206
|
+
|
159
207
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-rocketio-linda-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sho Hashimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: hashie
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: eventmachine
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
182
|
version: '0'
|
169
183
|
requirements: []
|
170
184
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.
|
185
|
+
rubygems_version: 2.1.5
|
172
186
|
signing_key:
|
173
187
|
specification_version: 4
|
174
188
|
summary: RocketIO Linda client for eventmachine
|