Class: PDTP::Server::StatusHandler

Inherits:
Mongrel::HttpHandler
  • Object
show all
Includes:
StatusHelper
Defined in:
lib/pdtp/server/status_handler.rb

Overview

A Mongrel::HttpHandler for generating the status page

Instance Method Summary collapse

Methods included from StatusHelper

#chunks_active, #chunks_completed, #client_count, #cycle, #downstream_bandwidth, #each_file, #each_peer, #each_transfer, #file_path, #peer_address, #peer_name, #percent_complete, #reset_cycle, #transfer_info, #upstream_bandwidth, #vhost

Constructor Details

#initialize(vhost, dispatcher) ⇒ StatusHandler

Returns a new instance of StatusHandler.



36
37
38
39
# File 'lib/pdtp/server/status_handler.rb', line 36

def initialize(vhost, dispatcher)
  @vhost, @dispatcher = vhost, dispatcher
  @status_erb = File.expand_path(File.dirname(__FILE__) + '/../../../status/index.erb')
end

Instance Method Details

#process(request, response) ⇒ Object

Process an incoming request to generate the status page



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/pdtp/server/status_handler.rb', line 42

def process(request, response)
  response.start(200) do |head, out|
    out.write begin
      # Read the status page ERb template
      erb_data = File.read @status_erb
      
      # Render the status ERb template
      html = ERB.new(erb_data).result(binding)
      
      # Call reset_cycle from the StatusHelper to reset cycle() calls
      reset_cycle
      
      # Return output html
      html
    rescue Exception => e
      "Exception: #{e}\n#{e.backtrace.join("\n")}"
    end
  end    
end