systems.composable.dropwizard.cassandra.loadbalancing.ErrorAwarePolicyFactory 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.ErrorAwarePolicy;
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 ErrorAwarePolicy} instances.
*
* Configuration Parameters:
*
*
* Name
* Default
* Description
*
*
* subPolicy
* No default. You must provide a child policy.
* The load balancing policy to wrap with error awareness.
*
*
* maxErrorsPerMinute
* Inherits the default from {@link ErrorAwarePolicy.Builder}
* The maximum number of errors allowed per minute for each host.
*
*
* retryPeriod
* Inherits the default from {@link ErrorAwarePolicy.Builder}
* The time during which a host is excluded by the policy once it has exceeded {@link #maxErrorsPerMinute}
*
*
*/
@JsonTypeName("errorAware")
public class ErrorAwarePolicyFactory implements LoadBalancingPolicyFactory {
@Valid
@NotNull
private LoadBalancingPolicyFactory subPolicy;
private Integer maxErrorsPerMinute;
private Duration retryPeriod;
@JsonProperty
public LoadBalancingPolicyFactory getSubPolicy() {
return subPolicy;
}
@JsonProperty
public void setSubPolicy(LoadBalancingPolicyFactory subPolicy) {
this.subPolicy = subPolicy;
}
@JsonProperty
public Integer getMaxErrorsPerMinute() {
return maxErrorsPerMinute;
}
@JsonProperty
public void setMaxErrorsPerMinute(Integer maxErrorsPerMinute) {
this.maxErrorsPerMinute = maxErrorsPerMinute;
}
@JsonProperty
public Duration getRetryPeriod() {
return retryPeriod;
}
@JsonProperty
public void setRetryPeriod(Duration retryPeriod) {
this.retryPeriod = retryPeriod;
}
@Override
public LoadBalancingPolicy build() {
ErrorAwarePolicy.Builder builder = ErrorAwarePolicy.builder(subPolicy.build());
if (maxErrorsPerMinute != null) {
builder.withMaxErrorsPerMinute(maxErrorsPerMinute);
}
if (retryPeriod != null) {
builder.withRetryPeriod(retryPeriod.getQuantity(), retryPeriod.getUnit());
}
return builder.build();
}
}