public class TokenAwarePolicy extends Object implements LoadBalancingPolicy
This policy encapsulates another policy. The resulting policy works in the following way:
distance method is inherited from the child policy.newQueryPlan method will first
   return the LOCAL replicas for the query (based on Query.getRoutingKey())
   if possible (i.e. if the query getRoutingKey method
   doesn't return null and if 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 distance
 method returns 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 | 
|---|
TokenAwarePolicy(LoadBalancingPolicy childPolicy)
Creates a new  
TokenAware policy that wraps the provided child
 load balancing policy. | 
| Modifier and Type | Method and Description | 
|---|---|
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(Query query)
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 TokenAwarePolicy(LoadBalancingPolicy childPolicy)
TokenAware policy 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)
LoadBalancingPolicyNote 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.
init in interface LoadBalancingPolicycluster - the Cluster instance for which the policy is created.hosts - the initial hosts to use.public HostDistance distance(Host host)
distance in interface LoadBalancingPolicyhost - the host of which to return the distance of.host as returned by the wrapped policy.public Iterator<Host> newQueryPlan(Query query)
 The returned plan will first return replicas (whose HostDistance
 for the child policy is LOCAL) for the query if it can determine
 them (i.e. mainly if query.getRoutingKey() is not null).
 Following what it will return the plan of the child policy.
newQueryPlan in interface LoadBalancingPolicyquery - the query for which to build the plan.public void onUp(Host host)
Host.StateListeneronUp in interface Host.StateListenerhost - the host that has been detected up.public void onDown(Host host)
Host.StateListeneronDown in interface Host.StateListenerhost - the host that has been detected down.public void onAdd(Host host)
Host.StateListenerThe newly added node should be considered up.
onAdd in interface Host.StateListenerhost - the host that has been newly added.public void onRemove(Host host)
Host.StateListeneronRemove in interface Host.StateListenerhost - the removed host.Copyright © 2014. All Rights Reserved.