class Cassandra::LoadBalancing::Policies::RoundRobin

Public Class Methods

new() click to toggle source
   # File lib/cassandra/load_balancing/policies/round_robin.rb
49 def initialize
50   @hosts    = ::Array.new
51   @position = 0
52 
53   mon_initialize
54 end

Public Instance Methods

distance(host) click to toggle source

Returns distance to host. All hosts in rotation are considered `:local`, all other hosts - `:ignore`.

@param host [Cassandra::Host] a host instance @return [Symbol] `:local` for all hosts in rotation and `:ignore` for

all other hosts.

@see Cassandra::LoadBalancing::Policy#distance

    # File lib/cassandra/load_balancing/policies/round_robin.rb
106 def distance(host)
107   @hosts.include?(host) ? :local : :ignore
108 end
host_down(host) click to toggle source

Removes this host from rotation

@param host [Cassandra::Host] a host instance @return [Cassandra::LoadBalancing::Policies::RoundRobin] self @see Cassandra::Listener#host_down

   # File lib/cassandra/load_balancing/policies/round_robin.rb
72 def host_down(host)
73   synchronize do
74     @hosts = @hosts.dup
75     @hosts.delete(host)
76   end
77 
78   self
79 end
host_found(host) click to toggle source

Noop

@param host [Cassandra::Host] a host instance @return [Cassandra::LoadBalancing::Policies::RoundRobin] self @see Cassandra::Listener#host_found

   # File lib/cassandra/load_balancing/policies/round_robin.rb
86 def host_found(host)
87   self
88 end
host_lost(host) click to toggle source

Noop

@param host [Cassandra::Host] a host instance @return [Cassandra::LoadBalancing::Policies::RoundRobin] self @see Cassandra::Listener#host_lost

   # File lib/cassandra/load_balancing/policies/round_robin.rb
95 def host_lost(host)
96   self
97 end
host_up(host) click to toggle source

Adds this host to rotation

@param host [Cassandra::Host] a host instance @return [Cassandra::LoadBalancing::Policies::RoundRobin] self @see Cassandra::Listener#host_up

   # File lib/cassandra/load_balancing/policies/round_robin.rb
61 def host_up(host)
62   synchronize { @hosts = @hosts.dup.push(host) }
63 
64   self
65 end
inspect() click to toggle source

@private

    # File lib/cassandra/load_balancing/policies/round_robin.rb
133 def inspect
134   "#<#{self.class.name}:0x#{object_id.to_s(16)} " \
135   "hosts=#{@hosts.inspect}, " \
136   "position=#{@position.inspect}>"
137 end
plan(keyspace, statement, options) click to toggle source

Returns a load balancing plan that rotates hosts by 1 each time a plan is requested.

@param keyspace [String] current keyspace of the {Cassandra::Session} @param statement [Cassandra::Statement] actual statement to be

executed

@param options [Cassandra::Execution::Options] execution options to

be used

@return [Cassandra::LoadBalancing::Plan] a rotated load balancing plan @see Cassandra::LoadBalancing::Policy#plan

    # File lib/cassandra/load_balancing/policies/round_robin.rb
120 def plan(keyspace, statement, options)
121   hosts = @hosts
122   total = hosts.size
123 
124   return EMPTY_PLAN if total == 0
125 
126   position  = @position % total
127   @position = position + 1
128 
129   Plan.new(hosts, position)
130 end