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

io.dropwizard.cassandra.loadbalancing.ErrorAwarePolicyFactory Maven / Gradle / Ivy

Go to download

Provides easy integration for Dropwizard applications with Apache Cassandra using the DataStax 4.x client

There is a newer version: 4.0.0
Show newest version
package io.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;

@JsonTypeName("errorAware")
public class ErrorAwarePolicyFactory implements LoadBalancingPolicyFactory {
    @Valid
    @NotNull
    @JsonProperty
    private LoadBalancingPolicyFactory subPolicy;

    @JsonProperty
    private Integer maxErrorsPerMinute;

    @JsonProperty
    private Duration retryPeriod;

    public LoadBalancingPolicyFactory getSubPolicy() {
        return subPolicy;
    }

    public void setSubPolicy(LoadBalancingPolicyFactory subPolicy) {
        this.subPolicy = subPolicy;
    }

    public Integer getMaxErrorsPerMinute() {
        return maxErrorsPerMinute;
    }

    public void setMaxErrorsPerMinute(Integer maxErrorsPerMinute) {
        this.maxErrorsPerMinute = maxErrorsPerMinute;
    }

    public Duration getRetryPeriod() {
        return retryPeriod;
    }

    public void setRetryPeriod(Duration retryPeriod) {
        this.retryPeriod = retryPeriod;
    }

    @Override
    public LoadBalancingPolicy build() {
        final 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