Class: Garden
- Inherits:
-
Object
- Object
- Garden
- Defined in:
- lib/garden.rb,
lib/rows.rb,
lib/rows_paths.rb,
lib/garden_cycles.rb
Overview
These classes provides the garden part of the Gardener,Garden,Seed natural design patern
The Garden is where the thread concurency is implemented, offering itself as a thread queue manager, dispatching seeds from the Gardener to its Rows child class and back again. it does so using its child class, the Rows. Since Ruby doesn’t implement Native Threads, and only Native Threads scales to multi-core execution, the way to implement concurent execution is through splitting the task at hand between multiple single threaded parallel executions. The Rows system does exactly that, using the Ruby fork function, then connecting the isolated running processes to the Garden, through a simple socket system provided by the Toolshed Module.
- Author
-
lp ([email protected])
- Copyright
-
2008 Louis-Philippe Perron - Released under the terms of the MIT license
:title:Garden
Defined Under Namespace
Constant Summary
Constants included from Toolshed
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
-
#initialize ⇒ Garden
constructor
The
new
class method initializes the Garden. -
#rows(rows, init_timeout, grow_block) ⇒ Object
The
rows
method for the Garden instance allow instantiation of its child Rows.
Methods included from Toolshed
#add_readable, #add_writable, block_size=, #my_socket_path, #read_message_block, #read_raw, #remove_writable, #set_my_socket_as_a, #socket_duplex, #socket_recv, #socket_send, #write_raw
Methods included from Cycles
#crop_writable, #route_message_blocks, #seed_available_rows, #set_my_containers, #sprout_readable
Constructor Details
#initialize ⇒ Garden
The new
class method initializes the Garden. As part of the Abundance lib, Garden is not initialized directly, but rather as a side effect of the Gardener’s initialization. Its instance resides in the @garden Gardener’s instance variable. Its real muscles are inaccessibles from instance method intervention, because of its nature as a forked Ruby process.
Example
garden = Garden.new
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/garden.rb', line 35 def initialize @pid = fork do set_my_containers set_my_socket_as_a(:garden) loop do seed_available_rows ready = select(@reader[:sockets],@writer[:sockets],nil,10) unless ready.nil? readable, writable = ready[0..1] crop_writable(writable) if writable sprout_readable(readable) if readable end end end end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
24 25 26 |
# File 'lib/garden.rb', line 24 def pid @pid end |
Instance Method Details
#rows(rows, init_timeout, grow_block) ⇒ Object
The rows
method for the Garden instance allow instantiation of its child Rows. As part of the Abundance lib, Garden.rows is not invoked directly, but rather as a side effect of the Gardener’s initialization. Its in reality an indirect initializer for the Rows class.
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 = garden.rows(4,2) { grow_block }
14 15 16 |
# File 'lib/rows.rb', line 14 def rows(rows,init_timeout,grow_block) Rows.new(rows,init_timeout,@pid,grow_block) end |