Sha256: 1f53be2dfd641954e5c531d241a4b55de18e24166ed5c6c9051e2a7092790e4c

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

require "hot_tub"
require "hot_tub/clients/client"
module HotTub
  class EmSynchronyClient < HotTub::Client 
  
    def initialize(url,options={})
      @url = url
      @options = {:inactivity_timeout => 0}.merge(options)     
      @client = EM::HttpRequest.new(url,options)
    end
    
    def sanitize_hot_tub_client     
      if @client.conn && @client.conn.error?
        HotTub.logger.info "Sanitizing connection : #{EventMachine::report_connection_error_status(@client.conn.instance_variable_get(:@signature))}"
        @client.conn.close_connection
        @client.instance_variable_set(:@deferred, true)
      end
      @client
    end
    
    def close_hot_tub_client
      @client.conn.close_connection if @client.conn
    end
    
    # Default keepalive true for HTTP requests
    [:get,:head,:delete,:put,:post].each do |m|
      define_method m do |options={},&blk|
        options ={} if options.nil?
        options[:keepalive] = true
        @client.send(m,options,&blk)
      end
    end
    
    def dup
      self.class.new(@url,@options)
    end
    
    class << self
      # Use a fiber safe mutex
      def mutex
        EM::Synchrony::Thread::Mutex.new
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hot_tub-0.0.2 lib/hot_tub/clients/em_synchrony_client.rb
hot_tub-0.0.1 lib/hot_tub/clients/em_synchrony_client.rb