Class: Abundance
- Inherits:
-
Object
- Object
- Abundance
- Defined in:
- lib/abundance.rb
Class Method Summary collapse
-
.gardener(options = {:wheelbarrow => 8192, :rows => 2, :init_timeout => 2}, &gardener_block) ⇒ Object
The
gardener
class method initializes a gardener instance with its garden supplied as a block. -
.grow(&grow_block) ⇒ Object
The
grow
class method needs to be used inside the gardener invocation. -
.init_status(success, message) ⇒ Object
The
init_status
class method can be used inside the gardener invocation to return an initialisation status message.
Class Method Details
.gardener(options = {:wheelbarrow => 8192, :rows => 2, :init_timeout => 2}, &gardener_block) ⇒ Object
The gardener
class method initializes a gardener instance with its garden supplied as a block. The invocation block must include the grow
class method and a preceeding optional initialisation section that may include and init_status
return message.
Parameters
-
:wheelbarrow = the socket size for the garden communication packets, in bytes, up to 8192, defaults to 124
-
:rows = garden rows number, the number of concurent threads
-
:init_timeout = allow to pause execution to allow for larger gardens to initialize
Example
gardener = Abundance.gardener( :wheelbarrow => 124, :rows => 2, :init_timeout => 2) do
processor = SpecialProcess.new
if processor.started_successfully?
Abundance.init_status(true, processor.)
else
Abundance.init_status(false, processor.)
end
Abundance.grow do |seed|
command = seed.sprout
results = processor.parse(command)
seed.crop( true, results)
end
end
id1 = gardener.seed('command1')
id2 = gardener.seed('command2')
result1 = gardener.harvest(:one,id1)
result2 = gardener.harvest(:one,id2)
# with many more seeds over here
gardener.close
83 84 85 86 |
# File 'lib/abundance.rb', line 83 def Abundance.gardener(={:wheelbarrow => 8192, :rows => 2, :init_timeout => 2},&gardener_block) $log_abundance.debug("Abundance.gardener") {"options: #{.inspect}"} return Gardener.new(,gardener_block) end |
.grow(&grow_block) ⇒ Object
The grow
class method needs to be used inside the gardener invocation. A seed instance is given each time, acting as getter/setter for your queued seed commands
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/abundance.rb', line 91 def Abundance.grow(&grow_block) until nil $log_abundance.debug("Abundance.grow") {"enter loop"} unless $seed.nil? || $seed.include?(:message) $log_abundance.debug("Abundance.grow") {"call grow block for seed: #{$seed.inspect}"} grow_block.call(Seed.new) end Thread.stop end end |
.init_status(success, message) ⇒ Object
The init_status
class method can be used inside the gardener invocation to return an initialisation status message. The returned messages from all garden rows will then be accessible though the gardener’s init_status instance method.
Parameters
-
success = success of the initialisation, may be true or false
-
message = a ruby expression or object
Example
Abundance.init_status(true,'Initialisation Successfull!!!')
109 110 111 112 |
# File 'lib/abundance.rb', line 109 def Abundance.init_status(success,) $log_abundance.debug("Abundance.init_status") { "success: #{success.inspect} message: #{.inspect}"} $init = {:id => Process.pid, :seed => 'init_status', :success => success, :message => } end |