public class RetryingCacheProxy extends java.lang.Object implements Cache
Cache
that proxies another Cache
instance.
The usecase for this cache proxy is to periodically "retry" a get(String)
operation in the event that a timing issue
causes the cache not to have been populated when an attempt to get a value is made. If not explicitly configured, then there are
2 retries spaced 2 seconds apart. Other than this behaviour, everything else is delegated to the proxied cache implementation.
In the adapter configuration file this class is aliased as retrying-cache-proxy which is the preferred alternative to the fully qualified classname when building your configuration.
Constructor and Description |
---|
RetryingCacheProxy() |
RetryingCacheProxy(Cache cache) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears all entries from the cache
|
void |
close()
Closes the component.
|
java.lang.Object |
get(java.lang.String key)
Retrieves an object from the cache
|
java.util.List<java.lang.String> |
getKeys()
Retrieves a List of all the keys in the cache
|
java.lang.Integer |
getMaxAttempts() |
Cache |
getProxiedCache() |
TimeInterval |
getRetryInterval() |
void |
init()
Initialises the component.
|
void |
put(java.lang.String key,
java.lang.Object value)
Puts any object into the cache.
|
void |
put(java.lang.String key,
java.io.Serializable value)
Puts a serializable object into the cache.
|
void |
remove(java.lang.String key)
Removes an object from the cache.
|
void |
setMaxAttempts(java.lang.Integer max)
Set the maximum number of attempts to get a cache.
|
void |
setProxiedCache(Cache c) |
void |
setRetryInterval(TimeInterval t)
Set the interval between each retry attempt.
|
int |
size() |
void |
start()
Starts the component.
|
void |
stop()
Stop the component
|
RetryingCacheProxy |
withMaxAttempts(java.lang.Integer i) |
RetryingCacheProxy |
withProxiedCache(Cache c) |
RetryingCacheProxy |
withRetryInterval(TimeInterval i) |
public RetryingCacheProxy()
public RetryingCacheProxy(Cache cache)
public void init() throws CoreException
ComponentLifecycle
Component initialisation includes config verification, creation of connections etc.
init
in interface Cache
init
in interface ComponentLifecycle
CoreException
- wrapping any underlying Exception
spublic void close()
ComponentLifecycle
A closed component should release any connections it uses, etc. and clean up completely. Throwing a RuntimeException
may
cause unintended consequences
close
in interface Cache
close
in interface ComponentLifecycle
public void start() throws CoreException
ComponentLifecycle
Once a component is started it should be ready to process messages. In the case of AdaptrisMessageConsumer
, calling start
will begin message delivery.
start
in interface Cache
start
in interface ComponentLifecycle
CoreException
- wrapping any underlying Exception
spublic void stop()
ComponentLifecycle
A stopped component is not expected to be ready to process messages. In the case of AdaptrisMessageConsumer
, calling stop
will pause message delivery. Throwing a RuntimeException
may cause unintended consequences
stop
in interface Cache
stop
in interface ComponentLifecycle
public void put(java.lang.String key, java.io.Serializable value) throws CoreException
Cache
put
in interface Cache
key
- key to store the value againstvalue
- value to be storedCoreException
- if there was an exception accessing the cache.public void put(java.lang.String key, java.lang.Object value) throws CoreException
Cache
Not guaranteed to be supported by all cache implementations as some persistent caches require serialization.
put
in interface Cache
key
- key to store the value againstvalue
- value to be storedCoreException
- if there was an exception accessing the cache.public java.lang.Object get(java.lang.String key) throws CoreException
Cache
get
in interface Cache
key
- the key to look up the objectCoreException
- if there was an exception accessing the cache.public void remove(java.lang.String key) throws CoreException
Cache
remove
in interface Cache
key
- the key to locate the object in the cacheCoreException
- if there was an exception accessing the cache.public java.util.List<java.lang.String> getKeys() throws CoreException
Cache
getKeys
in interface Cache
CoreException
- if there was an exception accessing the cache.public void clear() throws CoreException
Cache
clear
in interface Cache
CoreException
- if there was an exception accessing the cache.public int size() throws CoreException
size
in interface Cache
CoreException
- if there was an exception accessing the cache.public Cache getProxiedCache()
public void setProxiedCache(Cache c)
public java.lang.Integer getMaxAttempts()
public void setMaxAttempts(java.lang.Integer max)
max
- maximum number of attempts, defaults to 2.public TimeInterval getRetryInterval()
public void setRetryInterval(TimeInterval t)
t
- the interval between each attempt, defaults to 2 seconds.public RetryingCacheProxy withMaxAttempts(java.lang.Integer i)
public RetryingCacheProxy withRetryInterval(TimeInterval i)
public RetryingCacheProxy withProxiedCache(Cache c)