Class: Garden::Rows
Overview
:title:Rows
Constant Summary
Constants included from Toolshed
Instance Attribute Summary collapse
-
#pids ⇒ Object
readonly
Returns the value of attribute pids.
Instance Method Summary collapse
-
#initialize(rows, init_timeout, gardener_block) ⇒ Rows
constructor
The
new
class method initializes the Rows.
Methods included from Toolshed
available_port, block_size, block_size=, garden_port, garden_port=, socket_client_perm, #socket_client_perm_duplex, #socket_client_perm_send, socket_client_temp, #socket_client_temp, socket_server, #socket_server_recv, #socket_server_send
Constructor Details
#initialize(rows, init_timeout, gardener_block) ⇒ Rows
The new
class method initializes the Rows. As part of the Abundance lib, Rows is not initialized directly, but rather as a side effect of the Gardener’s initialization, through the rows
Garden instance method. Its instance resides in the @garden_rows Gardener’s instance variable. Its real muscles are inaccessibles from instance method intervention, because of its nature as a forked Ruby process.
Parameter
-
rows = garden rows number, the number of concurent threads
-
init_timeout = allow to pause execution to allow for larger garden rows to initialize
Example
rows = Rows.new(4,2) { grow_block }
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/garden.rb', line 166 def initialize(rows,init_timeout,gardener_block) @pids = [] rows.times do row_port = Toolshed.available_port @pids << fork do @socket_server = Toolshed.socket_server(row_port) t1 = Thread.new do gardener_block.call end t2 = Thread.new do @socket_client_perm = Toolshed.socket_client_perm loop do if $seed.nil? command, data = socket_client_perm_duplex(:row,row_port) if command == :quit pid = Process.pid socket_client_perm_send(:close,{:level => :seed, :pid => pid}) exit end $seed = data if $seed.nil? command, data, clientport, clientname, clientaddr = socket_server_recv $seed = data end elsif $seed.include?(:success) command, data = socket_client_perm_duplex(:crop,$seed) $seed = nil else t1.run end end end t2.join end end sleep init_timeout end |
Instance Attribute Details
#pids ⇒ Object (readonly)
Returns the value of attribute pids.
151 152 153 |
# File 'lib/garden.rb', line 151 def pids @pids end |