Beispiel #1
0
  void performCancel(Action action) {
    String key = action.getKey();
    BitmapHunter hunter = hunterMap.get(key);
    if (hunter != null) {
      hunter.detach(action);
      if (hunter.cancel()) {
        hunterMap.remove(key);
        if (action.getPicasso().loggingEnabled) {
          Utils.log(Utils.OWNER_DISPATCHER, Utils.VERB_CANCELED, action.getRequest().logId());
        }
      }
    }

    if (pausedTags.contains(action.getTag())) {
      pausedActions.remove(action.getTarget());
      if (action.getPicasso().loggingEnabled) {
        Utils.log(
            Utils.OWNER_DISPATCHER,
            Utils.VERB_CANCELED,
            action.getRequest().logId(),
            "because paused request got canceled");
      }
    }

    Action remove = failedActions.remove(action.getTarget());
    if (remove != null && remove.getPicasso().loggingEnabled) {
      Utils.log(
          Utils.OWNER_DISPATCHER,
          Utils.VERB_CANCELED,
          remove.getRequest().logId(),
          "from replaying");
    }
  }
Beispiel #2
0
  void performSubmit(Action action, boolean dismissFailed) {
    if (pausedTags.contains(action.getTag())) {
      pausedActions.put(action.getTarget(), action);
      if (action.getPicasso().loggingEnabled) {
        Utils.log(
            Utils.OWNER_DISPATCHER,
            Utils.VERB_PAUSED,
            action.request.logId(),
            "because tag '" + action.getTag() + "' is paused");
      }
      return;
    }

    BitmapHunter hunter = hunterMap.get(action.getKey());
    if (hunter != null) {
      if (hunter.isCancelled() || action.isCancelled()) {
        if (action.getPicasso().loggingEnabled) {
          Utils.log(
              Utils.OWNER_DISPATCHER,
              Utils.VERB_REMOVED,
              action.request.logId(),
              "action is cancelled");
        }
        hunterMap.remove(action.getKey());
        return;
      }
      hunter.attach(action);
      return;
    }

    if (service.isShutdown()) {
      if (action.getPicasso().loggingEnabled) {
        Utils.log(
            Utils.OWNER_DISPATCHER,
            Utils.VERB_IGNORED,
            action.request.logId(),
            "because shut down");
      }
      return;
    }

    hunter =
        forRequest(
            action.getPicasso(),
            this,
            action.request.cache,
            action.request.diskCache,
            stats,
            action);
    hunter.future = service.submit(hunter);
    hunterMap.put(action.getKey(), hunter);
    if (dismissFailed) {
      failedActions.remove(action.getTarget());
    }

    if (action.getPicasso().loggingEnabled) {
      Utils.log(Utils.OWNER_DISPATCHER, Utils.VERB_ENQUEUED, action.request.logId());
    }
  }
Beispiel #3
0
 private void markForReplay(Action action) {
   Object target = action.getTarget();
   if (target != null) {
     action.willReplay = true;
     failedActions.put(target, action);
   }
 }
Beispiel #4
0
 @Test
 public void performCancelUnqueuesAndDetachesPausedRequest() {
   Action action = mockAction(URI_KEY_1, URI_1, mockTarget(), "tag");
   BitmapHunter hunter = mockHunter(URI_KEY_1, bitmap1, false, action);
   dispatcher.hunterMap.put(URI_KEY_1, hunter);
   dispatcher.pausedTags.add("tag");
   dispatcher.pausedActions.put(action.getTarget(), action);
   dispatcher.performCancel(action);
   assertThat(dispatcher.pausedTags).hasSize(1).contains("tag");
   assertThat(dispatcher.pausedActions).isEmpty();
   verify(hunter).detach(action);
 }
Beispiel #5
0
    public Map<String, Construct> evaluate(BindableEvent e) throws EventException {
      Map<String, Construct> retn = new HashMap<String, Construct>();

      if (e instanceof Action) {
        Action msg = (Action) e;

        retn.put("id", new CString(msg.getBot().getID(), Target.UNKNOWN));
        retn.put("who", new CString(msg.getWho(), Target.UNKNOWN));
        retn.put("target", new CString(msg.getTarget(), Target.UNKNOWN));
        retn.put("message", new CString(msg.getMessage(), Target.UNKNOWN));
      }

      return retn;
    }
Beispiel #6
0
  void performPauseTag(Object tag) {
    // Trying to pause a tag that is already paused.
    if (!pausedTags.add(tag)) {
      return;
    }

    // Go through all active hunters and detach/pause the requests
    // that have the paused tag.
    for (Iterator<BitmapHunter> it = hunterMap.values().iterator(); it.hasNext(); ) {
      BitmapHunter hunter = it.next();
      boolean loggingEnabled = hunter.getPicasso().loggingEnabled;

      Action single = hunter.getAction();
      List<Action> joined = hunter.getActions();
      boolean hasMultiple = joined != null && !joined.isEmpty();

      // Hunter has no requests, bail early.
      if (single == null && !hasMultiple) {
        continue;
      }

      if (single != null && single.getTag().equals(tag)) {
        hunter.detach(single);
        pausedActions.put(single.getTarget(), single);
        if (loggingEnabled) {
          Utils.log(
              Utils.OWNER_DISPATCHER,
              Utils.VERB_PAUSED,
              single.request.logId(),
              "because tag '" + tag + "' was paused");
        }
      }

      if (hasMultiple) {
        for (int i = joined.size() - 1; i >= 0; i--) {
          Action action = joined.get(i);
          if (!action.getTag().equals(tag)) {
            continue;
          }

          hunter.detach(action);
          pausedActions.put(action.getTarget(), action);
          if (loggingEnabled) {
            Utils.log(
                Utils.OWNER_DISPATCHER,
                Utils.VERB_PAUSED,
                action.request.logId(),
                "because tag '" + tag + "' was paused");
          }
        }
      }

      // Check if the hunter can be cancelled in case all its requests
      // had the tag being paused here.
      if (hunter.cancel()) {
        it.remove();
        if (loggingEnabled) {
          Utils.log(
              Utils.OWNER_DISPATCHER,
              Utils.VERB_CANCELED,
              Utils.getLogIdsForHunter(hunter),
              "all actions paused");
        }
      }
    }
  }