Class 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.

    • Field Detail

      • logger

        @Named("jclouds.compute")
        protected Logger logger
    • Method Detail

      • get

        public Set<? extends Image> get()
        Specified by:
        get in interface com.google.common.base.Supplier<Set<? extends Image>>
        Specified by:
        get in interface Supplier<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 the liveImageSupplier 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.