class Cassandra::Execution::Profile
A profile is a collection of settings to use when executing and preparing statements. Register different profiles when creating the {Cassandra::Cluster} and execute/prepare statements with a particular profile by providing its name to the relevant method in {Session}.
@see Cassandra.cluster
@see Session#execute_async
@see Session#execute
@see Session#prepare_async
@see Session#prepare
Constants
- DEFAULT_OPTIONS
@private
Attributes
@return [Symbol] consistency level with which to run statements.
@return [Cassandra::LoadBalancing::Policy] load-balancing policy that determines which node will run the
next statement.
@return [Cassandra::Retry::Policy] retry policy that determines how request retries should be handled for
different failure modes.
@return [Numeric] request execution timeout in seconds. `nil` means there is no timeout.
Public Class Methods
@param options [Hash] hash of attributes. Unspecified attributes fall back to system defaults. @option options [Numeric] :timeout (12) Request execution timeout in
seconds. Setting value to `nil` will remove request timeout.
@option options [Cassandra::LoadBalancing::Policy] :load_balancing_policy (
LoadBalancing::Policies::TokenAware(LoadBalancing::Policies::DCAwareRoundRobin)) Load-balancing policy that determines which node will run the next statement.
@option options [Cassandra::Retry::Policy] :retry_policy (Retry::Policies::Default
) Retry
policy that
determines how request retries should be handled for different failure modes.
@option options [Symbol] :consistency (:local_one) Consistency level with which to run statements. Must be one
of {Cassandra::CONSISTENCIES}.
# File lib/cassandra/execution/profile.rb 58 def initialize(options = {}) 59 validate(options) 60 options = DEFAULT_OPTIONS.merge(options) 61 @load_balancing_policy = options[:load_balancing_policy] || 62 LoadBalancing::Policies::TokenAware.new( 63 LoadBalancing::Policies::DCAwareRoundRobin.new, 64 true) 65 @retry_policy = options[:retry_policy] || Retry::Policies::Default.new 66 @consistency = options[:consistency] 67 @timeout = options[:timeout] 68 end
Public Instance Methods
@private
# File lib/cassandra/execution/profile.rb 81 def eql?(other) 82 other.is_a?(Profile) && \ 83 @load_balancing_policy == other.load_balancing_policy && \ 84 @retry_policy == other.retry_policy && \ 85 @consistency == other.consistency && \ 86 @timeout == other.timeout 87 end
@private
# File lib/cassandra/execution/profile.rb 91 def hash 92 @hash ||= begin 93 h = 17 94 h = 31 * h + @load_balancing_policy.hash 95 h = 31 * h + @retry_policy.hash 96 h = 31 * h + @consistency.hash 97 h = 31 * h + @timeout.hash 98 h 99 end 100 end
@private
# File lib/cassandra/execution/profile.rb 103 def inspect 104 "#<#{self.class.name}:0x#{object_id.to_s(16)} " \ 105 "load_balancing_policy=#{@load_balancing_policy.inspect}, " \ 106 "retry_policy=#{@retry_policy.inspect}, " \ 107 "consistency=#{@consistency.inspect}, " \ 108 "timeout=#{@timeout.inspect}>" 109 end
@private
# File lib/cassandra/execution/profile.rb 71 def to_h 72 { 73 load_balancing_policy: @load_balancing_policy, 74 retry_policy: @retry_policy, 75 consistency: @consistency, 76 timeout: @timeout 77 } 78 end
@private
# File lib/cassandra/execution/profile.rb 112 def validate(options) 113 if options.key?(:timeout) 114 timeout = options[:timeout] 115 116 unless timeout.nil? 117 Util.assert_instance_of(::Numeric, 118 timeout, 119 ":timeout must be a number of seconds, 120 #{timeout.inspect} given") 121 Util.assert(timeout > 0, ":timeout must be greater than 0, #{timeout} given") 122 end 123 end 124 125 if options.key?(:load_balancing_policy) 126 load_balancing_policy = options[:load_balancing_policy] 127 methods = [:host_up, :host_down, :host_found, :host_lost, :setup, :teardown, 128 :distance, :plan] 129 Util.assert_responds_to_all(methods, load_balancing_policy) do 130 ":load_balancing_policy #{load_balancing_policy.inspect} must respond " \ 131 "to #{methods.inspect}, but doesn't" 132 end 133 end 134 135 if options.key?(:retry_policy) 136 retry_policy = options[:retry_policy] 137 methods = [:read_timeout, :write_timeout, :unavailable] 138 Util.assert_responds_to_all(methods, retry_policy) do 139 ":retry_policy #{retry_policy.inspect} must respond to #{methods.inspect}, " \ 140 "but doesn't" 141 end 142 end 143 144 if options.key?(:consistency) 145 consistency = options[:consistency] 146 Util.assert_one_of(CONSISTENCIES, consistency, 147 ":consistency must be one of #{CONSISTENCIES.inspect}, " \ 148 "#{consistency.inspect} given") 149 end 150 end