Skip to content

Commit

Permalink
Consistently order executors in Engine.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjudd committed Oct 10, 2014
1 parent c274f4e commit 7080b40
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
10 changes: 5 additions & 5 deletions library/src/main/java/com/bumptech/glide/GlideBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class GlideBuilder {
private BitmapPool bitmapPool;
private MemoryCache memoryCache;
private DiskCache diskCache;
private ExecutorService resizeService;
private ExecutorService sourceService;
private ExecutorService diskCacheService;

public GlideBuilder(Context context) {
Expand Down Expand Up @@ -86,7 +86,7 @@ public GlideBuilder setDiskCache(DiskCache diskCache) {
* @return This builder.
*/
public GlideBuilder setResizeService(ExecutorService service) {
this.resizeService = service;
this.sourceService = service;
return this;
}

Expand Down Expand Up @@ -117,9 +117,9 @@ GlideBuilder setEngine(Engine engine) {
}

Glide createGlide() {
if (resizeService == null) {
if (sourceService == null) {
final int cores = Math.max(1, Runtime.getRuntime().availableProcessors());
resizeService = new FifoPriorityThreadPoolExecutor(cores);
sourceService = new FifoPriorityThreadPoolExecutor(cores);
}
if (diskCacheService == null) {
diskCacheService = new FifoPriorityThreadPoolExecutor(1);
Expand Down Expand Up @@ -149,7 +149,7 @@ Glide createGlide() {
}

if (engine == null) {
engine = new Engine(memoryCache, diskCache, resizeService, diskCacheService);
engine = new Engine(memoryCache, diskCache, diskCacheService, sourceService);
}

return new Glide(engine, memoryCache, bitmapPool, context);
Expand Down
20 changes: 10 additions & 10 deletions library/src/main/java/com/bumptech/glide/load/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ public void cancel() {
}
}

public Engine(MemoryCache memoryCache, DiskCache diskCache, ExecutorService resizeService,
ExecutorService diskCacheService) {
this(memoryCache, diskCache, resizeService, diskCacheService, null, null, null, null);
public Engine(MemoryCache memoryCache, DiskCache diskCache, ExecutorService diskCacheService,
ExecutorService sourceService) {
this(memoryCache, diskCache, diskCacheService, sourceService, null, null, null, null);
}

// Visible for testing.
Engine(MemoryCache cache, DiskCache diskCache, ExecutorService resizeService,
ExecutorService diskCacheService, Map<Key, EngineJob> jobs, EngineKeyFactory keyFactory,
Engine(MemoryCache cache, DiskCache diskCache, ExecutorService diskCacheService, ExecutorService sourceService,
Map<Key, EngineJob> jobs, EngineKeyFactory keyFactory,
Map<Key, WeakReference<EngineResource<?>>> activeResources, EngineJobFactory engineJobFactory) {
this.cache = cache;
this.diskCache = diskCache;
Expand All @@ -82,7 +82,7 @@ public Engine(MemoryCache memoryCache, DiskCache diskCache, ExecutorService resi
this.jobs = jobs;

if (engineJobFactory == null) {
engineJobFactory = new EngineJobFactory(diskCacheService, resizeService, this);
engineJobFactory = new EngineJobFactory(diskCacheService, sourceService, this);
}
this.engineJobFactory = engineJobFactory;

Expand Down Expand Up @@ -307,18 +307,18 @@ public boolean queueIdle() {
// Visible for testing.
static class EngineJobFactory {
private final ExecutorService diskCacheService;
private final ExecutorService resizeService;
private final ExecutorService sourceService;
private final EngineJobListener listener;

public EngineJobFactory(ExecutorService diskCacheService, ExecutorService resizeService,
public EngineJobFactory(ExecutorService diskCacheService, ExecutorService sourceService,
EngineJobListener listener) {
this.diskCacheService = diskCacheService;
this.resizeService = resizeService;
this.sourceService = sourceService;
this.listener = listener;
}

public EngineJob build(Key key, boolean isMemoryCacheable) {
return new EngineJob(key, diskCacheService, resizeService, isMemoryCacheable, listener);
return new EngineJob(key, diskCacheService, sourceService, isMemoryCacheable, listener);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class EngineJob implements EngineRunnable.EngineRunnableManager {

private volatile Future<?> future;


public EngineJob(Key key, ExecutorService diskCacheService, ExecutorService sourceService, boolean isCacheable,
EngineJobListener listener) {
this(key, diskCacheService, sourceService, isCacheable, listener, DEFAULT_FACTORY);
Expand Down

0 comments on commit 7080b40

Please sign in to comment.