Class FcCommand<T>

java.lang.Object
org.frontcache.resilience.FcCommand<T>
Direct Known Subclasses:
FC_BypassCache, FC_ThroughCache, FC_ThroughCache_HttpClient, FC_ThroughCache_WebFilter, FC_Total

public abstract class FcCommand<T> extends Object
The seam. Reproduces the slice of the HystrixCommand contract Frontcache's five commands actually use, on top of Resilience4j. The five commands consume exactly five things from Hystrix: the Setter chain in the constructor, run(), getFallback(), getExecutionEvents(), getFailedExecutionException() and execute(). That uniformity is what makes this migration a base-class swap rather than a rewrite - see proposal sections 3.1 and 4. Two behavioral details are preserved deliberately, because getting either wrong would be a silent production change: - getFailedExecutionException() is populated only for a genuine FAILURE, and stays null for TIMEOUT / SHORT_CIRCUITED / rejections, exactly as Hystrix does. The existing fallbacks depend on it: FC_ThroughCache_HttpClient's log line passes it to SLF4J as the throwable, and expects a null there for a timeout so it logs a message without a stack trace. - getFallback() is invoked from the catch block below, on the calling thread, with no reactive subscription in between - so it always runs. That is the fix for the "in multi threaded environment hystrix does not resolve fallback ??" comment in ConcurrentIncludeProcessor (section 6.4). An FcBadRequestException is rethrown to the caller without resolving a fallback and without moving the circuit breaker's failure rate, matching HystrixBadRequestException.
  • Constructor Details

  • Method Details

    • run

      protected abstract T run() throws Exception
      Throws:
      Exception
    • getFallback

      protected T getFallback()
      Overridden by every Frontcache command. The base implementation signals "no fallback available", which execute() turns into an FcCommandException - the HystrixRuntimeException equivalent.
    • getExecutionDescription

      protected String getExecutionDescription()
      What the watchdog names in its log line. Overridable so a command can add the URL it is on.
    • execute

      public T execute()
    • getExecutionEvents

      public List<FcEventType> getExecutionEvents()
      The events of this execution, in the order they happened. Read inside getFallback() by four of the five commands (via FallbackLogger.failureType(List)), so the failure event is already recorded by the time the fallback runs.
    • getFailedExecutionException

      public Throwable getFailedExecutionException()
      Null unless run() itself threw - see the class javadoc.
    • getCommandKey

      public String getCommandKey()
    • getGroupKey

      public String getGroupKey()