Example #1
0
  /**
   * インスタンスを生成する
   *
   * @param messageBus スケジューラー
   * @param accountId アカウントID (long)
   */
  public TimelineChannel(MessageBus messageBus, String accountId) {
    this.messageBus = messageBus;
    this.accountId = accountId;
    listeners = messageBus.getListeners(accountId, "statuses/timeline");

    configuration = ClientConfiguration.getInstance();
    configProperties = configuration.getConfigProperties();
    intervalOfTimeline =
        configProperties.getInteger(ClientConfiguration.PROPERTY_INTERVAL_TIMELINE);
  }
Example #2
0
  @Override
  public synchronized void realConnect() {
    if (scheduledFuture == null) {
      twitter = new TwitterFactory(messageBus.getTwitterConfiguration(accountId)).getInstance();

      scheduledFuture =
          configuration
              .getTimer()
              .scheduleWithFixedDelay(
                  () -> configuration.addJob(JobQueue.Priority.LOW, this),
                  0,
                  intervalOfTimeline,
                  TimeUnit.SECONDS);
    }
  }
Example #3
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;
    }
  }
Example #4
0
  /** インスタンスを生成する。 */
  public ImageCacher() {
    this.configuration = ClientConfiguration.getInstance();

    //		flushThreshold =
    // configuration.getConfigProperties().getInteger("core.cache.icon.flush_threshold");
    //		flushResetInterval =
    // configuration.getConfigProperties().getInteger("core.cache.icon.flush_reset_interval");

    imageCacheDir = new File(System.getProperty("elnetw.cache.dir"), "user");
  }
Example #5
0
  /**
   * 画像を取得する。
   *
   * @param entry イメージエントリ
   * @throws java.lang.InterruptedException interrupted
   */
  protected void fetchImage(FetchEntry entry) throws InterruptedException {
    synchronized (entry) {
      if (entry.isFinished()) {
        return;
      }

      byte[] imageData = NetworkSupport.fetchContents(entry.connectionInfo);
      ImageEntry imageEntry = entry.imageEntry;
      imageEntry.rawData = imageData;
      imageEntry.image = Toolkit.getDefaultToolkit().createImage(imageData);
      cachedImages.put(entry.getImageUrl(), entry.imageEntry);
      configuration.addJob(JobQueue.PRIORITY_IDLE, new ImageFlusher(imageEntry));
    }
  }