Class: Ap4r::Carriers

Inherits:
Object show all
Defined in:
lib/ap4r/carrier.rb

Overview

This class aims to balance loads of several reliable-msg servers. Only P2P channells (queues) are considered so far. Now reliable-msg can not be accessed from remote (means “not localhost”). Alpha status now. – TODO: refactoring with dispatcher.rb, around thread group, etc. 2007/05/09 by shino

Instance Method Summary collapse

Constructor Details

#initialize(queue_manager, config, logger, dispatchers) ⇒ Carriers

Returns a new instance of Carriers.



23
24
25
26
27
28
29
# File 'lib/ap4r/carrier.rb', line 23

def initialize(queue_manager, config, logger, dispatchers)
  @qm = queue_manager
  @config = config
  @logger = logger
  @group = ThreadGroup.new
  @dispatchers = dispatchers
end

Instance Method Details

#startObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ap4r/carrier.rb', line 31

def start
  return unless @config
  @logger.info{ "ready to start carrires with config #{@config.to_yaml}" }
  @config.each { |remote|
    remote["threads"].times { |index|
      Thread.fork(@group, remote, index){|group, remote, index|
        carrier_loop(group, remote, index)
      }
    }
  }
  @logger.info{"queue manager has forked all carriers"}
end

#stopObject



44
45
46
47
48
49
# File 'lib/ap4r/carrier.rb', line 44

def stop
  @logger.info{"stop_carriers #{@group}"}
  return unless @group
  @group.list.each{|d| d[:dying] = true}
  @group.list.each{|d| d.join }
end