Class: Riak::Client::ExconBackend

Inherits:
HTTPBackend show all
Defined in:
lib/riak/client/excon_backend.rb

Overview

An HTTP backend for Riak::Client that uses Wesley Beary’s Excon HTTP library. Conforms to the Riak::Client::HTTPBackend interface.

Constant Summary

Constants included from FeatureDetection

FeatureDetection::VERSION

Instance Attribute Summary

Attributes inherited from HTTPBackend

#client, #node

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HTTPBackend

#delete_file, #delete_object, #fetch_object, #file_exists?, #get_bucket_props, #get_file, #get_index, #initialize, #link_walk, #list_buckets, #list_keys, #mapred, #ping, #reload_object, #search, #set_bucket_props, #stats, #store_file, #store_object, #update_search_index

Methods included from HTTPBackend::Configuration

#bucket_list_path, #bucket_properties_path, #index_eq_path, #index_range_path, #key_list_path, #link_walk_path, #luwak_path, #mapred_path, #object_path, #ping_path, #solr_select_path, #solr_update_path, #stats_path

Methods included from HTTPBackend::ObjectMethods

#load_object, #reload_headers, #store_headers

Methods included from HTTPBackend::TransportMethods

#basic_auth_header, #client_id, #default_headers, #delete, #get, #head, #path, #post, #put, #return_body?, #root_uri, #valid_response?, #verify_body!

Methods included from FeatureDetection

#get_server_version, #mapred_phaseless?, #pb_conditionals?, #pb_head?, #pb_indexes?, #pb_search?, #quorum_controls?, #server_version, #tombstone_vclocks?

Methods included from Util::Translation

#i18n_scope, #t

Methods included from Util::Escape

#escape, #maybe_escape, #maybe_unescape, #unescape

Constructor Details

This class inherits a constructor from Riak::Client::HTTPBackend

Class Method Details

.configured?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
# File 'lib/riak/client/excon_backend.rb', line 11

def self.configured?
  begin
    require 'excon'
    minimum_version?("0.5.7") && register_exceptions && handle_deprecations && patch_sockets
  rescue LoadError
    false
  end
end

.connect_timeoutObject



94
95
96
# File 'lib/riak/client/excon_backend.rb', line 94

def self.connect_timeout
  @connect_timeout ||= 4096
end

.connect_timeout=(timeout) ⇒ Object

Sets the connect timeout applied to the Excon connection Increase this if you have very long request times.



90
91
92
# File 'lib/riak/client/excon_backend.rb', line 90

def self.connect_timeout=(timeout)
  @connect_timeout = timeout
end

.handle_deprecationsObject

Defines instance methods that handle changes in the Excon API across different versions.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/riak/client/excon_backend.rb', line 47

def self.handle_deprecations
  # Define #make_request
  unless method_defined?(:make_request)
    if minimum_version?("0.10.2")
      def make_request(params, block)
        params[:response_block] = block if block
        connection.request(params)
      end
    else
      def make_request(params, block)
        response = connection.request(params, &block)
      end
    end
    private :make_request
  end

  # Define #configure_ssl
  unless method_defined?(:configure_ssl)
    if minimum_version?("0.9.6")
      def configure_ssl
        Excon.defaults[:ssl_verify_peer] = (@node.ssl_options[:verify_mode].to_s === "peer")
        Excon.defaults[:ssl_ca_path]     = @node.ssl_options[:ca_path] if @node.ssl_options[:ca_path]
      end
    else
      def configure_ssl
        Excon.ssl_verify_peer = (@node.ssl_options[:verify_mode].to_s === "peer")
        Excon.ssl_ca_path     = @node.ssl_options[:ca_path] if @node.ssl_options[:ca_path]
      end
    end
    private :configure_ssl
  end
  true
end

.minimum_version?(version) ⇒ Boolean

Returns true if the Excon library is at least the given version. This is used inside the backend to check how to provide certain request and configuration options.

Returns:

  • (Boolean)


84
85
86
# File 'lib/riak/client/excon_backend.rb', line 84

def self.minimum_version?(version)
  Gem::Version.new(Excon::VERSION) >= Gem::Version.new(version)
end

.patch_socketsObject

Note:

This can be changed when Excon has a proper pool of its own.

Adjusts Excon’s connection collection to allow multiple connections to the same host from the same Thread. Instead we use the Riak::Client::Pool to segregate connections.



34
35
36
37
38
39
40
41
42
43
# File 'lib/riak/client/excon_backend.rb', line 34

def self.patch_sockets
  unless defined? @@patched
    ::Excon::Connection.class_eval do
      def sockets
        @sockets ||= {}
      end
    end
  end
  @@patched = true
end

.read_timeoutObject



104
105
106
# File 'lib/riak/client/excon_backend.rb', line 104

def self.read_timeout
  @read_timeout ||= 4096
end

.read_timeout=(timeout) ⇒ Object

Sets the read_timeout applied to the Excon connection Increase this if you have very long request times.



100
101
102
# File 'lib/riak/client/excon_backend.rb', line 100

def self.read_timeout=(timeout)
  @read_timeout = timeout
end

.register_exceptionsObject

Adds Excon’s relevant internal exceptions to the rescuable network-related errors.



22
23
24
25
26
27
28
# File 'lib/riak/client/excon_backend.rb', line 22

def self.register_exceptions
  unless Client::NETWORK_ERRORS.include?(Excon::Errors::SocketError)
    Client::NETWORK_ERRORS << Excon::Errors::SocketError
    Client::NETWORK_ERRORS << Excon::Errors::Timeout if defined? Excon::Errors::Timeout
  end
  true
end

.write_timeoutObject



114
115
116
# File 'lib/riak/client/excon_backend.rb', line 114

def self.write_timeout
  @write_timeout ||= 4096
end

.write_timeout=(timeout) ⇒ Object

Sets the write_timeout applied to the Excon connection Increase this if you have very long request times.



110
111
112
# File 'lib/riak/client/excon_backend.rb', line 110

def self.write_timeout=(timeout)
  @write_timeout = timeout
end

Instance Method Details

#teardownObject



118
119
120
# File 'lib/riak/client/excon_backend.rb', line 118

def teardown
  connection.reset
end