static String getLogIdsForHunter(BitmapHunter hunter, String prefix) { StringBuilder builder = new StringBuilder(prefix); Action action = hunter.getAction(); if (action != null) { builder.append(action.request.logId()); } List<Action> actions = hunter.getActions(); if (actions != null) { for (int i = 0, count = actions.size(); i < count; i++) { if (i > 0 || action != null) builder.append(", "); builder.append(actions.get(i).request.logId()); } } return builder.toString(); }
private void flushFailedActions() { if (!failedActions.isEmpty()) { Iterator<Action> iterator = failedActions.values().iterator(); while (iterator.hasNext()) { Action action = iterator.next(); iterator.remove(); if (action.picasso.loggingEnabled) { log(OWNER_DISPATCHER, VERB_REPLAYING, action.request.logId()); } performSubmit(action, false); } } }
void detach(Action action) { boolean detached = false; if (this.action == action) { this.action = null; detached = true; } else if (actions != null) { detached = actions.remove(action); } // The action being detached had the highest priority. Update this // hunter's priority with the remaining actions. if (detached && action.request.priority == priority) { priority = computeNewPriority(); } if (picasso.loggingEnabled) { log(OWNER_HUNTER, VERB_REMOVED, action.request.logId(), getLogIdsForHunter(this, "from ")); } }
void performCancel(Action action) { String key = action.request.key; BitmapHunter hunter = hunterMap.get(key); if (hunter != null) { hunter.detach(action); if (hunter.cancel()) { hunterMap.remove(key); if (action.picasso.loggingEnabled) { log(OWNER_DISPATCHER, VERB_CANCELED, action.request.logId()); } } } if (pausedTags.contains(action.getTag())) { pausedActions.remove(action.getTarget()); if (action.picasso.loggingEnabled) { log(OWNER_DISPATCHER, VERB_CANCELED, action.request.logId(), "because paused request got canceled"); } } Action remove = failedActions.remove(action.getTarget()); if (remove != null && remove.picasso.loggingEnabled) { log(OWNER_DISPATCHER, VERB_CANCELED, remove.request.logId(), "from replaying"); } }
void attach(Action action) { boolean loggingEnabled = picasso.loggingEnabled; Request request = action.request; if (this.action == null) { this.action = action; if (loggingEnabled) { if (actions == null || actions.isEmpty()) { log(OWNER_HUNTER, VERB_JOINED, request.logId(), "to empty hunter"); } else { log(OWNER_HUNTER, VERB_JOINED, request.logId(), getLogIdsForHunter(this, "to ")); } } return; } if (actions == null) { actions = new ArrayList<>(3); } actions.add(action); if (loggingEnabled) { log(OWNER_HUNTER, VERB_JOINED, request.logId(), getLogIdsForHunter(this, "to ")); } Priority actionPriority = action.request.priority; if (actionPriority.ordinal() > priority.ordinal()) { priority = actionPriority; } }
void performSubmit(Action action, boolean dismissFailed) { if (pausedTags.contains(action.getTag())) { pausedActions.put(action.getTarget(), action); if (action.picasso.loggingEnabled) { log(OWNER_DISPATCHER, VERB_PAUSED, action.request.logId(), "because tag '" + action.getTag() + "' is paused"); } return; } BitmapHunter hunter = hunterMap.get(action.request.key); if (hunter != null) { hunter.attach(action); return; } if (service.isShutdown()) { if (action.picasso.loggingEnabled) { log(OWNER_DISPATCHER, VERB_IGNORED, action.request.logId(), "because shut down"); } return; } hunter = forRequest(action.picasso, this, cache, stats, action); hunter.future = service.submit(hunter); hunterMap.put(action.request.key, hunter); if (dismissFailed) { failedActions.remove(action.getTarget()); } if (action.picasso.loggingEnabled) { log(OWNER_DISPATCHER, VERB_ENQUEUED, action.request.logId()); } }
private void deliverAction(@Nullable RequestHandler.Result result, Action action, @Nullable Exception e) { if (action.cancelled) { return; } if (!action.willReplay) { targetToAction.remove(action.getTarget()); } if (result != null) { action.complete(result); if (loggingEnabled) { log(OWNER_MAIN, VERB_COMPLETED, action.request.logId(), "from " + result.getLoadedFrom()); } } else { Exception exception = checkNotNull(e, "e == null"); action.error(exception); if (loggingEnabled) { log(OWNER_MAIN, VERB_ERRORED, action.request.logId(), exception.getMessage()); } } }
newResult = transformation.transform(result); if (picasso.loggingEnabled) { log(OWNER_HUNTER, VERB_TRANSFORMED, data.logId(), "from transformations");
pausedActions.put(single.getTarget(), single); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_PAUSED, single.request.logId(), "because tag '" + tag + "' was paused"); pausedActions.put(action.getTarget(), action); if (loggingEnabled) { log(OWNER_DISPATCHER, VERB_PAUSED, action.request.logId(), "because tag '" + tag + "' was paused");
void resumeAction(Action action) { Bitmap bitmap = null; if (shouldReadFromMemoryCache(action.request.memoryPolicy)) { bitmap = quickMemoryCacheCheck(action.request.key); } if (bitmap != null) { // Resumed action is cached, complete immediately. deliverAction(new RequestHandler.Result(bitmap, MEMORY), action, null); if (loggingEnabled) { log(OWNER_MAIN, VERB_COMPLETED, action.request.logId(), "from " + MEMORY); } } else { // Re-submit the action to the executor. enqueueAndSubmit(action); if (loggingEnabled) { log(OWNER_MAIN, VERB_RESUMED, action.request.logId()); } } }
/** Create the request optionally passing it through the request transformer. */ private Request createRequest(long started) { int id = nextId.getAndIncrement(); Request request = data.build(); request.id = id; request.started = started; boolean loggingEnabled = picasso.loggingEnabled; if (loggingEnabled) { log(OWNER_MAIN, VERB_CREATED, request.plainId(), request.toString()); } Request transformed = picasso.transformRequest(request); if (transformed != request) { // If the request was changed, copy over the id and timestamp from the original. transformed.id = id; transformed.started = started; if (loggingEnabled) { log(OWNER_MAIN, VERB_CHANGED, transformed.logId(), "into " + transformed); } } return transformed; }