@Override
  public void run() {
    try {
      for (Entry<Pair<Topic, ConsumerGroup>, Long> entry : m_limits.entrySet()) {
        Topic topic = entry.getKey().getKey();
        ConsumerGroup group = entry.getKey().getValue();
        long limit = entry.getValue();

        Map<Integer, Long> backlogs = calculateBacklog(topic, group);

        long totalBacklog = 0;
        for (Long backlog : backlogs.values()) {
          totalBacklog += backlog;
        }

        if (totalBacklog >= limit) {
          m_result.addMonitorEvent(
              new ConsumeLargeBacklogEvent(topic.getName(), group.getName(), backlogs));
        }
      }
    } catch (Exception e) {
      m_exceptions.add(e);
    } finally {
      m_latch.countDown();
    }
  }
  private Map<Integer, Long> calculateBacklog(Topic topic, ConsumerGroup group) {
    Map<Integer, Long> backlogs = new HashMap<Integer, Long>();

    for (Partition partition : topic.getPartitions()) {
      long pBacklog = doCalculateBacklog(topic.getName(), partition.getId(), 0, group.getId());
      long npBacklog = doCalculateBacklog(topic.getName(), partition.getId(), 1, group.getId());
      backlogs.put(partition.getId(), pBacklog + npBacklog);
    }

    return backlogs;
  }