HostTimeoutTracker extends BackgroundCassandraHostService { public boolean checkTimeout(CassandraHost cassandraHost) { timeouts.putIfAbsent(cassandraHost, new LinkedBlockingQueue<Long>()); long currentTimeMillis = System.currentTimeMillis(); timeouts.get(cassandraHost).add(currentTimeMillis); boolean timeout = false; if ( timeouts.get(cassandraHost).size() > timeoutCounter) { Long last = timeouts.get(cassandraHost).remove(); if (last.longValue() < (currentTimeMillis - timeoutWindow)) { timeout = true; connectionManager.suspendCassandraHost(cassandraHost); suspended.putIfAbsent(cassandraHost, currentTimeMillis); } } return timeout; } HostTimeoutTracker(HConnectionManager connectionManager,
      CassandraHostConfigurator cassandraHostConfigurator); boolean checkTimeout(CassandraHost cassandraHost); static final int DEF_TIMEOUT_COUNTER; static final int DEF_TIMEOUT_WINDOW; static final int DEF_NODE_SUSPENSION_DURATION_IN_SECONDS; static final int DEF_NODE_UNSUSPEND_CHECK_DELAY_IN_SECONDS; }
@Test public void testTrackHostLatency() { CassandraHost cassandraHost = new CassandraHost("localhost:9170"); assertFalse(hostTimeoutTracker.checkTimeout(cassandraHost)); assertFalse(hostTimeoutTracker.checkTimeout(cassandraHost)); assertFalse(hostTimeoutTracker.checkTimeout(cassandraHost)); try { Thread.currentThread().sleep(501); } catch (InterruptedException e) { } assertTrue(hostTimeoutTracker.checkTimeout(cassandraHost)); }