-
- All Implemented Interfaces:
-
com.mobwith.imgmodule.load.engine.EngineJobListener,com.mobwith.imgmodule.load.engine.EngineResource.ResourceListener,com.mobwith.imgmodule.load.engine.cache.MemoryCache.ResourceRemovedListener
public class Engine implements EngineJobListener, MemoryCache.ResourceRemovedListener, EngineResource.ResourceListener
Responsible for starting loads and managing active and cached resources.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classEngine.LoadStatusAllows a request to indicate it no longer is interested in a given load.
Non-final for mocking.
-
Constructor Summary
Constructors Constructor Description Engine(MemoryCache memoryCache, DiskCache.Factory diskCacheFactory, ImageExecutor diskCacheExecutor, ImageExecutor sourceExecutor, ImageExecutor sourceUnlimitedExecutor, ImageExecutor animationExecutor, boolean isActiveResourceRetentionAllowed)
-
Method Summary
Modifier and Type Method Description <R> Engine.LoadStatusload(ImageContext imageContext, Object model, Key signature, int width, int height, Class<out Object> resourceClass, Class<R> transcodeClass, Priority priority, DiskCacheStrategy diskCacheStrategy, Map<Class<out Object>, Transformation<out Object>> transformations, boolean isTransformationRequired, boolean isScaleOnlyOrNoTransform, Options options, boolean isMemoryCacheable, boolean useUnlimitedSourceExecutorPool, boolean useAnimationPool, boolean onlyRetrieveFromCache, ResourceCallback cb, Executor callbackExecutor)Starts a load for the given arguments. voidrelease(Resource<out Object> resource)synchronized voidonEngineJobComplete(EngineJob<out Object> engineJob, Key key, EngineResource<out Object> resource)synchronized voidonEngineJobCancelled(EngineJob<out Object> engineJob, Key key)voidonResourceRemoved(@NonNull() Resource<out Object> resource)voidonResourceReleased(Key cacheKey, EngineResource<out Object> resource)voidclearDiskCache()voidshutdown()-
Methods inherited from class com.mobwith.imgmodule.load.engine.EngineJobListener
onEngineJobComplete -
Methods inherited from class com.mobwith.imgmodule.load.engine.cache.MemoryCache.ResourceRemovedListener
onResourceRemoved -
Methods inherited from class com.mobwith.imgmodule.load.engine.EngineResource.ResourceListener
onResourceReleased -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
Engine
Engine(MemoryCache memoryCache, DiskCache.Factory diskCacheFactory, ImageExecutor diskCacheExecutor, ImageExecutor sourceExecutor, ImageExecutor sourceUnlimitedExecutor, ImageExecutor animationExecutor, boolean isActiveResourceRetentionAllowed)
-
-
Method Detail
-
load
<R> Engine.LoadStatus load(ImageContext imageContext, Object model, Key signature, int width, int height, Class<out Object> resourceClass, Class<R> transcodeClass, Priority priority, DiskCacheStrategy diskCacheStrategy, Map<Class<out Object>, Transformation<out Object>> transformations, boolean isTransformationRequired, boolean isScaleOnlyOrNoTransform, Options options, boolean isMemoryCacheable, boolean useUnlimitedSourceExecutorPool, boolean useAnimationPool, boolean onlyRetrieveFromCache, ResourceCallback cb, Executor callbackExecutor)
Starts a load for the given arguments.
Must be called on the main thread.
The flow for any request is as follows:
- Check the current set of actively used resources, return the active resource if present,and move any newly inactive resources into the memory cache.
- Check the memory cache and provide the cached resource if present.
- Check the current set of in progress loads and add the cb to the in progress load if oneis present.
- Start a new load.
Active resources are those that have been provided to at least one request and have not yetbeen released. Once all consumers of a resource have released that resource, the resource thengoes to cache. If the resource is ever returned to a new consumer from cache, it is re-added tothe active resources. If the resource is evicted from the cache, its resources are recycled andre-used if possible and the resource is discarded. There is no strict requirement thatconsumers release their resources so active resources are held weakly.
- Parameters:
width- The target width in pixels of the desired resource.height- The target height in pixels of the desired resource.cb- The callback that will be called when the load completes.
-
onEngineJobComplete
synchronized void onEngineJobComplete(EngineJob<out Object> engineJob, Key key, EngineResource<out Object> resource)
-
onEngineJobCancelled
synchronized void onEngineJobCancelled(EngineJob<out Object> engineJob, Key key)
-
onResourceRemoved
void onResourceRemoved(@NonNull() Resource<out Object> resource)
-
onResourceReleased
void onResourceReleased(Key cacheKey, EngineResource<out Object> resource)
-
clearDiskCache
void clearDiskCache()
-
shutdown
void shutdown()
-
-
-
-