Class ConsulFailoverInterceptor
java.lang.Object
org.kiwiproject.consul.util.failover.ConsulFailoverInterceptor
- All Implemented Interfaces:
okhttp3.Interceptor
-
Nested Class Summary
Nested classes/interfaces inherited from interface okhttp3.Interceptor
okhttp3.Interceptor.Chain, okhttp3.Interceptor.Companion -
Field Summary
Fields inherited from interface okhttp3.Interceptor
Companion -
Constructor Summary
ConstructorsConstructorDescriptionConsulFailoverInterceptor(Collection<com.google.common.net.HostAndPort> targets, long timeout) Default constructor for a set of hosts and portsAllows customization of the interceptor chain -
Method Summary
Modifier and TypeMethodDescription@NonNull okhttp3.Responseintercept(okhttp3.Interceptor.Chain chain) intReturn the maximum number of failover attempts, after which aMaxFailoverAttemptsExceededExceptionis thrown.withMaxFailoverAttempts(int maxFailoverAttempts) Change the maximum number of failover attempts before giving up.
-
Constructor Details
-
ConsulFailoverInterceptor
public ConsulFailoverInterceptor(Collection<com.google.common.net.HostAndPort> targets, long timeout) Default constructor for a set of hosts and ports- Parameters:
targets- the host/port pairs to use for failovertimeout- the timeout in milliseconds
-
ConsulFailoverInterceptor
Allows customization of the interceptor chain- Parameters:
strategy- the failover strategy
-
-
Method Details
-
withMaxFailoverAttempts
Change the maximum number of failover attempts before giving up. The default value is 10.While this method can be called at any time after construction, it is intended to be called immediately following a constructor when there is a need to change the default maximum. For example:
var interceptor = new ConsulFailoverInterceptor(hosts, timeout) .withMaxFailoverAttempts(25);- Parameters:
maxFailoverAttempts- the new maximum number of failover attempts- Returns:
- this instance, to permit chaining on a constructor call
-
maxFailoverAttempts
public int maxFailoverAttempts()Return the maximum number of failover attempts, after which aMaxFailoverAttemptsExceededExceptionis thrown.- Returns:
- maximum failover attempts
-
intercept
public @NonNull okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) - Specified by:
interceptin interfaceokhttp3.Interceptor
-