All Downloads are FREE. Search and download functionalities are using the official Maven repository.

systems.composable.dropwizard.cassandra.loadbalancing.ErrorAwarePolicyFactory Maven / Gradle / Ivy

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: *

* * * * * * * * * * * * * * * * * * * * *
NameDefaultDescription
subPolicyNo default. You must provide a child policy.The load balancing policy to wrap with error awareness.
maxErrorsPerMinuteInherits the default from {@link ErrorAwarePolicy.Builder}The maximum number of errors allowed per minute for each host.
retryPeriodInherits 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(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy