abundance 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/abundance.rb CHANGED
@@ -63,6 +63,7 @@ class Abundance
63
63
  # results = processor.parse(command)
64
64
  # seed.crop( true, results)
65
65
  # end
66
+ #
66
67
  # end
67
68
  #
68
69
  # id1 = gardener.seed('command1')
@@ -92,3 +93,4 @@ class Abundance
92
93
  end
93
94
 
94
95
  end
96
+
data/lib/garden.rb CHANGED
@@ -3,8 +3,9 @@
3
3
  # The Garden is where the thread concurency is implemented,
4
4
  # offering itself as a thread queue manager,
5
5
  # dispatching seeds from the Gardener to its Rows child class and back again.
6
- # Since Ruby doesn't implement Native Threads, and only Native Threads scales to multi-core execution,
7
- # the way to implement concurent execution is through splitting the task at hand between multiple single threaded parallel executions.
6
+ # it does so using its child class, the Rows. Since Ruby doesn't implement Native Threads,
7
+ # and only Native Threads scales to multi-core execution, the way to implement concurent execution is
8
+ # through splitting the task at hand between multiple single threaded parallel executions.
8
9
  # The Rows system does exactly that, using the Ruby fork function, then connecting the isolated running
9
10
  # processes to the Garden, through a simple socket system provided by the Toolshed Module.
10
11
  #
@@ -77,7 +78,8 @@ class Garden
77
78
  when :growth
78
79
  case data
79
80
  when :progress
80
- progress = sprintf( "%.2f", @crops.size.to_f / (@crops.size + @sprouts.compact.size + @seeds.size))
81
+ value = @crops.size.to_f / (@crops.size + @sprouts.compact.size + @seeds.size)
82
+ value = 1 if value.nan?; progress = sprintf( "%.2f", value)
81
83
  socket_server_send(command,progress,clientaddr,clientport)
82
84
  when :seed
83
85
  socket_server_send(command,@seeds.size,clientaddr,clientport)
@@ -98,10 +100,12 @@ class Garden
98
100
  socket_server_send(command,@sprouts.compact,clientaddr,clientport)
99
101
  when :crop
100
102
  socket_server_send(command,@crops,clientaddr,clientport)
103
+ @crops.clear
101
104
  else
102
105
  if data.is_a? Integer
103
106
  if @crops[data]
104
107
  socket_server_send(command,@crops[data],clientaddr,clientport)
108
+ @crops[data] = nil
105
109
  else
106
110
  @harvest[data] = {:clientaddr => clientaddr, :clientport => clientport}
107
111
  end
data/lib/gardener.rb CHANGED
@@ -20,17 +20,13 @@ class Gardener
20
20
 
21
21
  # The +new+ class method initializes the class.
22
22
  # As part of the Abundance lib, Gardener is not initialized directly,
23
- # but rather through +Abundance.gardener+.
23
+ # but rather through Abundance.gardener.
24
24
  # === Parameters
25
25
  # * :seed_size = allowed seed size in bytes
26
26
  # * :rows = garden rows number, the number of concurent threads
27
27
  # * :init_timeout = allow to pause execution to allow for larger gardens to initialize
28
28
  # === Example
29
- # gardener = Gardener.new({:seed_size => 1024, :rows => 6, :init_timeout => 1}) do
30
- # Abundance.grow do |seed|
31
- # seed.crop(`#{seed.sprout}`)
32
- # end
33
- # end
29
+ # gardener = Gardener.new({:seed_size => 1024, :rows => 6, :init_timeout}) { your_special_garden function }
34
30
  #
35
31
 
36
32
  def initialize(options,gardener_block)
@@ -47,7 +43,7 @@ class Gardener
47
43
  # === Parameter
48
44
  # * _command_ = a ruby expression or object
49
45
  # === Example
50
- # id_seed_1 = gardener.seed('ruby -v')
46
+ # id_seed_1 = gardener.seed(system 'ruby -v')
51
47
 
52
48
  def seed(command)
53
49
  command, data = socket_client_perm_duplex(:seed,command)
@@ -70,17 +66,19 @@ class Gardener
70
66
  return data
71
67
  end
72
68
 
73
- # The +harvest+ method for the Gardener instance allow to get arrays of results for each queue level
69
+ # The +harvest+ method for the Gardener instance allow to get arrays of results for each queue level.
70
+ # It has two different behaviour on queue data, one for ripe elements where it removes them from crop array ( on _seedID_ and :crop invocations ),
71
+ # for all other methods of invocation it leaves the queue intact.
74
72
  # === Parameter
75
73
  # The parameter given as a symbol specifies the level of queue results you wish to get:
76
- # * _seedID_ = return the result for a specific seed, if seed hasn't processed it wait until completed
77
- # * :crop = return an array of seed for which process has completed
74
+ # * seedID = return the result for a specific seed, if seed hasn't processed it wait until completed, _seedID_ is removed from crop array
75
+ # * :crop = return an array of seed for which process has completed, empties the crop array.
78
76
  # * :sprout = return an array of seed actually processing
79
77
  # * :seed = return an array of seed waiting to be processed
80
78
  # * :all = return a hash of respective arrays for crops, sprouts and seeds
81
79
  # === Example
82
- # puts "result is: #{gardener.harvest(id_seed_1)} # => result is: ruby 1.8.6 (2007-09-24 patchlevel 111) [universal-darwin9.0]
83
-
80
+ # seed1_result = gardener.harvest(id_seed_1)
81
+
84
82
  def harvest(crop)
85
83
  command, data = socket_client_perm_duplex(:harvest,crop)
86
84
  return data
data/lib/seed.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # This class provides the seed part of the Gardener,Garden,Seed natural design patern
2
2
  #
3
3
  # In nature, seed is usually small, and so is this class.
4
- # No attributes/variables of itself, its only a kind of localized getter/setter class for
4
+ # No atributes/variables of itself, its only a kind of localized getter/setter class for
5
5
  # the global $seed variable. Every garden row assess one fork-localized $seed variable, and
6
6
  # you get access to it from a +seed+ instance passed to every Abundance.grow iteration.
7
7
  #
@@ -14,7 +14,7 @@ class Seed
14
14
 
15
15
  # The +new+ class method initializes the class.
16
16
  # You don't have to initialize it inside of Abundance,
17
- # as it gets initialized automatically inside the Abundance.grow method
17
+ # as it gets initialized automatically inside the +Abundance.grow+ method
18
18
 
19
19
  # The +sprout+ method for the Seed instance allow to get the passed command
20
20
  # from the inside the Abundance.grow block.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abundance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Louis-Philippe Perron
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-03 00:00:00 -05:00
12
+ date: 2008-12-04 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -26,7 +26,6 @@ files:
26
26
  - lib/garden.rb
27
27
  - lib/gardener.rb
28
28
  - lib/seed.rb
29
- - lib/test.rb
30
29
  - lib/toolshed.rb
31
30
  has_rdoc: true
32
31
  homepage: http://abundance.rubyforge.org/
data/lib/test.rb DELETED
@@ -1,121 +0,0 @@
1
- require 'pty'
2
- require 'expect'
3
- require 'abundance'
4
-
5
- # puts "Init pid #{Process.pid}"
6
- #
7
- # g = Abundance.gardener(:seed_size => 8192, :rows => 1, :init_timeout => 1) do
8
- # puts "Garden init done, pid: #{Process.pid}"
9
- # puts "@@ yield just before growing..."
10
- # Abundance.grow do |seed|
11
- # puts "@@ yield #{Time.now}: got in here"
12
- # puts "@@ yield job: #{seed.sprout}"
13
- # seed.crop(true, "Bravo!!gadigooo!!")
14
- # end
15
- # puts "Garden seeded"
16
- # end
17
- #
18
- # g.seed("jobidoo")
19
- # puts "First chore sent"
20
- # g.seed("jobidaa")
21
- # puts "second chore sent"
22
- # g.seed("jobidob")
23
- # puts "!!!!!!!!!!!!!!!!!!!!!!! growth: #{g.growth}"
24
- # g.seed("jobidoc")
25
- # puts "!!!!!!!!!!!!!!!!!!!!!!! growth: #{g.growth}"
26
- # id = g.seed("jobidod")
27
- # puts "!!!!!!!!!!!!!!!!!!!!!!! growth: #{g.growth}"
28
- # puts "!!!!!!!!!!!!!!!!!!!!!!!!!! waiting for harvest: #{id.class.to_s}"
29
- # har = g.harvest(id)
30
- # puts "!!!!!!!!!!!!!!!!!!!!!!!!!! famous harvest: #{har.inspect}"
31
- # g.seed("jobidoe")
32
- # puts "!!!!!!!!!!!!!!!!!!!!!!! growth: #{g.growth}"
33
- # g.seed("jobidof")
34
- # puts "!!!!!!!!!!!!!!!!!!!!!!! growth: #{g.growth}"
35
- # g.seed("jobidog")
36
- # puts "!!!!!!!!!!!!!!!!!!!!!!! growth: #{g.growth}"
37
- # g.seed("jobidoh")
38
- # puts "!!!!!!!!!!!!!!!!!!!!!!! growth: #{g.growth}"
39
- # g.seed("jobidoi")
40
- # puts "!!! some seeds: #{g.harvest(:seed).inspect}"
41
- # puts "!!! some sprouts: #{g.harvest(:sprout).inspect}"
42
- # puts "!!! some crops: #{g.harvest(:crop).inspect}"
43
- # puts "!!!!!!!!!!!!!!!!!!!!!!! growth: #{g.growth}"
44
- # g.seed("jobidoj")
45
- # puts "!!!!!!!!!!!!!!!!!!!!!!! growth: #{g.growth}"
46
- # g.seed("jobidok")
47
- # puts "!!!!!!!!!!!!!!!!!!!!!!! growth: #{g.growth}"
48
- # g.seed("jobidol")
49
- # puts "!!!!!!!!!!!!!!!!!!!!!!! growth: #{g.growth}"
50
- # g.seed("jobidom")
51
- # puts "!!!!!!!!!!!!!!!!!!!!!!! growth: #{g.growth}"
52
- # g.seed("jobidon")
53
- # g.seed("jobidop")
54
- # g.seed("jobidoq")
55
- # g.seed("jobidor")
56
- # g.seed("jobidos")
57
- # g.seed("jobidot")
58
- # g.seed("jobidou")
59
- # g.seed("jobidov")
60
- # g.seed("jobidow")
61
- # g.seed("jobidox")
62
- # g.seed("jobidoy")
63
- # g.seed("jobidoz")
64
- # puts "!!!!!!!!!!!!!!!!!!!!!!! growth: #{g.growth}"
65
- # sleep 30
66
- # puts "!!! some seeds: #{g.harvest(:seed).inspect}"
67
- # puts "!!! some sprouts: #{g.harvest(:sprout).inspect}"
68
- # puts "!!! some crops: #{g.harvest(:crop).inspect}"
69
- # sleep 5
70
- # puts "!!!!!!!!!!!!!!!!!!!!!!! growth: #{g.growth}"
71
- # fin = g.close
72
- # puts "on close #{fin.inspect}"
73
-
74
- puts "Init pid #{Process.pid}"
75
-
76
- g = Abundance.gardener(:seed_size => 8192, :rows => 1, :init_timeout => 3) do
77
- puts "@@ yield just before growing..."
78
- PTY.spawn('smbclient //spiralgemini/geminishare goLEELAubu -U leelasheel') do |r,w,pid|
79
- w.sync = true
80
- $expect_verbose = false
81
-
82
- r.expect(/.*smb: \\>.*/) do |text|
83
- puts "!!! starter: #{text}"
84
- end
85
- Abundance.grow do |seed|
86
- neew = seed.sprout
87
- puts "??? will go for: #{neew}"
88
- w.print "#{seed.sprout}\n"
89
-
90
- r.expect(/.*smb: \\>/) do |text|
91
- puts "!!! got #{text}"
92
- unless text
93
- r.expect(/.*smb: \\>/) do |text|
94
- puts "!!!2 got #{text}"
95
- seed.crop(true, text)
96
- end
97
- else
98
- seed.crop(true, text)
99
- end
100
-
101
- end
102
- end
103
-
104
- end
105
- end
106
-
107
- puts "Garden seeded"
108
-
109
- g.seed("ls")
110
- puts "First chore sent"
111
- g.seed("pwd")
112
- puts "second chore sent"
113
- g.seed("volume")
114
- g.seed("help")
115
- g.seed("du")
116
- g.seed("put inside.rb")
117
- sleep 20
118
- # r = g.harvest
119
- # puts r.inspect
120
- fin = g.close
121
- puts fin.inspect