@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(); }
public void leaveCritical() { if (logger.isTraceEnabled()) { CriticalAnalyzer analyzer = component != null ? component.getCriticalAnalyzer() : null; if (analyzer != null) { long nanoTimeout = analyzer.getTimeoutNanoSeconds(); if (isExpired(nanoTimeout)) { logger.trace("Path " + id + " on component " + getComponentName() + " is taking too long, leaving at", new Exception("entered")); logger.trace("Path " + id + " on component " + getComponentName() + " is taking too long, entered at", traceEnter); } } traceEnter = null; } TIME_LEFT_UPDATER.lazySet(this, System.nanoTime()); }
@Test public void testActionOnImpl() throws Exception { analyzer = new CriticalAnalyzerImpl().setTimeout(10, TimeUnit.MILLISECONDS).setCheckTime(5, TimeUnit.MILLISECONDS); CriticalComponent component = new CriticalComponentImpl(analyzer, 2); analyzer.add(component); component.enterCritical(0); component.leaveCritical(0); component.enterCritical(1); CountDownLatch latch = new CountDownLatch(1); analyzer.start(); analyzer.addAction((CriticalComponent comp) -> { System.out.println("component " + comp + " received"); latch.countDown(); }); Assert.assertTrue(latch.await(10, TimeUnit.SECONDS)); 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(); }
public void leaveCritical() { if (logger.isTraceEnabled()) { CriticalAnalyzer analyzer = component != null ? component.getCriticalAnalyzer() : null; if (analyzer != null) { long nanoTimeout = analyzer.getTimeoutNanoSeconds(); if (isExpired(nanoTimeout)) { logger.trace("Path " + id + " on component " + getComponentName() + " is taking too long, leaving at", new Exception("entered")); logger.trace("Path " + id + " on component " + getComponentName() + " is taking too long, entered at", traceEnter); } } traceEnter = null; } TIME_LEFT_UPDATER.lazySet(this, System.nanoTime()); }
@Test public void testNegative() throws Exception { analyzer = new CriticalAnalyzerImpl().setTimeout(10, TimeUnit.MILLISECONDS).setCheckTime(5, TimeUnit.MILLISECONDS); CriticalComponent component = new CriticalComponentImpl(analyzer, 1); analyzer.add(component); component.enterCritical(0); component.leaveCritical(0); CountDownLatch latch = new CountDownLatch(1); analyzer.start(); analyzer.addAction((CriticalComponent comp) -> { System.out.println("component " + comp + " received"); latch.countDown(); }); Assert.assertFalse(latch.await(100, TimeUnit.MILLISECONDS)); analyzer.stop(); }
@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 } } }
public void leaveCritical() { if (logger.isTraceEnabled()) { CriticalAnalyzer analyzer = component != null ? component.getCriticalAnalyzer() : null; if (analyzer != null) { long nanoTimeout = analyzer.getTimeoutNanoSeconds(); if (isExpired(nanoTimeout)) { logger.trace("Path " + id + " on component " + getComponentName() + " is taking too long, leaving at", new Exception("entered")); logger.trace("Path " + id + " on component " + getComponentName() + " is taking too long, entered at", traceEnter); } } traceEnter = null; } TIME_LEFT_UPDATER.lazySet(this, System.nanoTime()); }
@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 } } }
public void leaveCritical() { if (logger.isTraceEnabled()) { CriticalAnalyzer analyzer = component != null ? component.getCriticalAnalyzer() : null; if (analyzer != null) { long nanoTimeout = analyzer.getTimeoutNanoSeconds(); if (isExpired(nanoTimeout)) { logger.trace("Path " + id + " on component " + getComponentName() + " is taking too long, leaving at", new Exception("entered")); logger.trace("Path " + id + " on component " + getComponentName() + " is taking too long, entered at", traceEnter); } } traceEnter = null; } TIME_LEFT_UPDATER.lazySet(this, System.nanoTime()); }
@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 } } }
public void leaveCritical() { if (logger.isTraceEnabled()) { CriticalAnalyzer analyzer = component != null ? component.getCriticalAnalyzer() : null; if (analyzer != null) { long nanoTimeout = analyzer.getTimeoutNanoSeconds(); if (isExpired(nanoTimeout)) { logger.trace("Path " + id + " on component " + getComponentName() + " is taking too long, leaving at", new Exception("entered")); logger.trace("Path " + id + " on component " + getComponentName() + " is taking too long, entered at", traceEnter); } } traceEnter = null; } TIME_LEFT_UPDATER.lazySet(this, System.nanoTime()); }
@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 } } }