In Files

Parent

Methods

Class Index

Quicksearch

Arrow::DispatcherLoader

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.

Public Class Methods

new( hostsfile ) click to toggle source

Create a loader that will create dispatchers from the given hostsfile, which is a YAML hash that maps dispatcher names to a configfile path.

    # File lib/arrow.rb, line 81
81:         def initialize( hostsfile )
82:             @hostsfile = hostsfile
83:         end

Public Instance Methods

child_init( req ) click to toggle source

Load the dispatchers according to the registered hosts file.

     # File lib/arrow.rb, line 87
 87:         def child_init( req )
 88:             req.server.log_info( "Loading dispatcher configs from " + @hostsfile + "." )
 89:             Arrow::Dispatcher.create_from_hosts_file( @hostsfile )
 90: 
 91:             return Apache::OK
 92:         rescue ::Exception => err
 93:             errmsg = "%s failed to load dispatchers (%s): %s: %s" % [
 94:                 self.class.name,
 95:                 err.class.name,
 96:                 err.message,
 97:                 err.backtrace.join("\n  ")
 98:             ]
 99: 
100:             logfile = Pathname.new( Dir.tmpdir ) + 'arrow-dispatcher-failure.log'
101:             logfile.open( IO::WRONLY|IO::TRUNC|IO::CREAT ) do |ofh|
102:                 ofh.puts( errmsg )
103:                 ofh.flush
104:             end
105: 
106:             Apache.request.server.log_crit( errmsg )
107:             raise
108:         end

secsequence

--- SEC00184

seccomment

--- ""

method_list

--- 
- methods: 
  - visibility: public
    aref: M000344
    name: new
    sourcecode: "    <span class=\"ruby-comment cmt\"># File lib/arrow.rb, line 81</span>\n\
      81:         <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize</span>( <span class=\"ruby-identifier\">hostsfile</span> )\n\
      82:             <span class=\"ruby-ivar\">@hostsfile</span> = <span class=\"ruby-identifier\">hostsfile</span>\n\
      83:         <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Create a loader that will create dispatchers from the given
      <tt>hostsfile</tt>, which is a YAML hash that maps dispatcher names to a
      configfile path.
      </p>
    params: ( hostsfile )
  category: Class
  type: Public
- methods: 
  - visibility: public
    aref: M000345
    name: child_init
    sourcecode: "     <span class=\"ruby-comment cmt\"># File lib/arrow.rb, line 87</span>\n 87:         <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">child_init</span>( <span class=\"ruby-identifier\">req</span> )\n 88:             <span class=\"ruby-identifier\">req</span>.<span class=\"ruby-identifier\">server</span>.<span class=\"ruby-identifier\">log_info</span>( <span class=\"ruby-value str\">&quot;Loading dispatcher configs from &quot;</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-ivar\">@hostsfile</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-value str\">&quot;.&quot;</span> )\n 89:             <span class=\"ruby-constant\">Arrow</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Dispatcher</span>.<span class=\"ruby-identifier\">create_from_hosts_file</span>( <span class=\"ruby-ivar\">@hostsfile</span> )\n 90: \n 91:             <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-constant\">Apache</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">OK</span>\n 92:         <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Exception</span> =<span class=\"ruby-operator\">&gt;</span> <span class=\"ruby-identifier\">err</span>\n 93:             <span class=\"ruby-identifier\">errmsg</span> = <span class=\"ruby-value str\">&quot;%s failed to load dispatchers (%s): %s: %s&quot;</span> <span class=\"ruby-operator\">%</span> [\n 94:                 <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">class</span>.<span class=\"ruby-identifier\">name</span>,\n 95:                 <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">class</span>.<span class=\"ruby-identifier\">name</span>,\n 96:                 <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">message</span>,\n 97:                 <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">backtrace</span>.<span class=\"ruby-identifier\">join</span>(<span class=\"ruby-value str\">&quot;\\n  &quot;</span>)\n 98:             ]\n 99: \n\
      100:             <span class=\"ruby-identifier\">logfile</span> = <span class=\"ruby-constant\">Pathname</span>.<span class=\"ruby-identifier\">new</span>( <span class=\"ruby-constant\">Dir</span>.<span class=\"ruby-identifier\">tmpdir</span> ) <span class=\"ruby-operator\">+</span> <span class=\"ruby-value str\">'arrow-dispatcher-failure.log'</span>\n\
      101:             <span class=\"ruby-identifier\">logfile</span>.<span class=\"ruby-identifier\">open</span>( <span class=\"ruby-constant\">IO</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">WRONLY</span><span class=\"ruby-operator\">|</span><span class=\"ruby-constant\">IO</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">TRUNC</span><span class=\"ruby-operator\">|</span><span class=\"ruby-constant\">IO</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">CREAT</span> ) <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">ofh</span><span class=\"ruby-operator\">|</span>\n\
      102:                 <span class=\"ruby-identifier\">ofh</span>.<span class=\"ruby-identifier\">puts</span>( <span class=\"ruby-identifier\">errmsg</span> )\n\
      103:                 <span class=\"ruby-identifier\">ofh</span>.<span class=\"ruby-identifier\">flush</span>\n\
      104:             <span class=\"ruby-keyword kw\">end</span>\n\
      105: \n\
      106:             <span class=\"ruby-constant\">Apache</span>.<span class=\"ruby-identifier\">request</span>.<span class=\"ruby-identifier\">server</span>.<span class=\"ruby-identifier\">log_crit</span>( <span class=\"ruby-identifier\">errmsg</span> )\n\
      107:             <span class=\"ruby-identifier\">raise</span>\n\
      108:         <span class=\"ruby-keyword kw\">end</span>"
    m_desc: |-
      <p>
      Load the dispatchers according to the registered hosts file.
      </p>
    params: ( req )
  category: Instance
  type: Public

sectitle

--- 

[Validate]

Generated with the Darkfish Rdoc Generator.