Class: Cassandra::LoadBalancing::Policies::WhiteList
- Inherits:
-
Cassandra::LoadBalancing::Policy
- Object
- Cassandra::LoadBalancing::Policy
- Cassandra::LoadBalancing::Policies::WhiteList
- Extended by:
- Forwardable
- Defined in:
- lib/cassandra/load_balancing/policies/white_list.rb
Instance Method Summary collapse
-
#distance(host) ⇒ Object
Delegates to wrapped policy.
-
#host_down(host) ⇒ Object
Delegates to wrapped policy if host's ip is whitelisted.
-
#host_found(host) ⇒ Object
Delegates to wrapped policy if host's ip is whitelisted.
-
#host_lost(host) ⇒ Object
Delegates to wrapped policy if host's ip is whitelisted.
-
#host_up(host) ⇒ Object
Delegates to wrapped policy if host's ip is whitelisted.
-
#initialize(ips, wrapped_policy) ⇒ WhiteList
constructor
A new instance of WhiteList.
-
#plan(keyspace, statement, options) ⇒ Object
Delegates to wrapped policy.
Methods inherited from Cassandra::LoadBalancing::Policy
Constructor Details
#initialize(ips, wrapped_policy) ⇒ WhiteList
Returns a new instance of WhiteList.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cassandra/load_balancing/policies/white_list.rb', line 37 def initialize(ips, wrapped_policy) Util.assert_instance_of(::Enumerable, ips) { "ips must be an Enumerable, #{ips.inspect} given" } methods = [:host_up, :host_down, :host_found, :host_lost, :setup, :teardown, :distance, :plan] Util.assert_responds_to_all(methods, wrapped_policy) { "supplied policy must respond to #{methods.inspect}, but doesn't" } @ips = ::Set.new @policy = wrapped_policy ips.each do |ip| case ip when ::IPAddr @ips << ip when ::String @ips << ::IPAddr.new(ip) else raise ::ArgumentError, "each ip must be a String or IPAddr, #{ip.inspect} given" end end end |
Instance Method Details
#distance(host) ⇒ Object
Delegates to wrapped policy
32 |
# File 'lib/cassandra/load_balancing/policies/white_list.rb', line 32 def_delegators :@policy, :plan, :distance |
#host_down(host) ⇒ Object
Delegates to wrapped policy if host's ip is whitelisted
81 82 83 |
# File 'lib/cassandra/load_balancing/policies/white_list.rb', line 81 def host_down(host) @policy.host_down(host) if @ips.include?(host.ip) end |
#host_found(host) ⇒ Object
Delegates to wrapped policy if host's ip is whitelisted
60 61 62 |
# File 'lib/cassandra/load_balancing/policies/white_list.rb', line 60 def host_found(host) @policy.host_found(host) if @ips.include?(host.ip) end |
#host_lost(host) ⇒ Object
Delegates to wrapped policy if host's ip is whitelisted
67 68 69 |
# File 'lib/cassandra/load_balancing/policies/white_list.rb', line 67 def host_lost(host) @policy.host_lost(host) if @ips.include?(host.ip) end |
#host_up(host) ⇒ Object
Delegates to wrapped policy if host's ip is whitelisted
74 75 76 |
# File 'lib/cassandra/load_balancing/policies/white_list.rb', line 74 def host_up(host) @policy.host_up(host) if @ips.include?(host.ip) end |
#plan(keyspace, statement, options) ⇒ Object
Delegates to wrapped policy
32 |
# File 'lib/cassandra/load_balancing/policies/white_list.rb', line 32 def_delegators :@policy, :plan, :distance |