Class: Cassandra::Reconnection::Policies::Exponential

Inherits:
Cassandra::Reconnection::Policy show all
Defined in:
lib/cassandra/reconnection/policies/exponential.rb

Overview

A reconnection policy that returns a constant exponentially growing reconnection interval up to a given maximum

Instance Method Summary collapse

Constructor Details

#initialize(start, max, exponent = 2) ⇒ Exponential

Returns a new instance of Exponential.

Examples:

Using this policy

policy   = Cassandra::Reconnection::Policies::Exponential.new(0.5, 10, 2)
schedule = policy.schedule
schedule.next # 0.5
schedule.next # 1.0
schedule.next # 2.0
schedule.next # 4.0
schedule.next # 8.0
schedule.next # 10.0
schedule.next # 10.0
schedule.next # 10.0

Parameters:

  • start (Numeric)

    beginning interval

  • max (Numeric)

    maximum reconnection interval

  • exponent (Numeric) (defaults to: 2)

    (2) interval exponent to use



65
66
67
68
69
# File 'lib/cassandra/reconnection/policies/exponential.rb', line 65

def initialize(start, max, exponent = 2)
  @start    = start
  @max      = max
  @exponent = exponent
end

Instance Method Details

#scheduleCassandra::Reconnection::Schedule

Returns an exponential reconnection schedule.

Returns:



73
74
75
# File 'lib/cassandra/reconnection/policies/exponential.rb', line 73

def schedule
  Schedule.new(@start, @max, @exponent)
end