Class: Ap4r::Mongrel::Ap4rHandler

Inherits:
Mongrel::HttpHandler
  • Object
show all
Defined in:
lib/ap4r/mongrel.rb

Overview

Implements a handler that can run AP4R.

  • If the requested exact PATH_INFO exists as a file then serve it.

+ (Second, access server information or queue/topic API) NOT IMPLEMENTED.

  • Finally, raise an exception.

memo: want to use this handler to take information from AP4R server like mod_status. Message counts and status of threads are useful.

TODO not yet implemented 2007/04/09 by shino

Constant Summary collapse

@@file_only_methods =
["GET","HEAD"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Ap4rHandler

Returns a new instance of Ap4rHandler.



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ap4r/mongrel.rb', line 56

def initialize(options)
  # TODO: needs various modes for easy operations 2007/05/02 by shino
  #        e.g. not to initialize message store, not to start dispatchers, etc.

  # TODO what is "false" here? 2007/04/13 by shinohara
  @files = ::Mongrel::DirHandler.new(options[:docroot], false)
  @tick = Time.now

  # TODO: QueueManager life cycle should be controlled in Configurator? 2007/04/16 by shino
  qm = ::ReliableMsg::QueueManager.new({:config => options[:ap4r_config_file]})
  qm.start
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



53
54
55
# File 'lib/ap4r/mongrel.rb', line 53

def files
  @files
end

Instance Method Details

#log_threads_waiting_for(event) ⇒ Object



86
87
88
89
90
# File 'lib/ap4r/mongrel.rb', line 86

def log_threads_waiting_for(event)
  if Time.now - @tick > 10
    @tick = Time.now
  end
end

#process(request, response) ⇒ Object

  • If the requested exact PATH_INFO exists as a file then serve it.

  • Finally, raise an exception.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ap4r/mongrel.rb', line 71

def process(request, response)
  if response.socket.closed?
    return
  end

  path_info = request.params[Mongrel::Const::PATH_INFO]
  get_or_head = @@file_only_methods.include? request.params[Mongrel::Const::REQUEST_METHOD]
  if get_or_head and @files.can_serve(path_info)
    # File exists as-is so serve it up
    @files.process(request,response)
  else
    raise "No file... Sorry" #TODO set 404 status 2007/04/09 by shino
  end
end

#reload!Object

Does the internal reload for Rails. It might work for most cases, but sometimes you get exceptions. In that case just do a real restart.



94
95
96
97
98
99
# File 'lib/ap4r/mongrel.rb', line 94

def reload!
  begin
    #TODO not implemented 2007/04/09 by shino
    raise "not yet implemented!"
  end
end