public abstract class AbstractIconCache extends java.lang.Object implements IconCache
IconCache which provides the loading of multiple icons at
once. This will be most likely always the same independent of the cache strategy.
Additionally it implements strategies to avoid loading the same icon multiple times by identify the same payment methods even when they are different object.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
AbstractIconCache.CacheKey
The cache key uses the fact that the payment method configuration is uniquely identifiable by
the version and id.
|
DEFAULT_ICON_LOADING_TIMEOUT| Modifier | Constructor and Description |
|---|---|
protected |
AbstractIconCache(long timeout)
Constructs a new cache with the specified
timeout for loading multiple icons. |
| Modifier and Type | Method and Description |
|---|---|
void |
fetchIcons(java.util.Collection<PaymentMethodConfiguration> paymentMethodConfigurations,
AsynchronousCallback<java.util.Map<PaymentMethodConfiguration,PaymentMethodIcon>> callback)
This method fetches for a collection of
PaymentMethodConfiguration the associated
icons. |
void |
loadIcon(PaymentMethodConfiguration paymentMethodConfiguration,
RequestCallback<PaymentMethodIcon> callback)
This method is invoked when for the
methodConfiguration the images should be
downloaded. |
protected abstract PaymentMethodIcon |
lookupInLocalCache(AbstractIconCache.CacheKey paymentMethodConfiguration)
This method is invoked to try to load the icon from the local cache.
|
protected abstract void |
lookupInRemoteServer(AbstractIconCache.CacheKey paymentMethodConfiguration,
RequestCallback<PaymentMethodIcon> callback)
This method has to query the remote host to fetch the icon.
|
protected abstract void |
putInLocalCache(AbstractIconCache.CacheKey paymentMethodConfiguration,
PaymentMethodIcon icon)
This method is invoked to persist an entry into the local cache.
|
protected AbstractIconCache(long timeout)
timeout for loading multiple icons.timeout - the timeout which cannot be exceeded when multiple icons are loaded. The time
is in milliseconds.protected abstract void lookupInRemoteServer(AbstractIconCache.CacheKey paymentMethodConfiguration, RequestCallback<PaymentMethodIcon> callback)
This method has to be implemented in a thread-safe manner.
paymentMethodConfiguration - the payment method configuration for which the icon should
be fetched for.callback - the callback which has to be invoked once the loading has
been completed.protected abstract PaymentMethodIcon lookupInLocalCache(AbstractIconCache.CacheKey paymentMethodConfiguration)
null when the entry does not exists.
This method has to be implemented in a thread-safe manner.
paymentMethodConfiguration - the payment method configuration for which the icon should
be looked up.null when it does not exists.protected abstract void putInLocalCache(AbstractIconCache.CacheKey paymentMethodConfiguration, PaymentMethodIcon icon)
This method has to be implemented in a thread-safe manner.
paymentMethodConfiguration - the payment method configuration for which the icon should
be stored for.icon - the icon which should be stored.public void loadIcon(PaymentMethodConfiguration paymentMethodConfiguration, RequestCallback<PaymentMethodIcon> callback)
IconCachemethodConfiguration the images should be
downloaded.
The implementor has to make sure that a parallel invocation of this method does not cause
a memory leak. This means that a storage of the result should be implemented in a way that
duplicate requests get detected and handled properly. For example by using a ConcurrentMap or some kind of AtomicReference.
The URL from which the icon should be downloaded from can be found on PaymentMethodConfiguration.getResolvedImageUrl().
There is also a IconRequestManager which helps with the invocation of the remote
server.
public final void fetchIcons(java.util.Collection<PaymentMethodConfiguration> paymentMethodConfigurations, AsynchronousCallback<java.util.Map<PaymentMethodConfiguration,PaymentMethodIcon>> callback)
IconCachePaymentMethodConfiguration the associated
icons.
The method will stop after a specified timeout. The resulting map will have no entry for those which could not be loaded within the timeout.
fetchIcons in interface IconCachepaymentMethodConfigurations - the configurations for which the icons should be loaded
for.callback - the callback which is invoked once the loading has
completed or the timeout has been reached.