systems.composable.dropwizard.cassandra.loadbalancing.LatencyAwarePolicyFactory 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
The newest version!
package systems.composable.dropwizard.cassandra.loadbalancing;
import com.datastax.driver.core.policies.LatencyAwarePolicy;
import com.datastax.driver.core.policies.LoadBalancingPolicy;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.dropwizard.util.Duration;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
/**
* A factory for configuring and building {@link com.datastax.driver.core.policies.LatencyAwarePolicy} instances.
*
* Configuration Parameters:
*
*
* Name
* Default
* Description
*
*
* subPolicy
* No default. You must provide a child policy.
* The child policy that the resulting policy wraps.
*
*
* exclusionThreshold
* No default.
* The exclusion threshold to use for the resulting latency aware policy.
*
*
* minimumMeasurements
* No default.
* The minimum number of measurements per-host to consider for the resulting latency aware policy.
*
*
* retryPeriod
* No default.
* The retry period for the resulting latency aware policy.
*
*
* scale
* No default.
* The scale to use for the resulting latency aware policy.
*
*
* updateRate
* No default.
* The update rate for the resulting latency aware policy.
*
*
*/
@JsonTypeName("latencyAware")
public class LatencyAwarePolicyFactory implements LoadBalancingPolicyFactory {
@Valid
@NotNull
private LoadBalancingPolicyFactory subPolicy;
private Double exclusionThreshold;
private Integer minimumMeasurements;
private Duration retryPeriod;
private Duration scale;
private Duration updateRate;
@JsonProperty
public LoadBalancingPolicyFactory getSubPolicy() {
return subPolicy;
}
@JsonProperty
public void setSubPolicy(LoadBalancingPolicyFactory subPolicy) {
this.subPolicy = subPolicy;
}
@JsonProperty
public Double getExclusionThreshold() {
return exclusionThreshold;
}
@JsonProperty
public void setExclusionThreshold(Double exclusionThreshold) {
this.exclusionThreshold = exclusionThreshold;
}
@JsonProperty
public Integer getMinimumMeasurements() {
return minimumMeasurements;
}
@JsonProperty
public void setMinimumMeasurements(Integer minimumMeasurements) {
this.minimumMeasurements = minimumMeasurements;
}
@JsonProperty
public Duration getRetryPeriod() {
return retryPeriod;
}
@JsonProperty
public void setRetryPeriod(Duration retryPeriod) {
this.retryPeriod = retryPeriod;
}
@JsonProperty
public Duration getScale() {
return scale;
}
@JsonProperty
public void setScale(Duration scale) {
this.scale = scale;
}
@JsonProperty
public Duration getUpdateRate() {
return updateRate;
}
@JsonProperty
public void setUpdateRate(Duration updateRate) {
this.updateRate = updateRate;
}
@Override
public LoadBalancingPolicy build() {
LatencyAwarePolicy.Builder builder = LatencyAwarePolicy.builder(subPolicy.build());
if (exclusionThreshold != null) {
builder.withExclusionThreshold(exclusionThreshold);
}
if (minimumMeasurements != null) {
builder.withMininumMeasurements(minimumMeasurements);
}
if (retryPeriod != null) {
builder.withRetryPeriod(retryPeriod.getQuantity(), retryPeriod.getUnit());
}
if (scale != null) {
builder.withScale(scale.getQuantity(), scale.getUnit());
}
if (updateRate != null) {
builder.withUpdateRate(updateRate.getQuantity(), updateRate.getUnit());
}
return builder.build();
}
}