abundance 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/garden_cycles.rb +26 -3
  2. data/lib/gardener.rb +8 -1
  3. metadata +2 -2
data/lib/garden_cycles.rb CHANGED
@@ -37,6 +37,7 @@ class Garden
37
37
  def route_message_blocks
38
38
  until @message_block_queue.empty?
39
39
  message_block = @message_block_queue.shift
40
+
40
41
  case message_block[0]
41
42
  when :seed
42
43
  place_seed_in_queue(message_block)
@@ -54,6 +55,7 @@ class Garden
54
55
  message_block[2] = false
55
56
  add_writable(message_block)
56
57
  end
58
+
57
59
  end
58
60
  end
59
61
 
@@ -61,6 +63,7 @@ class Garden
61
63
  catch :fill_rows do
62
64
  loop do
63
65
  throw :fill_rows if @waiting_rows.empty?
66
+
64
67
  if @seed_all_message_block && @seed_all_message_block[4][:row_done].size != @seed_all_message_block[1]
65
68
  row_socket_path = @waiting_rows.shift
66
69
  unless @seed_all_message_block[4][:row_done].include?( row_socket_path )
@@ -69,6 +72,7 @@ class Garden
69
72
  else
70
73
  @waiting_rows << row_socket_path
71
74
  end
75
+
72
76
  elsif @init_message_block && @init_message_block[4][:row_done].size != @init_message_block[2]
73
77
  row_socket_path = @waiting_rows.shift
74
78
  unless @init_message_block[4][:row_done].include?( row_socket_path )
@@ -77,14 +81,18 @@ class Garden
77
81
  else
78
82
  @waiting_rows << row_socket_path
79
83
  end
84
+
80
85
  elsif ! @seeds.empty?
81
86
  seed = @seeds.shift; @sprouts[seed[:id]] = seed
82
87
  add_writable([:seed,:sprout,seed,@waiting_rows.shift])
88
+
83
89
  elsif @close_message_block && ! @waiting_rows.empty?
84
90
  add_writable([:seed,:quit,nil,@waiting_rows.shift])
91
+
85
92
  else
86
93
  throw :fill_rows
87
- end
94
+ end
95
+
88
96
  end
89
97
  end
90
98
  end
@@ -94,7 +102,7 @@ class Garden
94
102
  def readable_main(i_socket)
95
103
  message_block = read_message_block(i_socket)
96
104
  @message_block_queue << message_block
97
- @reader[:sockets].delete(i_socket) if @reader[:sockets].include?(i_socket)
105
+ @reader[:sockets].delete(i_socket)
98
106
  end
99
107
 
100
108
  def place_seed_in_queue(message_block)
@@ -109,25 +117,33 @@ class Garden
109
117
  end
110
118
 
111
119
  def this_row_is_available(message_block)
120
+
112
121
  if @close_message_block
113
- message_block = [:row, :quit, nil, message_block[3]]
122
+ message_block = [:row, :quit, nil, message_block[3]]
123
+
114
124
  elsif @seed_all_message_block && @seed_all_message_block[4][:row_done].size != @seed_all_message_block[1] && ! @seed_all_message_block[4][:row_done].include?( message_block[3] )
115
125
  message_block = [:row, :all, @seed_all_message_block[2], message_block[3]]
116
126
  @seed_all_message_block[4][:row_done] << message_block[3]
127
+
117
128
  elsif @init_message_block && @init_message_block[4][:row_done].size != @init_message_block[2] && ! @init_message_block[4][:row_done].include?( message_block[3] )
118
129
  message_block = [:row, :init, 'init_status', message_block[3]]
119
130
  @init_message_block[4][:row_done] << message_block[3]
131
+
120
132
  elsif @seeds.empty?
121
133
  @waiting_rows << message_block[2]
122
134
  message_block = [:row, :wait, nil, message_block[3]]
135
+
123
136
  else
124
137
  seed = @seeds.shift; @sprouts[seed[:id]] = seed
125
138
  message_block = [:row, :sprout, seed, message_block[3]]
139
+
126
140
  end
141
+
127
142
  add_writable(message_block)
128
143
  end
129
144
 
130
145
  def save_crop_for(message_block)
146
+
131
147
  case message_block[1]
132
148
  when :harvest
133
149
  @sprouts[message_block[2][:id]] = nil
@@ -139,12 +155,14 @@ class Garden
139
155
  add_writable(message_block[0..1]+[@crops.compact,@full_crop_message_block[3]])
140
156
  @crops.clear; @full_crop_message_block = nil
141
157
  end
158
+
142
159
  when :seed_all
143
160
  @seed_all_message_block[4][:crops] << message_block[2]
144
161
  if @seed_all_message_block[4][:crops].size == @seed_all_message_block[1]
145
162
  @seed_all_message_block[2] = @seed_all_message_block[4][:crops]; @seed_all_message_block[4] = nil
146
163
  add_writable(@seed_all_message_block.compact); @seed_all_message_block = nil
147
164
  end
165
+
148
166
  when :init
149
167
  @init_message_block[4][:crops] << message_block[2]
150
168
  if @init_message_block[4][:crops].size == @init_message_block[2]
@@ -152,9 +170,11 @@ class Garden
152
170
  add_writable(@init_message_block.compact); @init_message_block = nil
153
171
  end
154
172
  end
173
+
155
174
  end
156
175
 
157
176
  def report_growth(message_block)
177
+
158
178
  case message_block[1]
159
179
  when :progress
160
180
  value = @crops.size.to_f / (@crops.size + @sprouts.compact.size + @seeds.size)
@@ -169,10 +189,12 @@ class Garden
169
189
  else
170
190
  message_block[2] = false
171
191
  end
192
+
172
193
  add_writable(message_block)
173
194
  end
174
195
 
175
196
  def harvest_some(message_block)
197
+
176
198
  case message_block[1]
177
199
  when :one
178
200
  unless message_block[2].nil?
@@ -206,6 +228,7 @@ class Garden
206
228
  else
207
229
  message_block[2] = false; add_writable(message_block)
208
230
  end
231
+
209
232
  end
210
233
 
211
234
  def close_all(message_block)
data/lib/gardener.rb CHANGED
@@ -41,7 +41,14 @@ class Gardener
41
41
 
42
42
  set_my_socket_as_a(:gardener,@garden.pid)
43
43
  end
44
-
44
+
45
+ def garden_pid
46
+ @garden.pid
47
+ end
48
+
49
+ def rows_pids
50
+ @garden_rows.pids
51
+ end
45
52
  # The +init_status+ method for the Gardener instance allow to harvest an initialisation status message
46
53
  # that would have been set by the Abundance.init_status method, inside the Abundance.gardener's block.
47
54
  # It returns an array of hash, one hash for each garden rows.
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.3.0
4
+ version: 1.3.1
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: 2009-01-24 00:00:00 -05:00
12
+ date: 2009-01-25 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15