Class | Hookout::ReverseHttpConnector |
In: |
lib/hookout/reversehttp_connector.rb
|
Parent: | Object |
DEFAULT_SERVER | = | 'http://localhost:8000/reversehttp' |
DEFAULT_LABEL | = | 'ruby' |
failure_delay | [RW] | |
lease_seconds | [RW] | |
location_change_callback | [RW] | |
report_poll_exceptions | [RW] |
# File lib/hookout/reversehttp_connector.rb, line 11 def initialize(label, server_address, handler) @label = label @server_address = server_address @handler = handler @next_req = nil @location = nil @failure_delay = 2 @token = '-' @lease_seconds = 30 @report_poll_exceptions = false @location_change_callback = nil @closed = false @requestor = Hookout::Utils.new end
# File lib/hookout/reversehttp_connector.rb, line 47 def next_request until @closed declare_mode = (@next_req == nil) begin response = nil if declare_mode response = @requestor.post_form @server_address, {:name => @label, :token => @token} else response = @requestor.get @next_req end return nil if response.nil? @failure_delay = 2 if declare_mode link_headers = parse_link_headers(response) @next_req = link_headers['first'] location_text = link_headers['related'] if location_text @location = location_text on_location_changed() end elsif response['Requesting-Client'] client_addr = response['Requesting-Client'].split(":") this_req = @next_req @next_req = parse_link_headers(response)['next'] return [ReverseHttpRequest.new(this_req, @server_address, response.body), client_addr] end rescue if @report_poll_exceptions report_poll_exception end sleep(@failure_delay) unless @closed if @failure_delay < 30 @failure_delay = @failure_delay * 2 end end end end