Class ConsulFailoverInterceptor

java.lang.Object
org.kiwiproject.consul.util.failover.ConsulFailoverInterceptor
All Implemented Interfaces:
okhttp3.Interceptor

public class ConsulFailoverInterceptor extends Object implements okhttp3.Interceptor
  • 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 failover
      timeout - the timeout in milliseconds
    • ConsulFailoverInterceptor

      public ConsulFailoverInterceptor(ConsulFailoverStrategy strategy)
      Allows customization of the interceptor chain
      Parameters:
      strategy - the failover strategy
  • Method Details

    • withMaxFailoverAttempts

      public ConsulFailoverInterceptor withMaxFailoverAttempts(int maxFailoverAttempts)
      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 a MaxFailoverAttemptsExceededException is thrown.
      Returns:
      maximum failover attempts
    • intercept

      public @NonNull okhttp3.Response intercept(okhttp3.Interceptor.Chain chain)
      Specified by:
      intercept in interface okhttp3.Interceptor