class Cassandra::Cluster::Options

@private

Attributes

auth_provider[R]
compressor[R]
connect_timeout[R]
credentials[R]
custom_type_handlers[R]
heartbeat_interval[R]
idle_timeout[R]
port[R]
protocol_version[RW]
schema_refresh_delay[R]
schema_refresh_timeout[R]
ssl[R]

Public Class Methods

new(logger, protocol_version, credentials, auth_provider, compressor, port, connect_timeout, ssl, connections_per_local_node, connections_per_remote_node, heartbeat_interval, idle_timeout, synchronize_schema, schema_refresh_delay, schema_refresh_timeout, nodelay, requests_per_connection, custom_types, allow_beta_protocol) click to toggle source
   # File lib/cassandra/cluster/options.rb
32 def initialize(logger,
33                protocol_version,
34                credentials,
35                auth_provider,
36                compressor,
37                port,
38                connect_timeout,
39                ssl,
40                connections_per_local_node,
41                connections_per_remote_node,
42                heartbeat_interval,
43                idle_timeout,
44                synchronize_schema,
45                schema_refresh_delay,
46                schema_refresh_timeout,
47                nodelay,
48                requests_per_connection,
49                custom_types,
50                allow_beta_protocol)
51   @logger                 = logger
52   @protocol_version       = protocol_version
53   @credentials            = credentials
54   @auth_provider          = auth_provider
55   @compressor             = compressor
56   @port                   = port
57   @connect_timeout        = connect_timeout
58   @ssl                    = ssl
59   @heartbeat_interval     = heartbeat_interval
60   @idle_timeout           = idle_timeout
61   @synchronize_schema     = synchronize_schema
62   @schema_refresh_delay   = schema_refresh_delay
63   @schema_refresh_timeout = schema_refresh_timeout
64   @nodelay                = nodelay
65   @allow_beta_protocol    = allow_beta_protocol
66   @custom_type_handlers   = {}
67   custom_types.each do |type_klass|
68     @custom_type_handlers[type_klass.type] = type_klass
69   end
70 
71   @connections_per_local_node  = connections_per_local_node
72   @connections_per_remote_node = connections_per_remote_node
73   @requests_per_connection = requests_per_connection
74 
75   # If @protocol_version is nil, it means we want the driver to negotiate the
76   # protocol starting with our known max. If @protocol_version is not nil,
77   # it means the user wants us to use a particular version, so we should not
78   # support negotiation.
79 
80   @protocol_negotiable = @protocol_version.nil?
81   @protocol_version ||= allow_beta_protocol ?
82       Cassandra::Protocol::Versions::BETA_VERSION :
83       Cassandra::Protocol::Versions::MAX_SUPPORTED_VERSION
84 end

Public Instance Methods

compression() click to toggle source
   # File lib/cassandra/cluster/options.rb
86 def compression
87   @compressor && @compressor.algorithm
88 end
connections_per_local_node() click to toggle source
    # File lib/cassandra/cluster/options.rb
103 def connections_per_local_node
104   # Return the option if set.
105   return @connections_per_local_node if @connections_per_local_node
106 
107   # For v3 and later, default is 1 local connection.
108   # For v2 and earlier, default is 2 local connections.
109   # Return the default
110   (@protocol_version > 2) ? 1 : 2
111 end
connections_per_remote_node() click to toggle source
    # File lib/cassandra/cluster/options.rb
113 def connections_per_remote_node
114   # Return the option if set; otherwise return the default (1).
115   @connections_per_remote_node || 1
116 end
create_authenticator(authentication_class, host) click to toggle source
    # File lib/cassandra/cluster/options.rb
 90 def create_authenticator(authentication_class, host)
 91   if @auth_provider
 92     # Auth providers should take an auth-class and host, but they used to not, so for backward compatibility
 93     # we figure out if this provider does, and if so send both args, otherwise just send the auth-class.
 94 
 95     if @auth_provider.method(:create_authenticator).arity == 1
 96       @auth_provider.create_authenticator(authentication_class)
 97     else
 98       @auth_provider.create_authenticator(authentication_class, host)
 99     end
100   end
101 end
requests_per_connection() click to toggle source
    # File lib/cassandra/cluster/options.rb
118 def requests_per_connection
119   # There are a few possibilities here based on @requests_per_connection:
120   # nil: default to 1024 for protocol 3 and later, 128 for < 3.
121   # we're in v2 and value too high: return 128. We don't worry
122   #   about this case for v3+ because option validation in
123   #   Cassandra::cluster_async takes care of that.
124   # good value: return it.
125   #
126   # NOTE: We can't compute and cache the result because protocol_version
127   # can change over time in theory (if all nodes are upgraded to a new
128   # version of Cassandra)
129 
130   # Return the default if option wasn't specified.
131   default_requests_per_connection = @protocol_version > 2 ? 1024 : 128
132   return default_requests_per_connection unless @requests_per_connection
133 
134   if @requests_per_connection > 128 && @protocol_version < 3
135     @logger.warn(
136       ":requests_per_connection setting of #{@requests_per_connection} is more " \
137           'than the max of 128 for protocol v2. Falling back to 128.'
138     )
139     return 128
140   end
141   @requests_per_connection
142 end