public class DCAwareRoundRobinPolicy extends Object implements LoadBalancingPolicy
RoundRobinPolicy
, but its DC awareness incurs a slight overhead
so the latter should be preferred to this policy in that case.Modifier and Type | Class and Description |
---|---|
static class |
DCAwareRoundRobinPolicy.Builder
Helper class to build the policy.
|
Modifier and Type | Method and Description |
---|---|
static DCAwareRoundRobinPolicy.Builder |
builder()
Returns a builder to create a new instance.
|
void |
close()
Gets invoked at cluster shutdown.
|
HostDistance |
distance(Host host)
Return the HostDistance for the provided host.
|
void |
init(Cluster cluster,
Collection<Host> hosts)
Initialize this load balancing policy.
|
Iterator<Host> |
newQueryPlan(String loggedKeyspace,
Statement statement)
Returns the hosts to use for a new query.
|
void |
onAdd(Host host)
Called when a new node is added to the cluster.
|
void |
onDown(Host host)
Called when a node is determined to be down.
|
void |
onRemove(Host host)
Called when a node is removed from the cluster.
|
void |
onUp(Host host)
Called when a node is determined to be up.
|
public static DCAwareRoundRobinPolicy.Builder builder()
public void init(Cluster cluster, Collection<Host> hosts)
LoadBalancingPolicy
init
in interface LoadBalancingPolicy
cluster
- the Cluster
instance for which the policy is created.hosts
- the initial hosts to use.public HostDistance distance(Host host)
LOCAL
.
For each remote datacenter, it considers a configurable number of
hosts as REMOTE
and the rest is IGNORED
.
To configure how many hosts in each remote datacenter should be considered,
see DCAwareRoundRobinPolicy.Builder.withUsedHostsPerRemoteDc(int)
.distance
in interface LoadBalancingPolicy
host
- the host of which to return the distance of.host
.public Iterator<Host> newQueryPlan(String loggedKeyspace, Statement statement)
newQueryPlan
in interface LoadBalancingPolicy
loggedKeyspace
- the keyspace currently logged in on for this
query.statement
- the query for which to build the plan.public void onUp(Host host)
LoadBalancingPolicy
onUp
in interface LoadBalancingPolicy
host
- the host that has been detected up.public void onDown(Host host)
LoadBalancingPolicy
onDown
in interface LoadBalancingPolicy
host
- the host that has been detected down.public void onAdd(Host host)
LoadBalancingPolicy
onAdd
in interface LoadBalancingPolicy
host
- the host that has been newly added.public void onRemove(Host host)
LoadBalancingPolicy
onRemove
in interface LoadBalancingPolicy
host
- the removed host.public void close()
LoadBalancingPolicy
close
in interface LoadBalancingPolicy
Copyright © 2012–2018. All rights reserved.