Class TokenAwarePolicy
A wrapper load balancing policy that adds token awareness to a child policy.
This policy encapsulates another policy. The resulting policy works in the following way:
- The Distance(Host) method is inherited from the child policy.
- The host yielded by the NewQueryPlan(string, IStatement) method will first return the Local replicas for the statement, based on the RoutingKey.
Implements
Inherited Members
Namespace: Cassandra
Assembly: Cassandra.dll
Syntax
public class TokenAwarePolicy : ILoadBalancingPolicy
Constructors
TokenAwarePolicy(ILoadBalancingPolicy)
Creates a new TokenAware
policy that wraps the provided child
load balancing policy.
Declaration
public TokenAwarePolicy(ILoadBalancingPolicy childPolicy)
Parameters
Type | Name | Description |
---|---|---|
ILoadBalancingPolicy | childPolicy | the load balancing policy to wrap with token awareness. |
Properties
ChildPolicy
Declaration
public ILoadBalancingPolicy ChildPolicy { get; }
Property Value
Type | Description |
---|---|
ILoadBalancingPolicy |
Methods
Distance(Host)
Return the HostDistance for the provided host.
Declaration
public HostDistance Distance(Host host)
Parameters
Type | Name | Description |
---|---|---|
Host | host | the host of which to return the distance of. |
Returns
Type | Description |
---|---|
HostDistance | the HostDistance to |
Initialize(ICluster)
Initialize this load balancing policy.
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.
Declaration
public void Initialize(ICluster cluster)
Parameters
Type | Name | Description |
---|---|---|
ICluster | cluster | The information about the session instance for which the policy is created. |
NewQueryPlan(string, IStatement)
Returns the hosts to use for a new 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
IStatement.RoutingKey
is not null
). Following what
it will return the plan of the child policy.
Declaration
public IEnumerable<Host> NewQueryPlan(string loggedKeyspace, IStatement query)
Parameters
Type | Name | Description |
---|---|---|
string | loggedKeyspace | Keyspace on which the query is going to be executed |
IStatement | query | the query for which to build the plan. |
Returns
Type | Description |
---|---|
IEnumerable<Host> | the new query plan. |