systems.composable.dropwizard.cassandra.loadbalancing.TokenAwarePolicyFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dropwizard-cassandra Show documentation
Show all versions of dropwizard-cassandra Show documentation
Cassandra library for Dropwizard
package systems.composable.dropwizard.cassandra.loadbalancing;
import com.datastax.driver.core.policies.LoadBalancingPolicy;
import com.datastax.driver.core.policies.TokenAwarePolicy;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
/**
* A factory for configuring and building {@link com.datastax.driver.core.policies.TokenAwarePolicy} instances.
*
* Configuration Parameters:
*
*
* Name
* Default
* Description
*
*
* subPolicy
* No default. You must provide a child policy.
* The load balancing policy to wrap with token awareness.
*
*
* shuffleReplicas
* No default.
* Whether to shuffle the replicas returned by getRoutingKey.
*
*
*/
@JsonTypeName("tokenAware")
public class TokenAwarePolicyFactory implements LoadBalancingPolicyFactory {
@Valid
@NotNull
private LoadBalancingPolicyFactory subPolicy;
private Boolean shuffleReplicas;
@JsonProperty
public LoadBalancingPolicyFactory getSubPolicy() {
return subPolicy;
}
@JsonProperty
public void setSubPolicy(LoadBalancingPolicyFactory subPolicy) {
this.subPolicy = subPolicy;
}
@JsonProperty
public Boolean getShuffleReplicas() {
return shuffleReplicas;
}
@JsonProperty
public void setShuffleReplicas(Boolean shuffleReplicas) {
this.shuffleReplicas = shuffleReplicas;
}
@Override
public LoadBalancingPolicy build() {
return (shuffleReplicas == null)
? new TokenAwarePolicy(subPolicy.build())
: new TokenAwarePolicy(subPolicy.build(), shuffleReplicas);
}
}