コード例 #1
0
ファイル: HiveBolt.java プロジェクト: SeabassChen/storm
  /**
   * Locate all writers past idle timeout and retire them
   *
   * @return number of writers retired
   */
  private int retireIdleWriters() {
    int count = 0;
    long now = System.currentTimeMillis();
    ArrayList<HiveEndPoint> retirees = new ArrayList<HiveEndPoint>();

    // 1) Find retirement candidates
    for (Entry<HiveEndPoint, HiveWriter> entry : allWriters.entrySet()) {
      if (now - entry.getValue().getLastUsed() > options.getIdleTimeout()) {
        ++count;
        retirees.add(entry.getKey());
      }
    }
    // 2) Retire them
    for (HiveEndPoint ep : retirees) {
      try {
        LOG.info("Closing idle Writer to Hive end point : {}", ep);
        allWriters.remove(ep).close();
      } catch (IOException e) {
        LOG.warn("Failed to close writer for end point: {}. Error: " + ep, e);
      } catch (InterruptedException e) {
        LOG.warn("Interrupted when attempting to close writer for end point: " + ep, e);
        Thread.currentThread().interrupt();
      }
    }
    return count;
  }
コード例 #2
0
ファイル: HiveBolt.java プロジェクト: SeabassChen/storm
 /** Locate writer that has not been used for longest time and retire it */
 private void retireEldestWriter() {
   long oldestTimeStamp = System.currentTimeMillis();
   HiveEndPoint eldest = null;
   for (Entry<HiveEndPoint, HiveWriter> entry : allWriters.entrySet()) {
     if (entry.getValue().getLastUsed() < oldestTimeStamp) {
       eldest = entry.getKey();
       oldestTimeStamp = entry.getValue().getLastUsed();
     }
   }
   try {
     LOG.info("Closing least used Writer to Hive end point : " + eldest);
     allWriters.remove(eldest).close();
   } catch (IOException e) {
     LOG.warn("Failed to close writer for end point: " + eldest, e);
   } catch (InterruptedException e) {
     LOG.warn("Interrupted when attempting to close writer for end point: " + eldest, e);
     Thread.currentThread().interrupt();
   }
 }