public static class DCAwareRoundRobinPolicy.Builder extends Object
Constructor and Description |
---|
Builder() |
Modifier and Type | Method and Description |
---|---|
DCAwareRoundRobinPolicy.Builder |
allowRemoteDCsForLocalConsistencyLevel()
Allows the policy to return remote hosts when building query plans for queries having consistency level
LOCAL_ONE
or LOCAL_QUORUM . |
DCAwareRoundRobinPolicy |
build()
Builds the policy configured by this builder.
|
DCAwareRoundRobinPolicy.Builder |
withLocalDc(String localDc)
Sets the name of the datacenter that will be considered "local" by the policy.
|
DCAwareRoundRobinPolicy.Builder |
withUsedHostsPerRemoteDc(int usedHostsPerRemoteDc)
Sets the number of hosts per remote datacenter that the policy should consider.
|
public DCAwareRoundRobinPolicy.Builder withLocalDc(String localDc)
This must be the name as known by Cassandra (in other words, the name in that appears in
system.peers
, or in the output of admin tools like nodetool).
If this method isn't called, the policy will default to the datacenter of the first node
connected to. This will always be ok if all the contact points use at Cluster
creation are in the local data-center. Otherwise, you should provide the name yourself
with this method.
localDc
- the name of the datacenter. It should not be null
.public DCAwareRoundRobinPolicy.Builder withUsedHostsPerRemoteDc(int usedHostsPerRemoteDc)
The policy's distance()
method will return a HostDistance.REMOTE
distance for only usedHostsPerRemoteDc
hosts per remote datacenter. Other hosts of the remote datacenters will be ignored (and thus no connections to them will be
maintained).
If usedHostsPerRemoteDc > 0
, then if for a query no host in the local datacenter can be reached and if the consistency
level of the query is not LOCAL_ONE
or LOCAL_QUORUM
, then up to usedHostsPerRemoteDc
hosts per remote
datacenter will be tried by the policy as a fallback. By default, no remote host will be used for LOCAL_ONE
and
LOCAL_QUORUM
, since this would change the meaning of the consistency level, somewhat breaking the consistency contract
(this can be overridden with allowRemoteDCsForLocalConsistencyLevel()
).
If this method isn't called, the policy will default to 0.
usedHostsPerRemoteDc
- the number.public DCAwareRoundRobinPolicy.Builder allowRemoteDCsForLocalConsistencyLevel()
LOCAL_ONE
or LOCAL_QUORUM
.
When used in conjunction with usedHostsPerRemoteDc
> 0, this overrides the policy of
never using remote datacenter nodes for LOCAL_ONE
and LOCAL_QUORUM
queries. It is however inadvisable to do
so in almost all cases, as this would potentially break consistency guarantees and if you are fine with that, it's probably
better to use a weaker consitency like ONE
, TWO
or THREE
. As such, this method should generally be
avoided; use it only if you know and understand what you do.
public DCAwareRoundRobinPolicy build()
Copyright © 2012–2015. All rights reserved.