public synchronized void addEntry(String eventType, String eventId, long timeTaken) {
    // Store the last EventId for the JMX.
    lastEventId = eventId;
    // Update the entry in the descriptive statistics.
    DescriptiveStatistics descStatistics = descMap.get(eventType);
    if (descStatistics == null) {
      descStatistics = new DescriptiveStatistics();
      descStatistics.addValue(timeTaken);
      descMap.put(eventType, descStatistics);
    } else {
      descStatistics.addValue(timeTaken);
    }

    // Tracking for top K events, Maintain the list in descending order.
    ListOrderedMap<Long, Long> topKEntries = topKEvents.get(eventType);
    if (topKEntries == null) {
      topKEntries = new ListOrderedMap<>();
      topKEntries.put(Long.parseLong(eventId), timeTaken);
      topKEvents.put(eventType, topKEntries);
    } else {
      // Get the index of insertion, by descending order.
      int index = Collections.binarySearch(new ArrayList(topKEntries.values()), timeTaken, Collections.reverseOrder());
      // If the element comes as top K add it to the topEntries.
      // The index returned from the binary search, is either the index where the element already exist, else
      // (-insertionIndex) -1, so convert it to actual insertion index
      int insertionIndex = index < 0 ? -1 * (index) - 1 : index;
      if (insertionIndex < k && k >= 0) {
        topKEntries.put(insertionIndex, Long.parseLong(eventId), timeTaken);
      }
      // Post addition, if the size moves up by K, then remove the last entry, that would be smallest of the K
      // entries, since the list is sorted in descending order.
      if (topKEntries.size() > k) {
        topKEntries.remove(k);
      }
    }
  }
Adds an entry for tracking.
@param eventType the type of event.
@param eventId the event id.
@param timeTaken time taken to process the event.
ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplStatsTracker.java