Class: Andromeda::Guides::PoolGuide
- Defined in:
- lib/andromeda/pool_guide.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#max_procs ⇒ Object
readonly
Returns the value of attribute max_procs.
-
#pool_track ⇒ Object
readonly
Returns the value of attribute pool_track.
Class Method Summary collapse
-
.num_procs ⇒ Fixnum
Number of processors as determined by Facter.
Instance Method Summary collapse
-
#initialize(num_procs = nil) ⇒ PoolGuide
constructor
A new instance of PoolGuide.
- #pack(plan, track, was_suggested = false) ⇒ Object
- #track(spot, label, suggested_track = nil) ⇒ Object
Methods inherited from Guide
Methods included from Impl::To_S
Constructor Details
#initialize(num_procs = nil) ⇒ PoolGuide
Returns a new instance of PoolGuide.
23 24 25 26 27 28 29 |
# File 'lib/andromeda/pool_guide.rb', line 23 def initialize(num_procs = nil) num_procs = PoolGuide.num_procs unless num_procs raise ArgumentError unless num_procs.is_a?(Fixnum) raise ArgumentError unless num_procs > 0 @max_procs = num_procs @pool_track = PoolTrack.new ThreadPool.new(@max_procs) end |
Instance Attribute Details
#max_procs ⇒ Object (readonly)
Returns the value of attribute max_procs.
6 7 8 |
# File 'lib/andromeda/pool_guide.rb', line 6 def max_procs @max_procs end |
#pool_track ⇒ Object (readonly)
Returns the value of attribute pool_track.
7 8 9 |
# File 'lib/andromeda/pool_guide.rb', line 7 def pool_track @pool_track end |
Class Method Details
.num_procs ⇒ Fixnum
Returns number of processors as determined by Facter.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/andromeda/pool_guide.rb', line 10 def self.num_procs if ENV['NUM_PROCS'] @num_procs = ENV['NUM_PROCS'].to_i end case RUBY_PLATFORM when 'java' @num_procs = java.lang.Runtime.get_runtime.available_processors unless defined?(@num_procs) else @num_procs = Facter.sp_number_processors.strip.to_i unless defined?(@num_procs) end @num_procs end |
Instance Method Details
#pack(plan, track, was_suggested = false) ⇒ Object
36 37 38 39 40 |
# File 'lib/andromeda/pool_guide.rb', line 36 def pack(plan, track, was_suggested = false) return plan if plan.frozen? return plan.identical_copy if was_suggested if max_procs > 1 then plan.identical_copy else plan end end |
#track(spot, label, suggested_track = nil) ⇒ Object
31 32 33 34 |
# File 'lib/andromeda/pool_guide.rb', line 31 def track(spot, label, suggested_track = nil) return suggested_track if suggested_track return @pool_track end |