abundance 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/garden.rb CHANGED
@@ -40,30 +40,31 @@ class Garden
40
40
  loop do
41
41
  seed_if_row_available
42
42
 
43
- command, data, client_socket_path = socket_recv
44
- case command
43
+ message_block = socket_recv
44
+ case message_block[0]
45
45
  when :seed
46
- place_seed_in_queue(command,data,client_socket_path)
46
+ place_seed_in_queue(message_block)
47
47
  when :row
48
- this_row_is_available(command,data,client_socket_path)
48
+ this_row_is_available(message_block)
49
49
  when :crop
50
- save_crop_for(command,data,client_socket_path)
50
+ save_crop_for(message_block)
51
51
  when :growth
52
- report_growth(command,data,client_socket_path)
52
+ report_growth(message_block)
53
53
  when :harvest
54
- harvest_some(command,data,client_socket_path)
54
+ harvest_some(message_block)
55
55
  when :init
56
- ask_for_init_status(command,data,client_socket_path)
56
+ ask_for_init_status(message_block)
57
57
  when :init_crop
58
- answer_init_status(command,data,client_socket_path)
58
+ answer_init_status(message_block)
59
59
  when :seed_all
60
- seed_for_all_rows(command,data,client_socket_path)
60
+ seed_for_all_rows(message_block)
61
61
  when :seed_all_crop
62
- special_crop_seed_all(command,data,client_socket_path)
62
+ special_crop_seed_all(message_block)
63
63
  when :close
64
- close_all(command,data,client_socket_path)
64
+ close_all(message_block)
65
65
  else
66
- socket_send(command,false,client_socket_path)
66
+ message_block[2] = false
67
+ socket_send(message_block)
67
68
  end
68
69
  end
69
70
  end
data/lib/garden_cycles.rb CHANGED
@@ -16,7 +16,7 @@ class Garden
16
16
  if ! @seed_all.nil? && ! @rows_socket_paths.empty? && @seed_all_done.size != @seed_all[0]
17
17
  row_socket_path = @rows_socket_paths.shift
18
18
  unless @seed_all_done.include?( row_socket_path )
19
- socket_send(:seed_all,@seed_all[1],row_socket_path)
19
+ socket_send(:seed_all,:garden,@seed_all[1],row_socket_path)
20
20
  @seed_all_done << row_socket_path
21
21
  else
22
22
  @rows_socket_paths << row_socket_path
@@ -24,7 +24,7 @@ class Garden
24
24
  elsif ! @do_init.nil? && ! @rows_socket_paths.empty? && @init_done.size != @do_init
25
25
  row_socket_path = @rows_socket_paths.shift
26
26
  unless @init_done.include?( row_socket_path )
27
- socket_send(:init,'init_status',row_socket_path)
27
+ socket_send(:init,:garden,'init_status',row_socket_path)
28
28
  @init_done << row_socket_path
29
29
  else
30
30
  @rows_socket_paths << row_socket_path
@@ -33,11 +33,11 @@ class Garden
33
33
  seed = @seeds.shift
34
34
  @sprouts[seed[:id]] = seed
35
35
  row_socket_path = @rows_socket_paths.shift
36
- socket_send(:sprout,seed,row_socket_path)
36
+ socket_send(:sprout,:garden,seed,row_socket_path)
37
37
  elsif @quit && ! @rows_socket_paths.empty?
38
38
  seed = nil
39
39
  row_socket_path = @rows_socket_paths.shift
40
- socket_send(:quit,seed,row_socket_path)
40
+ socket_send(:quit,:garden,seed,row_socket_path)
41
41
  else
42
42
  throw :fill_rows
43
43
  end
@@ -45,118 +45,119 @@ class Garden
45
45
  end
46
46
  end
47
47
 
48
- def place_seed_in_queue(command,data,client_socket_path)
49
- @id += 1; @seeds << {:id => @id , :seed => data}
50
- socket_send(command,@id,client_socket_path)
48
+ def place_seed_in_queue(message_block)
49
+ @id += 1; @seeds << {:id => @id , :seed => message_block[2]}
50
+ socket_send(message_block[0],:garden,@id,message_block[3])
51
51
  end
52
52
 
53
- def this_row_is_available(command,data,client_socket_path)
53
+ def this_row_is_available(message_block)
54
54
  if @quit
55
- command = :quit; seed = nil
55
+ message_block[0] = :quit; seed = nil
56
56
  elsif @seeds.empty?
57
- seed = nil; @rows_socket_paths << data
57
+ seed = nil; @rows_socket_paths << message_block[2]
58
58
  else
59
59
  seed = @seeds.shift; @sprouts[seed[:id]] = seed
60
60
  end
61
- socket_send(command,seed,client_socket_path)
61
+ socket_send(message_block[0],:garden,seed,message_block[3])
62
62
  end
63
63
 
64
- def save_crop_for(command,data,client_socket_path)
65
- @sprouts[data[:id]] = nil; @crops[data[:id]] = data
66
- if @harvest[data[:id]]
67
- socket_send(command,data, @harvest[data[:id]][:client_socket_path])
68
- @crops[data[:id]] = @harvest[data[:id]] = nil
64
+ def save_crop_for(message_block)
65
+ @sprouts[message_block[2][:id]] = nil
66
+ @crops[message_block[2][:id]] = message_block[2]
67
+ if @harvest[message_block[2][:id]]
68
+ socket_send(message_block[0],:garden,message_block[2], @harvest[message_block[2][:id]][:client_socket_path])
69
+ @crops[message_block[2][:id]] = @harvest[message_block[2][:id]] = nil
69
70
  elsif @full_crop && @seeds.compact.empty? && @sprouts.compact.empty?
70
- socket_send(command,@crops.compact,@mem_client_socket_path)
71
+ socket_send(message_block[0],:garden,@crops.compact,@mem_client_socket_path)
71
72
  @crops.clear; @full_crop = false
72
73
  end
73
74
  end
74
75
 
75
- def report_growth(command,data,client_socket_path)
76
- case data
76
+ def report_growth(message_block)
77
+ case message_block[2]
77
78
  when :progress
78
79
  value = @crops.size.to_f / (@crops.size + @sprouts.compact.size + @seeds.size)
79
80
  value = 1 if value.nan?; progress = sprintf( "%.2f", value)
80
- socket_send(command,progress,client_socket_path)
81
+ socket_send(message_block[0],:garden,progress,message_block[3])
81
82
  when :seed
82
- socket_send(command,@seeds.size,client_socket_path)
83
+ socket_send(message_block[0],:garden,@seeds.size,message_block[3])
83
84
  when :sprout
84
- socket_send(command,@sprouts.compact.size,client_socket_path)
85
+ socket_send(message_block[0],:garden,@sprouts.compact.size,message_block[3])
85
86
  when :crop
86
- socket_send(command,@crops.size,client_socket_path)
87
+ socket_send(message_block[0],:garden,@crops.size,message_block[3])
87
88
  else
88
- socket_send(command,false,client_socket_path)
89
+ socket_send(message_block[0],:garden,false,message_block[3])
89
90
  end
90
91
  end
91
92
 
92
- def harvest_some(command,data,client_socket_path)
93
- case data
93
+ def harvest_some(message_block)
94
+ case message_block[2]
94
95
  when :all
95
- socket_send(command,{:seeds => @seeds, :sprouts => @sprouts.compact, :crops => @crops.compact},client_socket_path)
96
+ socket_send(message_block[0],:garden,{:seeds => @seeds, :sprouts => @sprouts.compact, :crops => @crops.compact},message_block[3])
96
97
  when :seed
97
- socket_send(command,@seeds,client_socket_path)
98
+ socket_send(message_block[0],:garden,@seeds,message_block[3])
98
99
  when :sprout
99
- socket_send(command,@sprouts.compact,client_socket_path)
100
+ socket_send(message_block[0],:garden,@sprouts.compact,message_block[3])
100
101
  when :crop
101
- socket_send(command,@crops.compact,client_socket_path)
102
+ socket_send(message_block[0],:garden,@crops.compact,message_block[3])
102
103
  @crops.clear
103
104
  when :full_crop
104
105
  if @seeds.compact.empty? && @sprouts.compact.empty?
105
- socket_send(command,@crops.compact,client_socket_path)
106
+ socket_send(message_block[0],:garden,@crops.compact,message_block[3])
106
107
  @crops.clear
107
108
  else
108
109
  @full_crop = true
109
- @mem_client_socket_path = client_socket_path
110
+ @mem_client_socket_path = message_block[3]
110
111
  end
111
112
  else
112
- if data.is_a? Integer
113
- if @crops[data]
114
- socket_send(command,@crops[data],client_socket_path)
115
- @crops[data] = nil
113
+ if message_block[2].is_a? Integer
114
+ if @crops[message_block[2]]
115
+ socket_send(message_block[0],:garden,@crops[message_block[2]],message_block[3])
116
+ @crops[message_block[2]] = nil
116
117
  else
117
- @harvest[data] = {:client_socket_path => client_socket_path}
118
+ @harvest[message_block[2]] = {:client_socket_path => message_block[3]}
118
119
  end
119
120
  else
120
- socket_send(command,false,client_socket_path)
121
+ socket_send(message_block[0],:garden,false,message_block[3])
121
122
  end
122
123
  end
123
124
  end
124
125
 
125
- def ask_for_init_status(command,data,client_socket_path)
126
- @do_init = data
127
- @init_return = {:client_socket_path => client_socket_path}
126
+ def ask_for_init_status(message_block)
127
+ @do_init = message_block[2]
128
+ @init_return = {:client_socket_path => message_block[3]}
128
129
  end
129
130
 
130
- def answer_init_status(command,data,client_socket_path)
131
- @init_all_crop << data
131
+ def answer_init_status(message_block)
132
+ @init_all_crop << message_block[2]
132
133
  if @init_all_crop.size == @do_init
133
- socket_send(command,@init_all_crop, @init_return[:client_socket_path])
134
+ socket_send(message_block[0],:garden,@init_all_crop, @init_return[:client_socket_path])
134
135
  @init_return = Hash.new; @init_done = Array.new; @do_init = nil; @init_all_crop = Array.new
135
136
  end
136
137
  end
137
138
 
138
- def seed_for_all_rows(command,data,client_socket_path)
139
- @seed_all = data
140
- @seed_all_return = {:client_socket_path => client_socket_path, :data => []}
139
+ def seed_for_all_rows(message_block)
140
+ @seed_all = message_block[2]
141
+ @seed_all_return = {:client_socket_path => message_block[3], :data => []}
141
142
  end
142
143
 
143
- def special_crop_seed_all(command,data,client_socket_path)
144
- @seed_all_crop << data
144
+ def special_crop_seed_all(message_block)
145
+ @seed_all_crop << message_block[2]
145
146
  if @seed_all_crop.size == @seed_all[0]
146
- socket_send(command,@seed_all_crop, @seed_all_return[:client_socket_path])
147
+ socket_send(message_block[0],:garden,@seed_all_crop, @seed_all_return[:client_socket_path])
147
148
  @seed_all = nil; @seed_all_return = Hash.new; @seed_all_done = Array.new; @seed_all_crop = Array.new
148
149
  end
149
150
  end
150
151
 
151
- def close_all(command,data,client_socket_path)
152
- if data[:level] == :garden
153
- @seeds_pid = data[:pid]
152
+ def close_all(message_block)
153
+ if message_block[2][:level] == :garden
154
+ @seeds_pid = message_block[2][:pid]
154
155
  @quit = true
155
- @mem_client_socket_path = client_socket_path
156
+ @mem_client_socket_path = message_block[3]
156
157
  else
157
- @seeds_pid.delete(data[:pid].to_i)
158
+ @seeds_pid.delete(message_block[2][:pid].to_i)
158
159
  if @seeds_pid.empty?
159
- socket_send(:close,{:seeds => @seeds, :sprouts => @sprouts.compact, :crops => @crops.compact}, @mem_client_socket_path)
160
+ socket_send(:close,:garden,{:seeds => @seeds, :sprouts => @sprouts.compact, :crops => @crops.compact}, @mem_client_socket_path)
160
161
  exit
161
162
  end
162
163
  end
data/lib/garden_rows.rb CHANGED
@@ -51,32 +51,32 @@ class Garden
51
51
  t2 = Thread.new do
52
52
  loop do
53
53
  if $seed.nil?
54
- command, data = socket_duplex(:row,my_socket_path)
55
- if command == :quit
54
+ message_block = socket_duplex(:row,:row,my_socket_path)
55
+ if message_block[0] == :quit
56
56
  pid = Process.pid
57
- socket_send(:close,{:level => :seed, :pid => pid})
57
+ socket_send(:close,:row,{:level => :seed, :pid => pid})
58
58
  exit
59
59
  end
60
- $seed = data
60
+ $seed = message_block[2]
61
61
  if $seed.nil?
62
- command, data, client_socket_path = socket_recv
63
- case command
62
+ message_block = socket_recv
63
+ case message_block[0]
64
64
  when :sprout
65
- $seed = data
65
+ $seed = message_block[2]
66
66
  when :seed_all
67
67
  @seed_all = true
68
- $seed = {:id => Process.pid, :seed => data}
68
+ $seed = {:id => Process.pid, :seed => message_block[2]}
69
69
  when :init
70
70
  $init = {:seed => 'init_status', :message => 'No Init Message', :id => Process.pid} if $init.nil?
71
- socket_send(:init_crop,$init)
71
+ socket_send(:init_crop,:row,$init)
72
72
  end
73
73
  end
74
74
  elsif ! $seed[:success].nil?
75
75
  if @seed_all
76
- socket_send(:seed_all_crop,$seed)
76
+ socket_send(:seed_all_crop,:row,$seed)
77
77
  @seed_all = false
78
78
  else
79
- socket_send(:crop,$seed)
79
+ socket_send(:crop,:row,$seed)
80
80
  end
81
81
  $seed = nil;
82
82
  else
data/lib/gardener.rb CHANGED
@@ -48,38 +48,38 @@ class Gardener
48
48
  # === Example
49
49
  # puts gardener.init_status.inspect # => [{:message=>"init ok", :success=>true, :pid=>4760}, {:message=>"init failed", :success=>false, :pid=>4761}]
50
50
  def init_status
51
- command, data = socket_duplex(:init,@garden_rows.pids.size)
52
- data.map! do |row|
51
+ message_block = socket_duplex(:init,:gardener,@garden_rows.pids.size)
52
+ message_block[2].map! do |row|
53
53
  {:success => row[:success], :message => row[:message], :pid => row[:id]}
54
54
  end
55
- return data
55
+ return message_block[2]
56
56
  end
57
57
 
58
58
  # The +seed+ method for the Gardener instance allow to sow a command in the Gardener's Garden.
59
59
  # === Parameter
60
- # * _command_ = a ruby expression or object
60
+ # * _data_ = a ruby expression or object
61
61
  # === Example
62
62
  # id_seed_1 = gardener.seed("system 'ruby -v'")
63
63
 
64
- def seed(command)
65
- command, data = socket_duplex(:seed,command)
66
- return data
64
+ def seed(data)
65
+ message_block = socket_duplex(:seed,:gardener,data)
66
+ return message_block[2]
67
67
  end
68
68
 
69
69
  # The +seed_all+ method allow to send a command to all row processes, usefull for a parameter change
70
70
  # that needs to affect the prefered behaviour of all row. It returns an array containing hashes for each rows results.
71
71
  # === Parameter
72
- # * _command_ = a ruby expression or object
72
+ # * _data_ = a ruby expression or object
73
73
  # === Example
74
74
  # result = gardener.seed_all("pref local") # => [{:success=>true, :message=>["row pref changed to local"], :seed=>"pref local", :pid=>14915},
75
75
  # {:success=>true, :message=>["row pref changed to local"], :seed=>"pref local", :pid=>14913}]
76
- def seed_all(command)
77
- seed = [@garden_rows.pids.size, command]
78
- command, data = socket_duplex(:seed_all, seed)
79
- data.map! do |row|
76
+ def seed_all(data)
77
+ seed = [@garden_rows.pids.size, data]
78
+ message_block = socket_duplex(:seed_all,:gardener,seed)
79
+ message_block[2].map! do |row|
80
80
  {:success => row[:success], :message => row[:message], :pid => row[:id]}
81
81
  end
82
- return data
82
+ return message_block[2]
83
83
  end
84
84
 
85
85
  # The +growth+ method for the Gardener instance allow to get report of the growing process
@@ -93,9 +93,9 @@ class Gardener
93
93
  # progress = gardener.growth(:progress)
94
94
  # puts "progress is now #{progress}" # => progress is now 0.75
95
95
 
96
- def growth(crop=:progress)
97
- command, data = socket_duplex(:growth,crop)
98
- return data
96
+ def growth(data=:progress)
97
+ message_block = socket_duplex(:growth,:gardener,data)
98
+ return message_block[2]
99
99
  end
100
100
 
101
101
  # The +harvest+ method for the Gardener instance allow to get arrays of results for each queue level.
@@ -112,9 +112,9 @@ class Gardener
112
112
  # === Example
113
113
  # seed1_result = gardener.harvest(id_seed_1)
114
114
 
115
- def harvest(crop)
116
- command, data = socket_duplex(:harvest,crop)
117
- return data
115
+ def harvest(data)
116
+ message_block = socket_duplex(:harvest,:gardener,data)
117
+ return message_block[2]
118
118
  end
119
119
 
120
120
  # The +close+ method for the Gardener instance allow to safely close the Garden and its Rows.
@@ -123,8 +123,8 @@ class Gardener
123
123
  # final_harvest = gardener.close
124
124
 
125
125
  def close
126
- command, data = socket_duplex(:close,{:level => :garden, :pid => @garden_rows.pids})
127
- return data
126
+ message_block = socket_duplex(:close,:gardener,{:level => :garden, :pid => @garden_rows.pids})
127
+ return message_block[2]
128
128
  end
129
129
 
130
130
  end
data/lib/toolshed.rb CHANGED
@@ -52,8 +52,8 @@ module Toolshed
52
52
  # * _command_ = command part of the sent packet
53
53
  # * _data_ = data part of the sent packet
54
54
  # * _server_socket_path_ = a UNIXServer socket path for the packets to be sent to
55
- def socket_send(command,data,server_socket_path=@garden_path)
56
- send_block(command,data,server_socket_path)
55
+ def socket_send(command,option,data,server_socket_path=@garden_path)
56
+ send_block(command,option,data,server_socket_path)
57
57
  end
58
58
 
59
59
  # The +socket_duplex+ method open a UNIXSocket and send packets to a UNIXServer socket, then wait for loopback communication from destination and return results like +socket_recv+.
@@ -61,8 +61,8 @@ module Toolshed
61
61
  # * _command_ = command part of the sent packet
62
62
  # * _data_ = data part of the sent packet
63
63
  # * _server_socket_path_ = a UNIXServer socket path for the packets to be sent to
64
- def socket_duplex(command,data,server_socket_path=@garden_path)
65
- send_block(command,data,server_socket_path)
64
+ def socket_duplex(command,option,data,server_socket_path=@garden_path)
65
+ send_block(command,option,data,server_socket_path)
66
66
  Marshal.load(recv_whole_block)
67
67
  end
68
68
 
@@ -121,10 +121,10 @@ module Toolshed
121
121
  # * _command_ = command part of the sent packet
122
122
  # * _data_ = data part of the sent packet
123
123
  # * _server_socket_path_ = the UNIXServer socket path to send to
124
- def send_block(command,data,server_socket_path)
124
+ def send_block(command,option,data,server_socket_path)
125
125
  begin
126
126
  client = UNIXSocket.open(server_socket_path)
127
- client.send(Marshal.dump([command,data,@my_socket_path]),0)
127
+ client.send(Marshal.dump([command,option,data,@my_socket_path]),0)
128
128
  client.close
129
129
  rescue Errno::EADDRINUSE
130
130
  retry
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.2.2
4
+ version: 1.2.3
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-13 00:00:00 -05:00
12
+ date: 2009-01-14 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15