Enum Class HttpResultState

java.lang.Object
java.lang.Enum<HttpResultState>
de.cuioss.http.client.result.HttpResultState
All Implemented Interfaces:
Serializable, Comparable<HttpResultState>, Constable

public enum HttpResultState extends Enum<HttpResultState>
HTTP-specific result states that extend the basic CUI result pattern with semantics tailored for HTTP operations, particularly ETag-aware caching and retry scenarios.

State Overview

  • FRESH - Successfully loaded new content from server
  • CACHED - Using cached content (ETag indicates not modified)
  • STALE - Using cached content but it may be outdated
  • RECOVERED - Succeeded after retry attempts
  • ERROR - All attempts failed, using fallback if available

Usage Patterns

1. ETag-Aware Caching

 HttpResultObject<String> result = etagHandler.load();
 if (result.isFresh()) {
     // New content loaded, update cache
     updateCache(result.getResult(), result.getETag());
 } else if (result.isCached()) {
     // Content unchanged, use existing cache
     useExistingContent(result.getResult());
 }
 

2. Retry Flow Control

 if (result.isRecovered()) {
     // Succeeded after retries, log for monitoring
     logger.info("HTTP operation recovered after {} attempts",
         result.getRetryMetrics().getTotalAttempts());
 } else if (result.getState() == ERROR) {
     // All retries failed, handle gracefully
     handleFailureWithFallback(result);
 }
 

State Semantics

  • FRESH: Content was loaded from server, ETag updated
  • CACHED: Server returned 304 Not Modified, content unchanged
  • STALE: Using cached content due to error, may be outdated
  • RECOVERED: Succeeded after 1+ retry attempts
  • ERROR: All retry attempts failed, using default/fallback result
Since:
1.0
Author:
Implementation based on CUI result pattern
See Also:
  • Enum Constant Details

    • FRESH

      public static final HttpResultState FRESH
      Successfully loaded fresh content from the server. This indicates the content is new or has been updated since the last request. ETag has been updated to reflect the current content version.
    • CACHED

      public static final HttpResultState CACHED
      Using cached content because server indicated it hasn't changed. This is the optimal case for ETag-aware operations where the server returned HTTP 304 Not Modified, confirming cached content is current.
    • STALE

      public static final HttpResultState STALE
      Using cached/fallback content because fresh content couldn't be retrieved. The cached content may be outdated but provides graceful degradation. This state indicates potential service degradation that should be monitored.
    • RECOVERED

      public static final HttpResultState RECOVERED
      Operation succeeded but only after retry attempts. This indicates temporary network/server issues that were successfully overcome. Retry metrics should be available for observability.
    • ERROR

      public static final HttpResultState ERROR
      All retry attempts failed. A default or cached result may be available for graceful degradation, but the primary operation could not be completed successfully.
  • Field Details

    • CACHE_STATES

      public static final Set<HttpResultState> CACHE_STATES
      States that indicate successful content retrieval from cache. These states mean the result can be used reliably for business logic.
    • SUCCESS_STATES

      public static final Set<HttpResultState> SUCCESS_STATES
      States that indicate successful operation completion. Content is available and can be used, though STALE and RECOVERED may warrant logging for monitoring purposes.
    • DEGRADED_STATES

      public static final Set<HttpResultState> DEGRADED_STATES
      States that indicate content freshness concerns. These states suggest monitoring or validation may be appropriate.
    • MUST_BE_HANDLED

      public static final Set<HttpResultState> MUST_BE_HANDLED
      States that must be handled before accessing the result. Overrides the base ResultState behavior to include STALE state as it may require special handling in some contexts.
  • Method Details

    • values

      public static HttpResultState[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static HttpResultState valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null