@Beta public class ImageCacheSupplier extends Object implements com.google.common.base.Supplier<Set<? extends Image>>, ValueLoadedCallback<Set<? extends Image>>
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.
ValueLoadedCallback.NoOpCallback<V>
Constructor and Description |
---|
ImageCacheSupplier(com.google.common.base.Supplier<Set<? extends Image>> imageSupplier,
long sessionIntervalSeconds,
AtomicReference<AuthorizationException> authException,
com.google.inject.Provider<GetImageStrategy> imageLoader) |
Modifier and Type | Method and 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 the
liveImageSupplier 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 the
MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier . |
@Named(value="jclouds.compute") protected Logger logger
public ImageCacheSupplier(com.google.common.base.Supplier<Set<? extends Image>> imageSupplier, long sessionIntervalSeconds, AtomicReference<AuthorizationException> authException, com.google.inject.Provider<GetImageStrategy> imageLoader)
public void valueLoaded(com.google.common.base.Optional<Set<? extends Image>> value)
MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier
.
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.
valueLoaded
in interface ValueLoadedCallback<Set<? extends Image>>
public void reset(Set<? extends Image> 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.
public Set<? extends Image> rebuildCache()
liveImageSupplier
to get the current images and
rebuilds the cache with them.public com.google.common.base.Optional<? extends Image> get(String id)
This methods returns the cached image, or performs a call to retrieve it if the image is still not cached.
public void registerImage(Image image)
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.
image
- The image to be registered to the cache.public void removeImage(String imageId)
This method should be called to invalidate an already cached image, when some image known to not exist in the provider is still cached.
imageId
- The id of the image to invalidate.Copyright © 2009-2016 The Apache Software Foundation. All Rights Reserved.