@SuppressWarnings("boxing") @Test public void testCanProcess1s() throws InterruptedException { LoadShedder loadShedder = new LoadShedder(1, ONE_SECOND_IN_MINUTES, false, "Test"); for( int i=0; i<3; i++) { assertEquals( true, loadShedder.canProcess() ); assertEquals( false, loadShedder.canProcess() ); Thread.sleep(ONE_SECOND_IN_MILLIS + 1l); } assertEquals( true, loadShedder.canProcess() ); }
public boolean canProcess() { long currentTimeMillis = System.currentTimeMillis(); double deltaMillis = currentTimeMillis - lastSetTime; if ( (deltaMillis <= intervalMillis) || ( lastSetTime == 0 ) ) { counter++; if (counter <= maxLimit) { lastSetTime = currentTimeMillis; return true; } else { if (warnOnLimit && !warningEmitted) { warningEmitted = true; logger.warn("LoadShedder[" + name + "] reached limit of " + maxLimit + " messages per " + intervalMinutes + " mins reached with current count = " + counter); } return false; } } else { counter = 1; lastSetTime = currentTimeMillis; warningEmitted = false; return true; } }
LoadShedder { public boolean canProcess() { long currentTimeMillis = System.currentTimeMillis(); double deltaMillis = currentTimeMillis - lastSetTime; if ( (deltaMillis <= intervalMillis) || ( lastSetTime == 0 ) ) { counter++; if (counter <= maxLimit) { lastSetTime = currentTimeMillis; return true; } else { if (warnOnLimit && !warningEmitted) { warningEmitted = true; logger.warn("LoadShedder[" + name + "] reached limit of " + maxLimit + " messages per " + intervalMinutes + " mins reached with current count = " + counter); } return false; } } else { counter = 1; lastSetTime = currentTimeMillis; warningEmitted = false; return true; } } }
LoadShedder { public boolean canProcess() { long currentTimeMillis = System.currentTimeMillis(); double deltaMillis = currentTimeMillis - lastSetTime; if ( (deltaMillis <= intervalMillis) || ( lastSetTime == 0 ) ) { counter++; if (counter <= maxLimit) { lastSetTime = currentTimeMillis; return true; } else { if (warnOnLimit && !warningEmitted) { warningEmitted = true; logger.warn("LoadShedder[" + name + "] reached limit of " + maxLimit + " messages per " + intervalMinutes + " mins reached with current count = " + counter); } return false; } } else { counter = 1; lastSetTime = currentTimeMillis; warningEmitted = false; return true; } } LoadShedder(final int maxLimit, final int intervalMinutes, final boolean warnOnLimit, String name);  LoadShedder(final int maxLimit, final double intervalMinutes, final boolean warnOnLimit, String name); }
LoadShedder { public boolean canProcess() { long currentTimeMillis = System.currentTimeMillis(); double deltaMillis = currentTimeMillis - lastSetTime; if ( (deltaMillis <= intervalMillis) || ( lastSetTime == 0 ) ) { counter++; if (counter <= maxLimit) { lastSetTime = currentTimeMillis; return true; } else { if (warnOnLimit && !warningEmitted) { warningEmitted = true; logger.warn("LoadShedder[" + name + "] reached limit of " + maxLimit + " messages per " + intervalMinutes + " mins reached with current count = " + counter); } return false; } } else { counter = 1; lastSetTime = currentTimeMillis; warningEmitted = false; return true; } } LoadShedder(final int maxLimit, final int intervalMinutes, final boolean warnOnLimit, String name);  LoadShedder(final int maxLimit, final double intervalMinutes, final boolean warnOnLimit, String name); int getCounter(); boolean getWarn(); int getMaxLimit(); String getName(); boolean canProcess(); long getLastSetTime(); void setLastSetTime(long lastSetTime); }
LoadShedder { public boolean canProcess() { long currentTimeMillis = System.currentTimeMillis(); double deltaMillis = currentTimeMillis - lastSetTime; if ( (deltaMillis <= intervalMillis) || ( lastSetTime == 0 ) ) { counter++; if (counter <= maxLimit) { lastSetTime = currentTimeMillis; return true; } else { if (warnOnLimit && !warningEmitted) { warningEmitted = true; logger.warn("LoadShedder[" + name + "] reached limit of " + maxLimit + " messages per " + intervalMinutes + " mins reached with current count = " + counter); } return false; } } else { counter = 1; lastSetTime = currentTimeMillis; warningEmitted = false; return true; } } LoadShedder(final int maxLimit, final int intervalMinutes, final boolean warnOnLimit, String name);  LoadShedder(final int maxLimit, final double intervalMinutes, final boolean warnOnLimit, String name); int getCounter(); boolean getWarn(); int getMaxLimit(); String getName(); boolean canProcess(); long getLastSetTime(); void setLastSetTime(long lastSetTime);  }