@Override public void check() { boolean retry = true; while (retry) { try { for (CriticalComponent component : components) { if (component.isExpired(timeoutNanoSeconds)) { fireAction(component); // no need to keep running if there's already a component failed return; } } retry = false; // got to the end of the list, no need to retry } catch (ConcurrentModificationException dontCare) { // lets retry on the loop } } }
@Override public void check() { boolean retry = true; while (retry) { try { for (CriticalComponent component : components) { if (component.isExpired(timeoutNanoSeconds)) { fireAction(component); // no need to keep running if there's already a component failed return; } } retry = false; // got to the end of the list, no need to retry } catch (ConcurrentModificationException dontCare) { // lets retry on the loop } } }
@Override public void check() { boolean retry = true; while (retry) { try { for (CriticalComponent component : components) { if (component.isExpired(timeoutNanoSeconds)) { fireAction(component); // no need to keep running if there's already a component failed return; } } retry = false; // got to the end of the list, no need to retry } catch (ConcurrentModificationException dontCare) { // lets retry on the loop } } }
@Override public void check() { boolean retry = true; while (retry) { try { for (CriticalComponent component : components) { if (component.isExpired(timeoutNanoSeconds)) { fireAction(component); // no need to keep running if there's already a component failed return; } } retry = false; // got to the end of the list, no need to retry } catch (ConcurrentModificationException dontCare) { // lets retry on the loop } } }
@Override public void check() { boolean retry = true; while (retry) { try { for (CriticalComponent component : components) { if (component.isExpired(timeoutNanoSeconds)) { fireAction(component); // no need to keep running if there's already a component failed return; } } retry = false; // got to the end of the list, no need to retry } catch (ConcurrentModificationException dontCare) { // lets retry on the loop } } }
@Override public void check() { boolean retry = true; while (retry) { try { for (CriticalComponent component : components) { if (component.isExpired(timeoutNanoSeconds)) { fireAction(component); // no need to keep running if there's already a component failed return; } } retry = false; // got to the end of the list, no need to retry } catch (ConcurrentModificationException dontCare) { // lets retry on the loop } } }
@Override public void check() { boolean retry = true; while (retry) { try { for (CriticalComponent component : components) { if (component.isExpired(timeoutNanoSeconds)) { fireAction(component); // no need to keep running if there's already a component failed return; } } retry = false; // got to the end of the list, no need to retry } catch (ConcurrentModificationException dontCare) { // lets retry on the loop } } }
@Test public void testEnterNoLeaveNoExpire() throws Exception { analyzer = new CriticalAnalyzerImpl().setTimeout(10, TimeUnit.MILLISECONDS).setCheckTime(5, TimeUnit.MILLISECONDS); CriticalComponent component = new CriticalComponentImpl(analyzer, 2); component.enterCritical(0); Assert.assertFalse(component.isExpired(TimeUnit.MINUTES.toNanos(1))); analyzer.stop(); }
@Test public void testEnterNoLeaveExpire() throws Exception { analyzer = new CriticalAnalyzerImpl().setTimeout(10, TimeUnit.MILLISECONDS).setCheckTime(5, TimeUnit.MILLISECONDS); CriticalComponent component = new CriticalComponentImpl(analyzer, 2); component.enterCritical(0); Thread.sleep(50); Assert.assertTrue(component.isExpired(0)); analyzer.stop(); }