sinatra-rocketio-linda 0.0.1 → 0.0.2
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/History.txt +5 -2
- data/README.md +54 -7
- data/lib/js/linda.js +7 -0
- data/lib/sinatra-rocketio-linda/linda.rb +16 -0
- data/lib/sinatra-rocketio-linda/tuplespace.rb +7 -1
- data/lib/sinatra/rocketio/linda/client.rb +10 -0
- data/lib/sinatra/rocketio/linda/version.rb +1 -1
- data/sample/bin/cui_calc_watcher.rb +21 -0
- data/sample/public/client.js +5 -0
- data/test/test_tuplespace.rb +20 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebfcd893b6fd6ef33fa0c366cb796c70896b76f2
|
4
|
+
data.tar.gz: 85c84d5d7b420570cf6ed9a806dd2c94e2ea42ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2f78eeef9f0237a405a87684b7d832a986dcafa6b3aad4194036190efeef7859af3b811c72783820294d1bccd7826e13b9f6d0b9df2a0c78b8f833a66c9b47b
|
7
|
+
data.tar.gz: a73311f2263b81720aa7c6963af7ea7e8eaf1b590637dfd43184da1409c7486dd613ec835d0bbec666d8ed65feb222154f418518985ae50262087ecaf588f2ff
|
data/History.txt
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
=== 0.0.
|
1
|
+
=== 0.0.2 2013-05-15
|
2
|
+
* update README
|
3
|
+
* TupleSpace#watch(tuple, callback(tuple))
|
2
4
|
|
5
|
+
=== 0.0.1 2013-05-15
|
3
6
|
* JavaScript Linda Client for WebBrowser
|
4
7
|
* Ruby Linda Client
|
5
8
|
* TupleSpace#write(tuple)
|
6
9
|
* TupleSpace#take(tuple, callback(tuple))
|
7
10
|
* TupleSpace#read(tuple, callback(tuple))
|
8
|
-
* sinatra config - set :linda, :
|
11
|
+
* sinatra config - set :linda, :check_expire => 60 (sec)
|
data/README.md
CHANGED
@@ -5,13 +5,6 @@ sinatra-rocketio-linda
|
|
5
5
|
* https://github.com/shokai/sinatra-rocketio-linda
|
6
6
|
|
7
7
|
|
8
|
-
Linda
|
9
|
-
-----
|
10
|
-
|
11
|
-
* http://en.wikipedia.org/wiki/Linda_(coordination_language)
|
12
|
-
* http://ja.wikipedia.org/wiki/Linda
|
13
|
-
|
14
|
-
|
15
8
|
Installation
|
16
9
|
------------
|
17
10
|
|
@@ -27,6 +20,29 @@ Requirements
|
|
27
20
|
* [jQuery](http://jquery.com)
|
28
21
|
|
29
22
|
|
23
|
+
Linda
|
24
|
+
-----
|
25
|
+
Linda is a coordination launguage for parallel programming.
|
26
|
+
|
27
|
+
* http://en.wikipedia.org/wiki/Linda_(coordination_language)
|
28
|
+
* http://ja.wikipedia.org/wiki/Linda
|
29
|
+
|
30
|
+
|
31
|
+
### TupleSpace
|
32
|
+
Shared memory on Sinatra.
|
33
|
+
|
34
|
+
|
35
|
+
### Tuple Operations
|
36
|
+
- write( tuple, options )
|
37
|
+
- put a Tuple into the TupleSpace
|
38
|
+
- take( tuple, callback(tuple) )
|
39
|
+
- get a matched Tuple from the TupleSpace and delete
|
40
|
+
- read( tuple, callback(tuple) )
|
41
|
+
- get a matched Tuple from the TupleSpace
|
42
|
+
- watch( tuple, callback(tuple) )
|
43
|
+
- overwatch written Tuples in the TupleSpace
|
44
|
+
|
45
|
+
|
30
46
|
Usage
|
31
47
|
-----
|
32
48
|
|
@@ -99,6 +115,37 @@ var calc = function(){
|
|
99
115
|
io.on("connect", calc); // RocketIO's "connect" event
|
100
116
|
```
|
101
117
|
|
118
|
+
worker side (Ruby)
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
require 'rubygems'
|
122
|
+
require 'sinatra/rocketio/linda/client'
|
123
|
+
|
124
|
+
## create tuplespace
|
125
|
+
linda = Sinatra::RocketIO::Linda::Client.new 'http://localhost:5000'
|
126
|
+
ts = linda.tuplespace["calc"]
|
127
|
+
|
128
|
+
## calculate
|
129
|
+
calc = lambda{
|
130
|
+
ts.take ["calc_request"] do |tuple|
|
131
|
+
query = tuple[1] ## => "1-2+3*4"
|
132
|
+
result = eval(query)
|
133
|
+
puts "calc: #{query} = #{result}" ## => "1-2+3*4 = 11"
|
134
|
+
ts.write ["calc_result", result] ## return to 'client' side
|
135
|
+
calc.call ## recursive call
|
136
|
+
end
|
137
|
+
}
|
138
|
+
|
139
|
+
linda.io.on :connect do ## RocketIO's "connect" event
|
140
|
+
puts "connect #{io.session}"
|
141
|
+
calc.call
|
142
|
+
end
|
143
|
+
|
144
|
+
loop do
|
145
|
+
end
|
146
|
+
```
|
147
|
+
|
148
|
+
|
102
149
|
Test
|
103
150
|
----
|
104
151
|
|
data/lib/js/linda.js
CHANGED
@@ -32,5 +32,12 @@ var Linda = function(io, opts){
|
|
32
32
|
self.io.once("__linda_take_callback_"+callback_id, callback);
|
33
33
|
self.io.push("__linda_take", [space.name, tuple, callback_id]);
|
34
34
|
};
|
35
|
+
this.watch = function(tuple, callback){
|
36
|
+
if(tuple === null || typeof tuple !== "object") return;
|
37
|
+
if(typeof callback !== "function") return;
|
38
|
+
var callback_id = new Date()-0+"";
|
39
|
+
self.io.on("__linda_watch_callback_"+callback_id, callback);
|
40
|
+
self.io.push("__linda_watch", [space.name, tuple, callback_id]);
|
41
|
+
};
|
35
42
|
};
|
36
43
|
};
|
@@ -74,3 +74,19 @@ Sinatra::RocketIO.on :__linda_take do |data, client|
|
|
74
74
|
Sinatra::RocketIO.push "__linda_take_callback_#{callback}", tuple.data, :to => client.session
|
75
75
|
end
|
76
76
|
end
|
77
|
+
|
78
|
+
Sinatra::RocketIO.on :__linda_watch do |data, client|
|
79
|
+
space, tuple, callback = data
|
80
|
+
space = "__default__" if !space or !space.kind_of? String or space.empty?
|
81
|
+
unless [Hash, Array].include? tuple.class
|
82
|
+
Sinatra::RocketIO::Linda.emit :error, "received Tuple is not Hash or Array at :__linda_watch"
|
83
|
+
next
|
84
|
+
end
|
85
|
+
if !callback or !callback.kind_of? String or callback.empty?
|
86
|
+
Sinatra::RocketIO::Linda.emit :error, "received Callback ID is not valid at :__linda_watch"
|
87
|
+
next
|
88
|
+
end
|
89
|
+
Sinatra::RocketIO::Linda[space].watch tuple do |tuple|
|
90
|
+
Sinatra::RocketIO.push "__linda_watch_callback_#{callback}", tuple.data, :to => client.session
|
91
|
+
end
|
92
|
+
end
|
@@ -35,7 +35,7 @@ module Sinatra
|
|
35
35
|
@callbacks.each do |callback|
|
36
36
|
next unless callback[:tuple].match? tuple
|
37
37
|
callback[:callback].call tuple
|
38
|
-
calleds.push callback
|
38
|
+
calleds.push callback unless callback[:type] == :watch
|
39
39
|
if callback[:type] == :take
|
40
40
|
taked = tuple
|
41
41
|
break
|
@@ -84,6 +84,12 @@ module Sinatra
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
+
def watch(tuple, &block)
|
88
|
+
raise ArgumentError, "block not given" unless block_given?
|
89
|
+
tuple = Tuple.new tuple unless tuple.kind_of? Tuple
|
90
|
+
@callbacks.unshift(:type => :watch, :callback => block, :tuple => tuple)
|
91
|
+
end
|
92
|
+
|
87
93
|
def check_expire
|
88
94
|
expires = []
|
89
95
|
each do |tuple|
|
@@ -51,6 +51,16 @@ module Sinatra
|
|
51
51
|
@linda.io.once "__linda_take_callback_#{callback_id}", &block
|
52
52
|
@linda.io.push "__linda_take", [@name, tuple, callback_id]
|
53
53
|
end
|
54
|
+
|
55
|
+
def watch(tuple, &block)
|
56
|
+
unless [Hash, Array].include? tuple.class
|
57
|
+
raise ArgumentError, "tuple must be Array or Hash"
|
58
|
+
end
|
59
|
+
callback_id = "#{Time.now.to_i}#{Time.now.usec}"
|
60
|
+
@linda.io.on "__linda_watch_callback_#{callback_id}", &block
|
61
|
+
@linda.io.push "__linda_watch", [@name, tuple, callback_id]
|
62
|
+
end
|
63
|
+
|
54
64
|
end
|
55
65
|
|
56
66
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.unshift File.expand_path '../../lib', File.dirname(__FILE__)
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'sinatra/rocketio/linda/client'
|
5
|
+
|
6
|
+
linda = Sinatra::RocketIO::Linda::Client.new 'http://localhost:5000'
|
7
|
+
ts = linda.tuplespace["calc"]
|
8
|
+
|
9
|
+
linda.io.on :connect do
|
10
|
+
puts "connect #{io.session}"
|
11
|
+
ts.watch [] do |tuple|
|
12
|
+
puts "watch #{tuple}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
linda.io.on :disconnect do
|
17
|
+
puts "disconnect #{io.session}"
|
18
|
+
end
|
19
|
+
|
20
|
+
loop do
|
21
|
+
end
|
data/sample/public/client.js
CHANGED
data/test/test_tuplespace.rb
CHANGED
@@ -96,6 +96,26 @@ class TestTupleSpace < MiniTest::Test
|
|
96
96
|
assert_equal @space.size, 0
|
97
97
|
end
|
98
98
|
|
99
|
+
def test_watch
|
100
|
+
assert_equal @space.size, 0
|
101
|
+
_tuple1 = nil
|
102
|
+
@space.take [1] do |tuple|
|
103
|
+
_tuple1 = tuple
|
104
|
+
end
|
105
|
+
results = []
|
106
|
+
@space.watch [1,2] do |tuple|
|
107
|
+
results << tuple
|
108
|
+
end
|
109
|
+
@space.write [1,2,3]
|
110
|
+
@space.write [1,2,"aa"]
|
111
|
+
@space.write [1,"a",3]
|
112
|
+
assert_equal _tuple1.data, [1,2,3]
|
113
|
+
assert_equal @space.size, 2
|
114
|
+
assert_equal results.size, 2
|
115
|
+
assert_equal results[0].data, [1,2,3]
|
116
|
+
assert_equal results[1].data, [1,2,"aa"]
|
117
|
+
end
|
118
|
+
|
99
119
|
def test_tuple_expire
|
100
120
|
@space.write [1,2,3], :expire => 3
|
101
121
|
@space.write [1,2,"a","b"], :expire => 2
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-rocketio-linda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-05-
|
11
|
+
date: 2013-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- lib/sinatra/rocketio/linda.rb
|
147
147
|
- lib/sinatra/rocketio/linda/client.rb
|
148
148
|
- lib/sinatra/rocketio/linda/version.rb
|
149
|
+
- sample/bin/cui_calc_watcher.rb
|
149
150
|
- sample/bin/cui_calc_worker.rb
|
150
151
|
- sample/config.ru
|
151
152
|
- sample/main.rb
|