src/main/java/org/deduplogger/logger/LogCache.java
/**
   * Generate the summary message
   * @param msg the msg to be checked against the cache
   * @return A list of eviction message
   */
Generate the summary message
@param msg the msg to be checked against the cache
@return A list of eviction message
Generate the summary message @param msg the msg to be checked against the cache @return A list of eviction message
public List<String> generateSummaryMessage(String msg) {
    List<String> evictionMessages = new ArrayList<>();
    Long currentTime;
    currentTime = System.currentTimeMillis();
    LRU_MEMORY_USAGE =
        cache.containsKey(msg) ? LRU_MEMORY_USAGE + LONG_SIZE : LRU_MEMORY_USAGE + calculateStringSize(msg) + LONG_SIZE;
    boolean evicted = cache.put(msg, currentTime);
    String evictedMsg = cache.getEvictedMsg();
    LogMetadata metadata = cache.getEvictedMsgData();
    if (!pq.containsKey(msg)) {
      pq.put(msg, currentTime);
      PQ_MEMORY_USAGE += calculateStringSize(msg) + LONG_SIZE;
    }
    if (evicted) {
      if (metadata.getTimeStamp().size() > this.LOG_CACHE_THRESHOLD) {
        String
            msgToLog =
            generateSingleEvictionSummary(evictedMsg, MESSAGE.SIZE_EVICTION.toString(), metadata);
        assert (msgToLog != null);
        evictionMessages.add(msgToLog);
      }
      LRU_MEMORY_USAGE -= metadata.getTimeStamp().size() * LONG_SIZE + calculateStringSize(evictedMsg) ;
      PQ_MEMORY_USAGE -= calculateStringSize(evictedMsg) + LONG_SIZE;
      pq.remove(evictedMsg);
    }
    currentTime = System.currentTimeMillis();
    Entry<String, Long> top = getEarliestTimestamp();
    while (true) {
      if (top == null || currentTime - top.getValue() < LOG_TIME_THRESHOLD || pq.size() == 0) {
        break;
      }
      LogMetadata metadata1 = cache.get(top.getKey());
      if (metadata1.getTimeStamp().size() > this.LOG_CACHE_THRESHOLD) {
        String
            msgToLog1 =
            generateSingleEvictionSummary(top.getKey(), MESSAGE.TIME_EVICTION.toString(), metadata1);
        assert (msgToLog1 != null);
        evictionMessages.add(msgToLog1);
      }
      PQ_MEMORY_USAGE -= LONG_SIZE + calculateStringSize(top.getKey());
      LRU_MEMORY_USAGE -= cache.get(top.getKey()).getTimeStamp().size() * LONG_SIZE +  calculateStringSize(top.getKey());
      removeEarliestTimestamp();
      cache.remove(top.getKey());
      top = getEarliestTimestamp();
    }
    List<String> result = flushMessageIfOutOfMemory(evictionMessages);
    return result;
  }
public List < String > generateSummaryMessage ( String msg ) { List < String > evictionMessages = new ArrayList < > ( ) ; Long currentTime ; currentTime = System . currentTimeMillis ( ) ; LRU_MEMORY_USAGE = cache . containsKey ( msg ) ? LRU_MEMORY_USAGE + LONG_SIZE : LRU_MEMORY_USAGE + calculateStringSize ( msg ) + LONG_SIZE ; boolean evicted = cache . put ( msg , currentTime ) ; String evictedMsg = cache . getEvictedMsg ( ) ; LogMetadata metadata = cache . getEvictedMsgData ( ) ; if ( ! pq . containsKey ( msg ) ) { pq . put ( msg , currentTime ) ; PQ_MEMORY_USAGE += calculateStringSize ( msg ) + LONG_SIZE ; } if ( evicted ) { if ( metadata . getTimeStamp ( ) . size ( ) > this . LOG_CACHE_THRESHOLD ) { String msgToLog = generateSingleEvictionSummary ( evictedMsg , MESSAGE . SIZE_EVICTION . toString ( ) , metadata ) ; assert ( msgToLog != null ) ; evictionMessages . add ( msgToLog ) ; } LRU_MEMORY_USAGE -= metadata . getTimeStamp ( ) . size ( ) * LONG_SIZE + calculateStringSize ( evictedMsg ) ; PQ_MEMORY_USAGE -= calculateStringSize ( evictedMsg ) + LONG_SIZE ; pq . remove ( evictedMsg ) ; } currentTime = System . currentTimeMillis ( ) ; Entry < String , Long > top = getEarliestTimestamp ( ) ; while ( true ) { if ( top == null || currentTime - top . getValue ( ) < LOG_TIME_THRESHOLD || pq . size ( ) == 0 ) { break ; } LogMetadata metadata1 = cache . get ( top . getKey ( ) ) ; if ( metadata1 . getTimeStamp ( ) . size ( ) > this . LOG_CACHE_THRESHOLD ) { String msgToLog1 = generateSingleEvictionSummary ( top . getKey ( ) , MESSAGE . TIME_EVICTION . toString ( ) , metadata1 ) ; assert ( msgToLog1 != null ) ; evictionMessages . add ( msgToLog1 ) ; } PQ_MEMORY_USAGE -= LONG_SIZE + calculateStringSize ( top . getKey ( ) ) ; LRU_MEMORY_USAGE -= cache . get ( top . getKey ( ) ) . getTimeStamp ( ) . size ( ) * LONG_SIZE + calculateStringSize ( top . getKey ( ) ) ; removeEarliestTimestamp ( ) ; cache . remove ( top . getKey ( ) ) ; top = getEarliestTimestamp ( ) ; } List < String > result = flushMessageIfOutOfMemory ( evictionMessages ) ; return result ; }
Generate the summary message
 @param msg the msg to be checked against the cache
 @return A list of eviction message
Generate the summary message @param msg the msg to be checked against the cache @return A list of eviction message
// add the timestamp of the first occurrence of the message to the priorityQueue // Cache Full, evict the message from the cache and update the priorityQueue // update the priorityQueue; // Time Eviction, expire the old entries // Remove the evicted message from the cache and pq, update the memory count // check the memory limit and flush the messages if necessary