Class: Garden::Rows

Inherits:
Object
  • Object
show all
Includes:
Paths, Toolshed
Defined in:
lib/rows.rb,
lib/rows_paths.rb

Overview

Author

lp ([email protected])

Copyright

2008 Louis-Philippe Perron - Released under the terms of the MIT license

:title:Rows

Defined Under Namespace

Modules: Paths

Constant Summary

Constants included from Toolshed

Toolshed::SOCKET_ROOT

Instance Attribute Summary collapse

Instance Method Summary collapse

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 Paths

#all, #crop, #init, #quit, #sprout

Constructor Details

#initialize(rows, init_timeout, garden_pid, 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

  • garden_pid = the parent Garden’s pid, for loopback communication purpose

Example

rows = Rows.new(4,2) { grow_block }


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rows.rb', line 43

def initialize(rows,init_timeout,garden_pid,gardener_block)
  @pids = []
  rows.times do
    @pids << fork do
      set_my_socket_as_a(:row,garden_pid)

      t2 = Thread.new do
		t1 = Thread.new do
         gardener_block.call
       end
		
		until nil
          if t1.stop?
				if $seed.nil?
             message_block = socket_duplex([:row,:row,@my_socket_path,@garden_path])
             case message_block[1]
             when :sprout
               sprout(message_block)
             when :all
               all(message_block)
             when :wait
               message_block = socket_recv
               case message_block[1]
               when :sprout
                 sprout(message_block)
               when :all
                 all(message_block)
               when :init
                 init
               when :quit
                 quit
               end
             when :init
               init
             when :quit
               quit
             end
           elsif ! $seed[:success].nil?
             crop
           else
             t1.run
           end
			end
        end
      end
      t2.join
    end
  end
  sleep init_timeout
end

Instance Attribute Details

#pidsObject (readonly)

Returns the value of attribute pids.



27
28
29
# File 'lib/rows.rb', line 27

def pids
  @pids
end