public synchronized void add(final CacheRequest request, final CacheManager manager) { final RequestIdentifier identifier = request.createIdentifier(); // Is in progress? If so, add late joiner. or, cancel if requested. if (downloadsInProgress.containsKey(identifier)) { if (request.cancelExisting) { downloadsInProgress.get(identifier).cancel(); } else { downloadsInProgress.get(identifier).addLateJoiner(request); return; } } // Is the priority <= 0? If so, spin up a new thread and run immediately. if (request.priority <= 0) { final CacheDownload download; if (downloadsQueued.containsKey(identifier)) { download = downloadsQueued.remove(identifier); download.addLateJoiner(request); } else { download = new CacheDownload(request, manager, this); } downloadsInProgress.put(identifier, download); new CacheDownloadThread(this, download, true); return; } // Is in queue? If so, add late joiner if (downloadsQueued.containsKey(identifier)) { downloadsQueued.get(identifier).addLateJoiner(request); return; } // Otherwise, add to queue and notify all downloadsQueued.put(identifier, new CacheDownload(request, manager, this)); notifyAll(); }
public RequestIdentifier createIdentifier() { return initiator.createIdentifier(); }