Class: Arrow::DispatcherLoader
- Inherits:
-
Object
- Object
- Arrow::DispatcherLoader
- Defined in:
- lib/arrow/dispatcherloader.rb
Overview
A RubyChildInitHandler
class which loads one or more dispatchers when a child server starts. This can eliminate the startup lag for the first request each child handles. See the docs for dispatcher.rb for an example of how to use this.
Instance Method Summary collapse
-
#child_init(req) ⇒ Object
Load the dispatchers according to the registered hosts file.
-
#initialize(hostsfile) ⇒ DispatcherLoader
constructor
Create a loader that will create dispatchers from the given
hostsfile
, which is a YAML hash that maps dispatcher names to a configfile path.
Constructor Details
#initialize(hostsfile) ⇒ DispatcherLoader
Create a loader that will create dispatchers from the given hostsfile
, which is a YAML hash that maps dispatcher names to a configfile path.
16 17 18 19 20 21 22 |
# File 'lib/arrow/dispatcherloader.rb', line 16 def initialize( hostsfile ) require 'arrow/applet' require 'arrow/dispatcher' require 'arrow/broker' @hostsfile = hostsfile end |
Instance Method Details
#child_init(req) ⇒ Object
Load the dispatchers according to the registered hosts file.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/arrow/dispatcherloader.rb', line 26 def child_init( req ) req.server.log_info( "Loading dispatcher configs from " + @hostsfile + "." ) Arrow::Dispatcher.create_from_hosts_file( @hostsfile ) return Apache::OK rescue ::Exception => err errmsg = "%s failed to load dispatchers (%s): %s: %s" % [ self.class.name, err.class.name, err., err.backtrace.join("\n ") ] logfile = Pathname.new( Dir.tmpdir ) + 'arrow-dispatcher-failure.log' logfile.open( IO::WRONLY|IO::TRUNC|IO::CREAT ) do |ofh| ofh.puts( errmsg ) ofh.flush end Apache.request.server.log_crit( errmsg ) raise end |