systems.composable.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
Cassandra library for Dropwizard
package systems.composable.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() {
DCAwareRoundRobinPolicy.Builder builder = DCAwareRoundRobinPolicy.builder();
if (allowRemoteDCsForLocalConsistencyLevel == Boolean.TRUE) {
builder.allowRemoteDCsForLocalConsistencyLevel();
}
if (localDC != null) {
builder.withLocalDc(localDC);
}
if (usedHostsPerRemoteDC != null) {
builder.withUsedHostsPerRemoteDc(usedHostsPerRemoteDC);
}
return builder.build();
}
}