@Test public void testBuffer1() throws Exception { assertTrue(OneTimeLogger.isEligible("Message here")); assertFalse(OneTimeLogger.isEligible("Message here")); assertTrue(OneTimeLogger.isEligible("Message here 23")); }
protected static boolean isEligible(String message) { try { lock.readLock().lock(); if (hashSet.contains(message)) return false; } finally { lock.readLock().unlock(); } try { lock.writeLock().lock(); if (buffer.size() >= 100) { String rem = buffer.remove(); hashSet.remove(rem); } buffer.add(message); hashSet.add(message); return true; } finally { lock.writeLock().unlock(); } }
OneTimeLogger { protected static boolean isEligible(String message) { try { lock.readLock().lock(); if (hashSet.contains(message)) return false; } finally { lock.readLock().unlock(); } try { lock.writeLock().lock(); if (buffer.size() >= 100) { String rem = buffer.remove(); hashSet.remove(rem); } buffer.add(message); hashSet.add(message); return true; } finally { lock.writeLock().unlock(); } } }
OneTimeLogger { protected static boolean isEligible(String message) { try { lock.readLock().lock(); if (hashSet.contains(message)) return false; } finally { lock.readLock().unlock(); } try { lock.writeLock().lock(); if (buffer.size() >= 100) { String rem = buffer.remove(); hashSet.remove(rem); } buffer.add(message); hashSet.add(message); return true; } finally { lock.writeLock().unlock(); } }  }
OneTimeLogger { protected static boolean isEligible(String message) { try { lock.readLock().lock(); if (hashSet.contains(message)) return false; } finally { lock.readLock().unlock(); } try { lock.writeLock().lock(); if (buffer.size() >= 100) { String rem = buffer.remove(); hashSet.remove(rem); } buffer.add(message); hashSet.add(message); return true; } finally { lock.writeLock().unlock(); } }  static void info(Logger logger, String format, Object... arguments); static void warn(Logger logger, String format, Object... arguments); static void error(Logger logger, String format, Object... arguments); static void reset(); }
OneTimeLogger { protected static boolean isEligible(String message) { try { lock.readLock().lock(); if (hashSet.contains(message)) return false; } finally { lock.readLock().unlock(); } try { lock.writeLock().lock(); if (buffer.size() >= 100) { String rem = buffer.remove(); hashSet.remove(rem); } buffer.add(message); hashSet.add(message); return true; } finally { lock.writeLock().unlock(); } }  static void info(Logger logger, String format, Object... arguments); static void warn(Logger logger, String format, Object... arguments); static void error(Logger logger, String format, Object... arguments); static void reset();  }