Class ErrorAwarePolicy.Builder
- java.lang.Object
-
- com.datastax.driver.core.policies.ErrorAwarePolicy.Builder
-
- Enclosing class:
- ErrorAwarePolicy
public static class ErrorAwarePolicy.Builder extends Object
Utility class to create aErrorAwarePolicy.
-
-
Constructor Summary
Constructors Constructor Description Builder(LoadBalancingPolicy childPolicy)Creates aErrorAwarePolicy.Builderinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ErrorAwarePolicybuild()Creates theErrorAwarePolicyinstance.ErrorAwarePolicy.BuilderwithErrorsFilter(ErrorAwarePolicy.ErrorFilter errorFilter)Provides a filter that will decide which errors are counted towardswithMaxErrorsPerMinute(int).ErrorAwarePolicy.BuilderwithMaxErrorsPerMinute(int maxErrorsPerMinute)Defines the maximum number of errors allowed per minute for each host.ErrorAwarePolicy.BuilderwithRetryPeriod(long retryPeriod, TimeUnit retryPeriodTimeUnit)Defines the time during which a host is excluded by the policy once it has exceededwithMaxErrorsPerMinute(int).
-
-
-
Constructor Detail
-
Builder
public Builder(LoadBalancingPolicy childPolicy)
Creates aErrorAwarePolicy.Builderinstance.- Parameters:
childPolicy- the load balancing policy to wrap with error awareness.
-
-
Method Detail
-
withMaxErrorsPerMinute
public ErrorAwarePolicy.Builder withMaxErrorsPerMinute(int maxErrorsPerMinute)
Defines the maximum number of errors allowed per minute for each host.The policy keeps track of the number of errors on each host (filtered by
withErrorsFilter(com.datastax.driver.core.policies.ErrorAwarePolicy.ErrorFilter)) over a sliding 1-minute window. If a host had more than this number of errors, it will be excluded from the query plan for the duration defined bywithRetryPeriod(long, TimeUnit).Default value for the threshold is 1.
- Parameters:
maxErrorsPerMinute- the number.- Returns:
- this
ErrorAwarePolicy.Builderinstance, for method chaining.
-
withRetryPeriod
public ErrorAwarePolicy.Builder withRetryPeriod(long retryPeriod, TimeUnit retryPeriodTimeUnit)
Defines the time during which a host is excluded by the policy once it has exceededwithMaxErrorsPerMinute(int).Default value for the retry period is 2 minutes.
- Parameters:
retryPeriod- the period of exclusion for a host.retryPeriodTimeUnit- the time unit for the retry period.- Returns:
- this
ErrorAwarePolicy.Builderinstance, for method chaining.
-
withErrorsFilter
public ErrorAwarePolicy.Builder withErrorsFilter(ErrorAwarePolicy.ErrorFilter errorFilter)
Provides a filter that will decide which errors are counted towardswithMaxErrorsPerMinute(int).The default implementation will exclude from the error counting, the following exception types:
QueryConsistencyExceptionandUnavailableException: the assumption is that these errors are most often caused by other replicas being unavailable, not by something wrong on the coordinator;InvalidQueryException,AlreadyExistsException,SyntaxError: these are likely caused by a bad query in client code, that will fail on all hosts. Excluding hosts could lead to complete loss of connectivity, rather the solution is to fix the query;FunctionExecutionException: similarly, this is caused by a bad function definition and likely to fail on all hosts.
- Parameters:
errorFilter- the filter class that the policy will use.- Returns:
- this
ErrorAwarePolicy.Builderinstance, for method chaining.
-
build
public ErrorAwarePolicy build()
Creates theErrorAwarePolicyinstance.- Returns:
- the newly created
ErrorAwarePolicy.
-
-