public class TokenAwarePolicy extends Object implements LoadBalancingPolicy
This policy encapsulates another policy. The resulting policy works in the following way:
distancemethod is inherited from the child policy.
newQueryPlanmethod will first return the
LOCALreplicas for the query (based on
Query.getRoutingKey()) if possible (i.e. if the query
getRoutingKeymethod doesn't return
Metadata.getReplicas(java.nio.ByteBuffer)returns a non empty set of replicas for that partition key). If no local replica can be either found or successfully contacted, the rest of the query plan will fallback to one of the child policy.
Do note that only replica for which the child policy
HostDistance.LOCAL will be considered having
priority. For example, if you wrap
DCAwareRoundRobinPolicy with this
token aware policy, replicas from remote data centers may only be
returned after all the host of the local data center.
|Constructor and Description|
Creates a new
|Modifier and Type||Method and Description|
Return the HostDistance for the provided host.
Initialize this load balancing policy.
Returns the hosts to use for a new query.
Called when a new node is added to the cluster.
Called when a node is determined to be down.
Called when a node is removed from the cluster.
Called when a node is determined to be up.
public TokenAwarePolicy(LoadBalancingPolicy childPolicy)
TokenAwarepolicy that wraps the provided child load balancing policy.
childPolicy- the load balancing policy to wrap with token awareness.
public void init(Cluster cluster, Collection<Host> hosts)
Note that the driver guarantees that it will call this method exactly once per policy object and will do so before any call to another of the methods of the policy.
public HostDistance distance(Host host)
The returned plan will first return replicas (whose
for the child policy is
LOCAL) for the query if it can determine
them (i.e. mainly if
query.getRoutingKey() is not
Following what it will return the plan of the child policy.
public void onUp(Host host)
public void onDown(Host host)
public void onAdd(Host host)
The newly added node should be considered up.
Copyright © 2014. All Rights Reserved.