Esempio n. 1
0
 @Override
 public void run() {
   try {
     fetchImage(entry);
     ImageSetter setter = entry.getSetter();
     if (setter != null) {
       setter.setImageRecursively(entry.imageEntry.image);
     }
     fetchEntryMap.remove(entry.getImageUrl());
   } catch (InterruptedException e) {
     logger.warn("Interrupted: {}", entry.url);
   }
 }
Esempio n. 2
0
  /**
   * 画像を取得し、imageSetterを呼び出す。
   *
   * <p>フェッチに失敗したときは{@link ImageSetter#onException(Exception, ConnectionInfo)}が呼び出される
   *
   * @param imageSetter 画像セッター
   * @param url URL
   * @return キャッシュヒットしたかどうか
   * @throws InterruptedException 割り込まれた。
   */
  public boolean setImageIcon(ImageSetter imageSetter, URL url) throws InterruptedException {
    String urlString = url.toString();
    ImageEntry imageEntry = cachedImages.get(urlString);
    if (imageEntry == null) {
      FetchEntry fetchEntry = fetchEntryMap.get(urlString);
      FetchEntry newEntry = null;
      if (fetchEntry == null) {
        newEntry = getFetchEntry(urlString, url);
        fetchEntry = fetchEntryMap.putIfAbsent(urlString, newEntry);
      }
      if (fetchEntry == null) {
        newEntry.addSetter(imageSetter);
        configuration.addJob(JobQueue.PRIORITY_UI, new ImageFetcher(newEntry));
        return false;
      } else {
        synchronized (fetchEntry) {
          if (fetchEntry.isFinished()) {
            imageEntry = fetchEntry.imageEntry;
          } else {
            fetchEntry.addSetter(imageSetter);
            return false;
          }
        }
      }
    }

    if (imageEntry instanceof ErrorImageEntry) {
      return false;
    } else {
      imageSetter.setImageRecursively(imageEntry.image);
      return true;
    }
  }