org.stuartgunter.dropwizard.cassandra.loadbalancing.DCAwareRoundRobinPolicyFactory 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
Dropwizard Bundle for Cassandra
                
             The newest version!
        
        package org.stuartgunter.dropwizard.cassandra.loadbalancing;
import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy;
import com.datastax.driver.core.policies.LoadBalancingPolicy;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
/**
 * A factory for configuring and building {@link com.datastax.driver.core.policies.DCAwareRoundRobinPolicy} instances.
 * 
 * Configuration Parameters:
 * 
 *     
 *         Name 
 *         Default 
 *         Description 
 *      
 *     
 *         localDC 
 *         No default. 
 *         The name of the local datacenter (as known by Cassandra). 
 *      
 *     
 *         usedHostsPerRemoteDC 
 *         No default. May only be specified when localDC is specified. 
 *         The number of host per remote datacenter that policies created by the returned factory should consider. 
 *      
 *     
 *         allowRemoteDCsForLocalConsistencyLevel 
 *         No default. May only be specified when localDC and usedHostsPerRemoteDC are specified. 
 *         Whether or not the policy may return remote host when building query plan for query having consitency LOCAL_ONE and LOCAL_QUORUM. 
 *      
 * 
 */
@JsonTypeName("dcAwareRoundRobin")
public class DCAwareRoundRobinPolicyFactory implements LoadBalancingPolicyFactory {
    private String localDC;
    private Integer usedHostsPerRemoteDC;
    private Boolean allowRemoteDCsForLocalConsistencyLevel;
    @JsonProperty
    public String getLocalDC() {
        return localDC;
    }
    @JsonProperty
    public void setLocalDC(String localDC) {
        this.localDC = localDC;
    }
    @JsonProperty
    public Integer getUsedHostsPerRemoteDC() {
        return usedHostsPerRemoteDC;
    }
    @JsonProperty
    public void setUsedHostsPerRemoteDC(Integer usedHostsPerRemoteDC) {
        this.usedHostsPerRemoteDC = usedHostsPerRemoteDC;
    }
    @JsonProperty
    public Boolean getAllowRemoteDCsForLocalConsistencyLevel() {
        return allowRemoteDCsForLocalConsistencyLevel;
    }
    @JsonProperty
    public void setAllowRemoteDCsForLocalConsistencyLevel(Boolean allowRemoteDCsForLocalConsistencyLevel) {
        this.allowRemoteDCsForLocalConsistencyLevel = allowRemoteDCsForLocalConsistencyLevel;
    }
    @Override
    public LoadBalancingPolicy build() {
        if (allowRemoteDCsForLocalConsistencyLevel == null) {
            if (usedHostsPerRemoteDC == null) {
                if (localDC == null) {
                    return new DCAwareRoundRobinPolicy();
                } else {
                    return new DCAwareRoundRobinPolicy(localDC);
                }
            } else {
                return new DCAwareRoundRobinPolicy(localDC, usedHostsPerRemoteDC);
            }
        } else {
            return new DCAwareRoundRobinPolicy(localDC, usedHostsPerRemoteDC, allowRemoteDCsForLocalConsistencyLevel);
        }
    }
}
    © 2015 - 2025 Weber Informatics LLC | Privacy Policy