Class DefaultFailureCache
- java.lang.Object
-
- org.apache.http.impl.client.cache.DefaultFailureCache
-
- All Implemented Interfaces:
FailureCache
@Contract(threading=SAFE) public class DefaultFailureCache extends java.lang.Object implements FailureCache
Implements a bounded failure cache. The oldest entries are discarded when the maximum size is exceeded.- Since:
- 4.3
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static intDEFAULT_MAX_SIZE(package private) static intMAX_UPDATE_TRIESprivate intmaxSizeprivate java.util.concurrent.ConcurrentMap<java.lang.String,FailureCacheValue>storage
-
Constructor Summary
Constructors Constructor Description DefaultFailureCache()Create a new failure cache with the maximum size ofDEFAULT_MAX_SIZE.DefaultFailureCache(int maxSize)Creates a new failure cache with the specified maximum size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private FailureCacheValuefindValueWithOldestTimestamp()intgetErrorCount(java.lang.String identifier)Get the current error count.voidincreaseErrorCount(java.lang.String identifier)Increases the error count by one.private voidremoveOldestEntryIfMapSizeExceeded()voidresetErrorCount(java.lang.String identifier)Reset the error count back to zero.private voidupdateValue(java.lang.String identifier)
-
-
-
Field Detail
-
DEFAULT_MAX_SIZE
static final int DEFAULT_MAX_SIZE
- See Also:
- Constant Field Values
-
MAX_UPDATE_TRIES
static final int MAX_UPDATE_TRIES
- See Also:
- Constant Field Values
-
maxSize
private final int maxSize
-
storage
private final java.util.concurrent.ConcurrentMap<java.lang.String,FailureCacheValue> storage
-
-
Constructor Detail
-
DefaultFailureCache
public DefaultFailureCache()
Create a new failure cache with the maximum size ofDEFAULT_MAX_SIZE.
-
DefaultFailureCache
public DefaultFailureCache(int maxSize)
Creates a new failure cache with the specified maximum size.- Parameters:
maxSize- the maximum number of entries the cache should store
-
-
Method Detail
-
getErrorCount
public int getErrorCount(java.lang.String identifier)
Description copied from interface:FailureCacheGet the current error count.- Specified by:
getErrorCountin interfaceFailureCache- Parameters:
identifier- the identifier for which the error count is requested- Returns:
- the currently known error count or zero if there is no record
-
resetErrorCount
public void resetErrorCount(java.lang.String identifier)
Description copied from interface:FailureCacheReset the error count back to zero.- Specified by:
resetErrorCountin interfaceFailureCache- Parameters:
identifier- the identifier for which the error count should be reset
-
increaseErrorCount
public void increaseErrorCount(java.lang.String identifier)
Description copied from interface:FailureCacheIncreases the error count by one.- Specified by:
increaseErrorCountin interfaceFailureCache- Parameters:
identifier- the identifier for which the error count should be increased
-
updateValue
private void updateValue(java.lang.String identifier)
-
removeOldestEntryIfMapSizeExceeded
private void removeOldestEntryIfMapSizeExceeded()
-
findValueWithOldestTimestamp
private FailureCacheValue findValueWithOldestTimestamp()
-
-