Class: ThinkingSphinx::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/thinking_sphinx/connection.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnection

Returns a new instance of Connection.



29
30
31
# File 'lib/thinking_sphinx/connection.rb', line 29

def initialize
  client.open
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *arguments, &block) ⇒ Object (private)



57
58
59
# File 'lib/thinking_sphinx/connection.rb', line 57

def method_missing(method, *arguments, &block)
  client.send method, *arguments, &block
end

Class Method Details

.poolObject



2
3
4
5
6
7
# File 'lib/thinking_sphinx/connection.rb', line 2

def self.pool
  @pool ||= Innertube::Pool.new(
    Proc.new { Rails.logger.debug '>>> CONNECTING <<<'; ThinkingSphinx::Connection.new },
    Proc.new { |connection| connection.close }
  )
end

.takeObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/thinking_sphinx/connection.rb', line 9

def self.take
  retries  = 0
  original = nil
  begin
    pool.take do |connection|
      connection.reset
      begin
        yield connection
      rescue Riddle::ConnectionError, Riddle::ResponseError => error
        original = error
        raise Innertube::Pool::BadResource
      end
    end
  rescue Innertube::Pool::BadResource
    retries += 1
    retry if retries < 3
    raise original
  end
end

Instance Method Details

#clientObject



33
34
35
36
37
38
39
40
41
# File 'lib/thinking_sphinx/connection.rb', line 33

def client
  @client ||= begin
    client = Riddle::Client.new shuffled_addresses, configuration.port,
      client_key
    client.max_matches = _max_matches
    client.timeout     = configuration.timeout || 0
    client
  end
end