Class: Ap4r::Dispatchers
Overview
Represents a group of dispatchers. Responsibilities are follows:
-
polls target queues,
-
gets messages from queues, and
-
calls a
Dispatchers::Base
‘s instance.
Defined Under Namespace
Classes: Base, Druby, Http, SOAP, XmlRpc
Constant Summary collapse
- @@sleep_inverval =
0.1
- @@logger =
nil
- @@subclasses =
storage for
Dispatchers::Base
‘s subclasses. {}
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
Class Method Summary collapse
- .logger ⇒ Object
-
.register_dispatcher_class(mode, klass) ⇒ Object
Stores
klass
for a dispatch modemode
Eachklass
is used to create instances to handle dispatching messages.
Instance Method Summary collapse
-
#initialize(queue_manager, config, logger_obj) ⇒ Dispatchers
constructor
A new instance of Dispatchers.
-
#start ⇒ Object
Starts every dispatcher.
-
#stop ⇒ Object
Stops every dispatcher.
-
#targets ⇒ Object
Sum of each dispatcher’s target queues.
Constructor Details
#initialize(queue_manager, config, logger_obj) ⇒ Dispatchers
Returns a new instance of Dispatchers.
46 47 48 49 50 51 52 53 54 |
# File 'lib/ap4r/dispatcher.rb', line 46 def initialize(queue_manager, config, logger_obj) @qm = queue_manager @config = config # (typically) dispatcher section of queues.cfg @@logger ||= logger_obj raise "no configuration specified" unless @config @group = ThreadGroup.new # TODO: needs refinement 2007/05/30 by shino @dispatch_targets = "" end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
24 25 26 |
# File 'lib/ap4r/dispatcher.rb', line 24 def config @config end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
24 25 26 |
# File 'lib/ap4r/dispatcher.rb', line 24 def group @group end |
Class Method Details
.logger ⇒ Object
28 29 30 |
# File 'lib/ap4r/dispatcher.rb', line 28 def self.logger @@logger end |
.register_dispatcher_class(mode, klass) ⇒ Object
Stores klass
for a dispatch mode mode
Each klass
is used to create instances to handle dispatching messages.
37 38 39 |
# File 'lib/ap4r/dispatcher.rb', line 37 def self.register_dispatcher_class(mode, klass) @@subclasses[mode] = klass end |
Instance Method Details
#start ⇒ Object
Starts every dispatcher. If an exception is detected, this method raise it through with logging.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ap4r/dispatcher.rb', line 59 def start begin logger.info{ "about to start dispatchers with config\n#{@config.to_yaml}" } @config.each{ |conf| conf["threads"].to_i.times { |index| Thread.fork(@group, conf, index){|group, conf, index| dispatching_loop(group, conf, index) } } @dispatch_targets.concat(conf["targets"]).concat(';') logger.debug{ "dispatch targets are : #{@dispatch_targets}" } } logger.info "queue manager has forked dispatchers" rescue Exception => err logger.warn{"Error in starting dipatchers #{err}"} logger.warn{err.backtrace.join("\n")} raise err end end |
#stop ⇒ Object
Stops every dispatcher. Current implementation makes just dying flags up. Some threads don’t stop quickly in some cases such as blocking at socket read. – TODO: needs forced mode? 2007/05/09 by shino
84 85 86 87 88 89 90 |
# File 'lib/ap4r/dispatcher.rb', line 84 def stop logger.info{"stop_dispatchers #{@group}"} return unless @group @group.list.each {|d| d[:dying] = true} @group.list.each {|d| d.join } @dispatch_targets = "" end |
#targets ⇒ Object
Sum of each dispatcher’s target queues.
42 43 44 |
# File 'lib/ap4r/dispatcher.rb', line 42 def targets @dispatch_targets end |