Class ImageCacheSupplier
- All Implemented Interfaces:
com.google.common.base.Supplier<Set<? extends Image>>
,Supplier<Set<? extends Image>>
,ValueLoadedCallback<Set<? extends Image>>
The memoized Supplierinvalid input: '<'Setinvalid input: '<'? extends Image>>
is a static data
structure that can't be properly modified at runtime. This class is a wrapper
for the image supplier to provide a way to register new images as needed.
Once a new image is created by the
ImageExtension
, or discovered by other
means (see https://issues.apache.org/jira/browse/JCLOUDS-570) this supplier
will allow the image to be appended to the cached list.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jclouds.rest.suppliers.ValueLoadedCallback
ValueLoadedCallback.NoOpCallback<V>
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionImageCacheSupplier
(com.google.common.base.Supplier<Set<? extends Image>> imageSupplier, long sessionIntervalSeconds, AtomicReference<AuthorizationException> authException, com.google.inject.Provider<GetImageStrategy> imageLoader) -
Method Summary
Modifier and TypeMethodDescriptionget()
com.google.common.base.Optional
<? extends Image> Loads an image by id.Calls theliveImageSupplier
to get the current images and rebuilds the cache with them.void
registerImage
(Image image) Registers a new image in the image cache.void
removeImage
(String imageId) Removes an image from the image cache.void
Resets the cache to the given set of images.void
valueLoaded
(com.google.common.base.Optional<Set<? extends Image>> value) The cache is subscribed to value loading events generated by theMemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier
.
-
Field Details
-
logger
-
-
Constructor Details
-
ImageCacheSupplier
public ImageCacheSupplier(com.google.common.base.Supplier<Set<? extends Image>> imageSupplier, long sessionIntervalSeconds, AtomicReference<AuthorizationException> authException, com.google.inject.Provider<GetImageStrategy> imageLoader)
-
-
Method Details
-
get
-
valueLoaded
The cache is subscribed to value loading events generated by theMemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier
.Every time the memoized supplier reloads a value, an event will be populated and this method will handle it. This makes it possible to refresh the cache with the last values everytime they are reloaded.
- Specified by:
valueLoaded
in interfaceValueLoadedCallback<Set<? extends Image>>
-
reset
Resets the cache to the given set of images.This method is called when the memoized image supplier is reloaded, or when the cache needs to be refreshed (for example when the TempalteBuilder is invoked forcing a fresh image lookup.
-
rebuildCache
Calls theliveImageSupplier
to get the current images and rebuilds the cache with them. -
get
Loads an image by id.This methods returns the cached image, or performs a call to retrieve it if the image is still not cached.
-
registerImage
Registers a new image in the image cache.This method should be called to register new images into the image cache when some image that is known to exist in the provider is still not cached. For example, this can happen when an image is created after the image cache has been populated for the first time.
Note that this method does not check if the image is already cached, to avoid loading all images if the image cache is still not populated.
- Parameters:
image
- The image to be registered to the cache.
-
removeImage
Removes an image from the image cache.This method should be called to invalidate an already cached image, when some image known to not exist in the provider is still cached.
- Parameters:
imageId
- The id of the image to invalidate.
-