Class: Cassandra::LoadBalancing::Policies::RoundRobin
- Inherits:
-
Cassandra::LoadBalancing::Policy
- Object
- Cassandra::LoadBalancing::Policy
- Cassandra::LoadBalancing::Policies::RoundRobin
- Includes:
- MonitorMixin
- Defined in:
- lib/cassandra/load_balancing/policies/round_robin.rb
Instance Method Summary collapse
-
#distance(host) ⇒ Symbol
Returns distance to host.
-
#host_down(host) ⇒ Cassandra::LoadBalancing::Policies::RoundRobin
Removes this host from rotation.
-
#host_found(host) ⇒ Cassandra::LoadBalancing::Policies::RoundRobin
Noop.
-
#host_lost(host) ⇒ Cassandra::LoadBalancing::Policies::RoundRobin
Noop.
-
#host_up(host) ⇒ Cassandra::LoadBalancing::Policies::RoundRobin
Adds this host to rotation.
-
#initialize ⇒ RoundRobin
constructor
A new instance of RoundRobin.
-
#plan(keyspace, statement, options) ⇒ Cassandra::LoadBalancing::Plan
Returns a load balancing plan that rotates hosts by 1 each time a plan is requested.
Methods inherited from Cassandra::LoadBalancing::Policy
Constructor Details
#initialize ⇒ RoundRobin
Returns a new instance of RoundRobin.
49 50 51 52 53 54 |
# File 'lib/cassandra/load_balancing/policies/round_robin.rb', line 49 def initialize @hosts = ::Array.new @position = 0 mon_initialize end |
Instance Method Details
#distance(host) ⇒ Symbol
Returns distance to host. All hosts in rotation are considered
:local
, all other hosts - :ignore
.
106 107 108 |
# File 'lib/cassandra/load_balancing/policies/round_robin.rb', line 106 def distance(host) @hosts.include?(host) ? :local : :ignore end |
#host_down(host) ⇒ Cassandra::LoadBalancing::Policies::RoundRobin
Removes this host from rotation
72 73 74 75 76 77 78 79 |
# File 'lib/cassandra/load_balancing/policies/round_robin.rb', line 72 def host_down(host) synchronize do @hosts = @hosts.dup @hosts.delete(host) end self end |
#host_found(host) ⇒ Cassandra::LoadBalancing::Policies::RoundRobin
Noop
86 87 88 |
# File 'lib/cassandra/load_balancing/policies/round_robin.rb', line 86 def host_found(host) self end |
#host_lost(host) ⇒ Cassandra::LoadBalancing::Policies::RoundRobin
Noop
95 96 97 |
# File 'lib/cassandra/load_balancing/policies/round_robin.rb', line 95 def host_lost(host) self end |
#host_up(host) ⇒ Cassandra::LoadBalancing::Policies::RoundRobin
Adds this host to rotation
61 62 63 64 65 |
# File 'lib/cassandra/load_balancing/policies/round_robin.rb', line 61 def host_up(host) synchronize { @hosts = @hosts.dup.push(host) } self end |
#plan(keyspace, statement, options) ⇒ Cassandra::LoadBalancing::Plan
Returns a load balancing plan that rotates hosts by 1 each time a plan is requested.
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/cassandra/load_balancing/policies/round_robin.rb', line 120 def plan(keyspace, statement, ) hosts = @hosts total = hosts.size return EMPTY_PLAN if total == 0 position = @position % total @position = position + 1 Plan.new(hosts, position) end |