Class: Andromeda::Guides::PoolGuide

Inherits:
Guide show all
Defined in:
lib/andromeda/pool_guide.rb

Direct Known Subclasses

SharedPoolGuide, SinglePoolGuide

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Guide

#provision

Methods included from Impl::To_S

short_s, #to_s, #to_short_s

Constructor Details

#initialize(num_procs = nil) ⇒ PoolGuide

Returns a new instance of PoolGuide.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
# File 'lib/andromeda/pool_guide.rb', line 15

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_procsObject (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_trackObject (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_procsFixnum

Returns number of processors as determined by Facter.

Returns:

  • (Fixnum)

    number of processors as determined by Facter



10
11
12
13
# File 'lib/andromeda/pool_guide.rb', line 10

def self.num_procs
  @num_procs = Facter.sp_number_processors.strip.to_i unless defined?(@num_procs)
  @num_procs
end

Instance Method Details

#pack(plan, track, was_suggested = false) ⇒ Object



28
29
30
31
32
# File 'lib/andromeda/pool_guide.rb', line 28

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



23
24
25
26
# File 'lib/andromeda/pool_guide.rb', line 23

def track(spot, label, suggested_track = nil)
  return suggested_track if suggested_track
  return @pool_track
end