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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0484939a37aaa0a93cd380fea16785a5e99fc6a2
4
- data.tar.gz: b6bcde795bfc5303fd6b3076135d5f8c3c262b28
3
+ metadata.gz: d086a2200e04156cd3d5b5ac51af52214fb327f4
4
+ data.tar.gz: c530e1da28c79b35e5b99657d5435992560e64b8
5
5
  SHA512:
6
- metadata.gz: 80ab851054515b3abce7c1e92cdf51b9f1fa558e52cfe9f0db9dee8406a1422c7a39e7316f7f7207646e740d6787377e3a38b5d7d8fc2bf66d8b41e868d3f225
7
- data.tar.gz: a37de55934601f876eed60253a25ffc7dd48af85343fcf5721c02f20c360bff1a0dcf1bc22a2b63bbef5dd414553030c5a556653a60ab242a22e02e33108dfa6
6
+ metadata.gz: 310a6c7198955a044b2c8fed74dda469981afde1877c320b707a5e0829189c83550edebfc7da75d9ed5bea2ce33fa71d65c4e410816eeea85dcc153d3968b4ca
7
+ data.tar.gz: 11b0d3acb0fffb21267b72769801b37ff29a3c5e4287d09b64194680b173d0980f6317a9e0fef4d2dfbb4b6f737e4f6800165875280c03e83cb7e0e762b8b77a
@@ -1,3 +1,7 @@
1
+ === 1.0.0 2013-10-03
2
+
3
+ * !!! protocol was updated
4
+
1
5
  === 0.0.3 2013-07-04
2
6
 
3
7
  * blocking style TupleSpace#read and TupleSpace#take
data/README.md CHANGED
@@ -34,7 +34,7 @@ EM::run do
34
34
  end
35
35
 
36
36
  ## watch Tuples
37
- ts.watch [1,2] do |tuple|
37
+ ts.watch [1,2] do |tuple, info|
38
38
  p tuple
39
39
  end
40
40
 
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "thin"
25
25
 
26
26
  spec.add_dependency "em-rocketio-client"
27
+ spec.add_dependency "hashie"
27
28
  spec.add_dependency "eventmachine"
28
29
  spec.add_dependency "event_emitter"
29
30
  end
@@ -1,6 +1,7 @@
1
1
  require "eventmachine"
2
2
  require "em-rocketio-client"
3
3
  require "event_emitter"
4
+ require "hashie"
4
5
 
5
6
  require "em-rocketio-linda-client/version"
6
7
  require "em-rocketio-linda-client/client"
@@ -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}", &block
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 |tuple|
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}", &block
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 |tuple|
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}", &block
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
 
@@ -2,7 +2,7 @@ module EM
2
2
  module RocketIO
3
3
  module Linda
4
4
  class Client
5
- VERSION = "0.0.3"
5
+ VERSION = "1.0.0"
6
6
  end
7
7
  end
8
8
  end
@@ -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 "http://linda.shokai.org"
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
 
@@ -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 "http://linda.shokai.org"
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.3
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-07-03 00:00:00.000000000 Z
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.0.3
185
+ rubygems_version: 2.1.5
172
186
  signing_key:
173
187
  specification_version: 4
174
188
  summary: RocketIO Linda client for eventmachine