Class ImageCacheSupplier
- java.lang.Object
-
- org.jclouds.compute.suppliers.ImageCacheSupplier
-
- All Implemented Interfaces:
com.google.common.base.Supplier<Set<? extends Image>>
,Supplier<Set<? extends Image>>
,ValueLoadedCallback<Set<? extends Image>>
@Beta public class ImageCacheSupplier extends Object implements com.google.common.base.Supplier<Set<? extends Image>>, ValueLoadedCallback<Set<? extends Image>>
Memoized image supplier that allows new images to be registered at runtime.The memoized
Supplier
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>
-
-
Constructor Summary
Constructors Constructor Description ImageCacheSupplier(com.google.common.base.Supplier<Set<? extends Image>> imageSupplier, long sessionIntervalSeconds, AtomicReference<AuthorizationException> authException, com.google.inject.Provider<GetImageStrategy> imageLoader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<? extends Image>
get()
com.google.common.base.Optional<? extends Image>
get(String id)
Loads an image by id.Set<? extends Image>
rebuildCache()
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
reset(Set<? extends Image> images)
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 Detail
-
logger
@Named("jclouds.compute") protected Logger logger
-
-
Constructor Detail
-
ImageCacheSupplier
public ImageCacheSupplier(com.google.common.base.Supplier<Set<? extends Image>> imageSupplier, long sessionIntervalSeconds, AtomicReference<AuthorizationException> authException, com.google.inject.Provider<GetImageStrategy> imageLoader)
-
-
Method Detail
-
valueLoaded
public void valueLoaded(com.google.common.base.Optional<Set<? extends Image>> value)
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
public void reset(Set<? extends Image> images)
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
public Set<? extends Image> rebuildCache()
Calls theliveImageSupplier
to get the current images and rebuilds the cache with them.
-
get
public com.google.common.base.Optional<? extends Image> get(String id)
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
public void registerImage(Image image)
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
public void removeImage(String imageId)
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.
-
-