barney 0.10.1 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +36 -25
- data/README.md +39 -41
- data/lib/barney/share.rb +20 -9
- data/lib/barney.rb +13 -1
- data/test/suite/lib/barney.rb +10 -0
- metadata +3 -1
data/ChangeLog
CHANGED
@@ -1,39 +1,50 @@
|
|
1
|
-
2011-
|
1
|
+
2011-05-03 Robert Gleeson <rob@flowof.info>
|
2
2
|
|
3
3
|
* lib/barney.rb README.md ChangeLog:
|
4
|
-
Release 0.
|
5
|
-
|
6
|
-
* lib/barney/share.rb:
|
7
|
-
Fix a bug where Barney::Share#history could return unordered/incorrect data
|
8
|
-
when subprocesses are spawned in parallel.
|
4
|
+
Release 0.11.0
|
9
5
|
|
10
6
|
* lib/barney/share.rb:
|
11
|
-
|
7
|
+
Rename @context to @scope.
|
12
8
|
|
13
9
|
* lib/barney/share.rb:
|
14
|
-
|
15
|
-
|
10
|
+
Add Barney::Share#wait_all.
|
11
|
+
|
12
|
+
* test/suite/lib/barney.rb:
|
13
|
+
Add test suite for the 'Barney' module.
|
16
14
|
|
17
|
-
* lib/barney.rb:
|
18
|
-
|
15
|
+
* lib/barney.rb:
|
16
|
+
Document Barney.method_missing, and Barney.respond_to?
|
19
17
|
|
18
|
+
* lib/barney.rb:
|
19
|
+
Add Barney.respond_to?
|
20
20
|
|
21
|
-
|
21
|
+
* ChangeLog:
|
22
|
+
Record Releases.
|
22
23
|
|
23
|
-
*
|
24
|
-
|
24
|
+
* lib/barney/share.rb:
|
25
|
+
Remove Barney::Share#spawn_pipes (private method).
|
25
26
|
|
26
|
-
* lib/barney
|
27
|
-
|
28
|
-
|
29
|
-
* lib/barney/share.rb:
|
30
|
-
|
31
|
-
|
32
|
-
Remove @shared.
|
33
|
-
Replaced by @streams, an Array of StreamPair objects.
|
34
|
-
|
35
|
-
|
27
|
+
* lib/barney.rb README.md ChangeLog:
|
28
|
+
Release 0.10.1
|
29
|
+
|
30
|
+
* lib/barney/share.rb:
|
31
|
+
Fix a bug where Barney::Share#history could return unordered/incorrect data
|
32
|
+
when subprocesses are spawned in parallel.
|
36
33
|
|
37
34
|
|
35
|
+
2011-04-23 Robert Gleeson <rob@flowof.info>
|
38
36
|
|
39
|
-
|
37
|
+
* lib/barney.rb README.md:
|
38
|
+
Release 0.10.0
|
39
|
+
|
40
|
+
* lib/barney.rb:
|
41
|
+
Add Barney.method_missing …
|
42
|
+
Messages are passed onto an instance of Barney::Share.
|
43
|
+
|
44
|
+
* lib/barney.rb README.md:
|
45
|
+
Release 0.9.1
|
46
|
+
|
47
|
+
* lib/barney/share.rb:
|
48
|
+
Fix a bug where Barney::Share#share could return nil.
|
49
|
+
If there were no duplicates in @variables, `nil` would be returned.
|
50
|
+
|
data/README.md
CHANGED
@@ -1,66 +1,64 @@
|
|
1
|
-
![Barney Picture](http://
|
1
|
+
![Barney Picture](http://i.imgur.com/VblLQ.png)
|
2
2
|
|
3
|
-
Barney
|
4
|
-
Barney is developed
|
3
|
+
Barney makes sharing data between processes easy and natural by providing a simple and easy to use DSL.
|
4
|
+
Barney is developed against Ruby 1.9.1 and later, but it may work on earlier versions of Ruby as well.
|
5
5
|
|
6
6
|
Limitations
|
7
7
|
-----------
|
8
8
|
|
9
9
|
* Sharable objects
|
10
|
-
Behind the scenes, Barney is using Marshal to send data between processes.
|
10
|
+
Behind the scenes, Barney is using Marshal to send data between processes.
|
11
11
|
Any object that can be dumped through Marshal.dump can be shared.
|
12
|
-
This excludes anonymous modules, anonymous classes, Proc objects, and possibly some other objects I
|
13
|
-
cannot think of.
|
12
|
+
This excludes anonymous modules, anonymous classes, Proc objects, and possibly some other objects I cannot think of.
|
14
13
|
|
15
14
|
* Thread safety
|
16
15
|
Barney is thread-safe as long as one instance of Barney::Share is used per-thread.
|
17
|
-
There is a mutex lock in place, but it only concerns Barney::Share#synchronize, where data is shared
|
18
|
-
|
16
|
+
There is a mutex lock in place, but it only concerns Barney::Share#synchronize, where data is shared among all
|
17
|
+
instances of Barney::Share.
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
Okay, now that we've got that out of the way, let's see what using Barney is like:
|
24
|
-
(The [Samples](https://github.com/robgleeson/barney/tree/develop/samples) directory has more examples …)
|
19
|
+
Usage
|
20
|
+
-----
|
25
21
|
|
26
|
-
|
22
|
+
#!/usr/bin/env ruby
|
23
|
+
require 'barney'
|
27
24
|
|
28
|
-
|
29
|
-
|
25
|
+
Barney.share :name
|
26
|
+
name = 'Robert'
|
30
27
|
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
pid = Barney.fork do
|
29
|
+
name.slice! 0..2
|
30
|
+
end
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
32
|
+
Process.wait pid
|
33
|
+
Barney.sync
|
38
34
|
|
39
|
-
|
40
|
-
obj.sync
|
41
|
-
|
42
|
-
puts message # 'Hello, World!'
|
35
|
+
puts name # "Rob"
|
43
36
|
|
37
|
+
* _More!_
|
38
|
+
Check out the [samples](https://github.com/robgleeson/barney/tree/master/samples) directory or if you're looking
|
39
|
+
for precise and detailed info, check out the API docs.
|
44
40
|
|
45
|
-
|
46
|
-
|
41
|
+
* _Notes!_
|
42
|
+
It's worth mentioning that the _Barney_ module is passing method calls to an instance of _Barney::Share_,
|
43
|
+
where the DSL is implemented. If you prefer, or your situation requires, feel free to create instance(s) of
|
44
|
+
_Barney::Share_ yourself.
|
47
45
|
|
48
|
-
The Barney module will forward requests onto an instance of Barney::Share:
|
49
46
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
Barney.share :name
|
54
|
-
name = 'Robert'
|
47
|
+
Documentation
|
48
|
+
--------------
|
55
49
|
|
56
|
-
|
57
|
-
name.slice! 0..2
|
58
|
-
end
|
50
|
+
**API**
|
59
51
|
|
60
|
-
|
61
|
-
|
52
|
+
* [master (git)](http://rubydoc.info/github/robgleeson/barney/master/)
|
53
|
+
* [0.10.0](http://rubydoc.info/gems/barney/0.10.0/)
|
54
|
+
* [0.9.1](http://rubydoc.info/gems/barney/0.9.1/)
|
55
|
+
* [0.9.0](http://rubydoc.info/gems/barney/0.9.0/)
|
56
|
+
* [0.8.1](http://rubydoc.info/gems/barney/0.8.1/)
|
57
|
+
* [0.8.0](http://rubydoc.info/gems/barney/0.8.0/)
|
58
|
+
* [0.7.0](http://rubydoc.info/gems/barney/0.7.0)
|
59
|
+
* …
|
62
60
|
|
63
|
-
|
61
|
+
|
64
62
|
|
65
63
|
Install
|
66
64
|
--------
|
@@ -84,12 +82,12 @@ Documentation
|
|
84
82
|
**API**
|
85
83
|
|
86
84
|
* [master (git)](http://rubydoc.info/github/robgleeson/barney/master/)
|
85
|
+
* [0.11.0](http://rubydoc.info/gems/barney/0.11.0/)
|
87
86
|
* [0.10.1](http://rubydoc.info/gems/barney/0.10.1/)
|
88
87
|
* [0.10.0](http://rubydoc.info/gems/barney/0.10.0/)
|
89
88
|
* [0.9.1](http://rubydoc.info/gems/barney/0.9.1/)
|
90
89
|
* [0.9.0](http://rubydoc.info/gems/barney/0.9.0/)
|
91
90
|
* [0.8.1](http://rubydoc.info/gems/barney/0.8.1/)
|
92
|
-
* [0.8.0](http://rubydoc.info/gems/barney/0.8.0/)
|
93
91
|
* …
|
94
92
|
|
95
93
|
|
data/lib/barney/share.rb
CHANGED
@@ -45,7 +45,9 @@ module Barney
|
|
45
45
|
@streams = []
|
46
46
|
@variables = []
|
47
47
|
@history = []
|
48
|
-
@
|
48
|
+
@pids = []
|
49
|
+
@pid = nil
|
50
|
+
@scope = nil
|
49
51
|
yield self if block_given?
|
50
52
|
end
|
51
53
|
|
@@ -66,38 +68,47 @@ module Barney
|
|
66
68
|
@streams.delete_if { |stream| stream.variable == variable }
|
67
69
|
@variables.delete variable
|
68
70
|
end
|
69
|
-
|
70
71
|
@variables
|
71
72
|
end
|
72
73
|
|
74
|
+
# Collect the status of all subprocesses spawned by a {Barney::Share Barney::Share} instance.
|
75
|
+
# @return [void]
|
76
|
+
def wait_all
|
77
|
+
@pids.each do |pid|
|
78
|
+
Process.wait pid
|
79
|
+
end
|
80
|
+
@pids.clear
|
81
|
+
end
|
82
|
+
|
73
83
|
# Spawns a child process.
|
74
84
|
# It can be treated like the Kernel.fork method, but a block or Proc object is a required argument.
|
85
|
+
#
|
75
86
|
# @param [Proc] Proc Accepts a block or Proc object that will be executed in a child process.
|
76
87
|
# @raise [ArgumentError] Raises an ArgumentError if a block or Proc object isn't supplied.
|
77
88
|
# @return [Fixnum] Returns the Process ID(PID) of the spawned child process.
|
78
|
-
def fork &
|
89
|
+
def fork &block
|
79
90
|
raise ArgumentError, "A block or Proc object is expected" unless block_given?
|
91
|
+
@scope = block.binding
|
80
92
|
|
81
93
|
tmp_streams = Array.new @variables.size do |index|
|
82
94
|
StreamPair.new @variables[index], *IO.pipe
|
83
95
|
end
|
84
96
|
|
85
|
-
@context = blk.binding
|
86
97
|
@pid = Kernel.fork do
|
87
|
-
|
98
|
+
block.call
|
88
99
|
tmp_streams.each do |stream|
|
89
100
|
stream.in.close
|
90
|
-
stream.out.write Marshal.dump(eval("#{stream.variable}", @
|
101
|
+
stream.out.write Marshal.dump(eval("#{stream.variable}", @scope))
|
91
102
|
stream.out.close
|
92
103
|
end
|
93
104
|
end
|
94
|
-
|
105
|
+
|
106
|
+
@pids.push @pid
|
95
107
|
@streams.push *tmp_streams
|
96
108
|
@pid
|
97
109
|
end
|
98
110
|
|
99
111
|
# Synchronizes data between the parent and child process.
|
100
|
-
# It will block until the spawned child process has exited.
|
101
112
|
# @return [void]
|
102
113
|
def synchronize
|
103
114
|
Barney::Share.mutex.synchronize do
|
@@ -105,7 +116,7 @@ module Barney
|
|
105
116
|
stream.out.close
|
106
117
|
Barney::Share.value = Marshal.load stream.in.read
|
107
118
|
stream.in.close
|
108
|
-
value = eval "#{stream.variable} = Barney::Share.value", @
|
119
|
+
value = eval "#{stream.variable} = Barney::Share.value", @scope
|
109
120
|
@history.push HistoryItem.new(stream.variable, value)
|
110
121
|
end
|
111
122
|
|
data/lib/barney.rb
CHANGED
@@ -2,11 +2,14 @@ require 'barney/share'
|
|
2
2
|
|
3
3
|
module Barney
|
4
4
|
|
5
|
-
VERSION = '0.
|
5
|
+
VERSION = '0.11.0'
|
6
6
|
@proxy = Barney::Share.new
|
7
7
|
|
8
8
|
class << self
|
9
9
|
|
10
|
+
# Forward message to an instance of {Barney::Share Barney::Share}.
|
11
|
+
#
|
12
|
+
# @see Barney::Share Barney::Share.
|
10
13
|
def method_missing meth, *args, &blk
|
11
14
|
if @proxy.respond_to? meth
|
12
15
|
@proxy.send meth, *args, &blk
|
@@ -15,6 +18,15 @@ module Barney
|
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
21
|
+
# Ask {Barney} does it respond to _meth_.
|
22
|
+
#
|
23
|
+
# @param [String, Symbol, #to_sym] Name The method name.
|
24
|
+
# @param [Boolean] Scope Pass true to extend scope to include private methods.
|
25
|
+
# @return [Boolean] Return true if {Barney} can respond to _meth_.
|
26
|
+
def respond_to? meth, with_private = false
|
27
|
+
super || @proxy.respond_to?(meth, with_private)
|
28
|
+
end
|
29
|
+
|
18
30
|
end
|
19
31
|
|
20
32
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: barney
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.11.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Robert Gleeson
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- test/suite/lib/barney/share#shared.rb
|
59
59
|
- test/suite/lib/barney/share#synchronize.rb
|
60
60
|
- test/suite/lib/barney/share#unshare.rb
|
61
|
+
- test/suite/lib/barney.rb
|
61
62
|
has_rdoc: true
|
62
63
|
homepage: http://github.com/robgleeson/barney
|
63
64
|
licenses: []
|
@@ -93,3 +94,4 @@ test_files:
|
|
93
94
|
- test/suite/lib/barney/share#shared.rb
|
94
95
|
- test/suite/lib/barney/share#synchronize.rb
|
95
96
|
- test/suite/lib/barney/share#unshare.rb
|
97
|
+
- test/suite/lib/barney.rb
|