Class BlacklistingConsulFailoverStrategy

java.lang.Object
org.kiwiproject.consul.util.failover.strategy.BlacklistingConsulFailoverStrategy
All Implemented Interfaces:
ConsulFailoverStrategy

public class BlacklistingConsulFailoverStrategy extends Object implements ConsulFailoverStrategy
Author:
Troy Heanssgen
  • Constructor Summary

    Constructors
    Constructor
    Description
    BlacklistingConsulFailoverStrategy(Collection<com.google.common.net.HostAndPort> targets, long timeout)
    Constructs a blacklisting strategy with a collection of hosts and ports
  • Method Summary

    Modifier and Type
    Method
    Description
    @NonNull Optional<okhttp3.Request>
    computeNextStage(@NonNull okhttp3.Request previousRequest, @Nullable okhttp3.Response previousResponse)
    Computes the next failover stage for the consul failover strategy.
    boolean
    isRequestViable(@NonNull okhttp3.Request current)
    Determines if there is a viable candidate for the next request.
    void
    markRequestFailed(@NonNull okhttp3.Request current)
    Marks the specified request as a failed URL (in case of exceptions and other events that could cause us to never get a response).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BlacklistingConsulFailoverStrategy

      public BlacklistingConsulFailoverStrategy(Collection<com.google.common.net.HostAndPort> targets, long timeout)
      Constructs a blacklisting strategy with a collection of hosts and ports
      Parameters:
      targets - A set of viable hosts
      timeout - The timeout in milliseconds
  • Method Details

    • computeNextStage

      public @NonNull Optional<okhttp3.Request> computeNextStage(@NonNull okhttp3.Request previousRequest, @Nullable okhttp3.Response previousResponse)
      Description copied from interface: ConsulFailoverStrategy
      Computes the next failover stage for the consul failover strategy. This allows the end user to customize the way and methods by which additional failover targets may be selected.
      Specified by:
      computeNextStage in interface ConsulFailoverStrategy
      Parameters:
      previousRequest - The last request to go out the door.
      previousResponse - The response that was returned when the previousRequest was completed.
      Returns:
      An optional failover request. This may return an empty optional, signaling that the request should be aborted
    • isRequestViable

      public boolean isRequestViable(@NonNull okhttp3.Request current)
      Description copied from interface: ConsulFailoverStrategy
      Determines if there is a viable candidate for the next request. This lets us short circuit the first attempted request (such as when we know with certainty that a host should not be available) without interfering with the consul client too much.
      Specified by:
      isRequestViable in interface ConsulFailoverStrategy
      Parameters:
      current - The current inflight request.
      Returns:
      A boolean representing if there is another possible request candidate available.
    • markRequestFailed

      public void markRequestFailed(@NonNull okhttp3.Request current)
      Description copied from interface: ConsulFailoverStrategy
      Marks the specified request as a failed URL (in case of exceptions and other events that could cause us to never get a response). This avoids infinite loops where the strategy can never be made aware that the request has failed.
      Specified by:
      markRequestFailed in interface ConsulFailoverStrategy
      Parameters:
      current - The current request object representing a request that failed