- All Implemented Interfaces:
Serializable,Comparable<HttpResultState>,Constable
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 serverCACHED- Using cached content (ETag indicates not modified)STALE- Using cached content but it may be outdatedRECOVERED- Succeeded after retry attemptsERROR- 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:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionUsing cached content because server indicated it hasn't changed.All retry attempts failed.Successfully loaded fresh content from the server.Operation succeeded but only after retry attempts.Using cached/fallback content because fresh content couldn't be retrieved. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Set<HttpResultState> States that indicate successful content retrieval from cache.static final Set<HttpResultState> States that indicate content freshness concerns.static final Set<HttpResultState> States that must be handled before accessing the result.static final Set<HttpResultState> States that indicate successful operation completion. -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpResultStateReturns the enum constant of this class with the specified name.static HttpResultState[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
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
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
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
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
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
States that indicate successful content retrieval from cache. These states mean the result can be used reliably for business logic. -
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
States that indicate content freshness concerns. These states suggest monitoring or validation may be appropriate. -
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
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
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 nameNullPointerException- if the argument is null
-