@Override public void run(){
  clusterCache.acquireWriteLockOnKey(LAST_ALIVE_TIMER_CHECK_LONG);
  try {
    Long lastCheck=(Long)clusterCache.getCopy(LAST_ALIVE_TIMER_CHECK_LONG);
    if (System.currentTimeMillis() - lastCheck.longValue() < 9000) {
      LOGGER.debug("Skipping alive check as already performed.");
    }
 else {
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("run() : checking alive timers ... ");
      }
      short aliveDownCount=0;
      try {
        for (        Long currentId : aliveTimerCache.getKeys()) {
          AliveTimer aliveTimerCopy=null;
          boolean aliveExpiration=false;
          aliveTimerCopy=aliveTimerCache.getCopy(currentId);
          if (aliveTimerCopy.isActive()) {
            if (aliveTimerFacade.hasExpired(currentId)) {
              aliveTimerFacade.stop(currentId);
              aliveExpiration=true;
              aliveDownCount++;
            }
          }
 else {
            aliveDownCount++;
          }
          if (aliveExpiration) {
            onAliveTimerExpiration(currentId);
          }
        }
        if (!alarmActive && aliveDownCount > WARNING_THRESHOLD) {
          alarmActive=true;
          SMS_LOGGER.warn("Over " + WARNING_THRESHOLD + " DAQ/Equipment are currently down.");
        }
 else         if (alarmActive && warningSwitchOffCountDown.decrementAndGet() == 0) {
          SMS_LOGGER.warn("DAQ/Equipment status back to normal (" + aliveDownCount + " detected as down)");
          alarmActive=false;
          warningSwitchOffCountDown=new AtomicInteger(SWITCH_OFF_COUNTDOWN);
        }
      }
 catch (      CacheElementNotFoundException cacheEx) {
        LOGGER.warn("Failed to locate alive timer in cache on expiration check (may happen exceptionally if just removed).",cacheEx);
      }
catch (      Exception e) {
        LOGGER.error("Unexpected exception when checking the alive timers",e);
      }
      lastCheck=Long.valueOf(System.currentTimeMillis());
      clusterCache.put(LAST_ALIVE_TIMER_CHECK_LONG,lastCheck);
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("run() : finished checking alive timers ... ");
      }
    }
  }
  finally {
    clusterCache.releaseWriteLockOnKey(LAST_ALIVE_TIMER_CHECK_LONG);
  }
}

@ Override public void run ( ) { clusterCache . acquireWriteLockOnKey ( LAST_ALIVE_TIMER_CHECK_LONG ) ; try { Long lastCheck = ( Long ) clusterCache . getCopy ( LAST_ALIVE_TIMER_CHECK_LONG ) ; if ( System . currentTimeMillis ( ) - lastCheck . longValue ( ) < 9000 ) { LOGGER . debug ( "Skipping alive check as already performed." ) ; } else { if ( LOGGER . isDebugEnabled ( ) ) { LOGGER . debug ( "run() : checking alive timers ... " ) ; } short aliveDownCount = 0 ; try { for ( Long currentId : aliveTimerCache . getKeys ( ) ) { AliveTimer aliveTimerCopy = null ; boolean aliveExpiration = false ; aliveTimerCopy = aliveTimerCache . getCopy ( currentId ) ; if ( aliveTimerCopy . isActive ( ) ) { if ( aliveTimerFacade . hasExpired ( currentId ) ) { aliveTimerFacade . stop ( currentId ) ; aliveExpiration = true ; aliveDownCount ++ ; } } else { aliveDownCount ++ ; } if ( aliveExpiration ) { onAliveTimerExpiration ( currentId ) ; } } if ( ! alarmActive && aliveDownCount > WARNING_THRESHOLD ) { alarmActive = true ; SMS_LOGGER . warn ( "Over " + WARNING_THRESHOLD + " DAQ/Equipment are currently down." ) ; } else if ( alarmActive && warningSwitchOffCountDown . decrementAndGet ( ) == 0 ) { SMS_LOGGER . warn ( "DAQ/Equipment status back to normal (" + aliveDownCount + " detected as down)" ) ; alarmActive = false ; warningSwitchOffCountDown = new AtomicInteger ( SWITCH_OFF_COUNTDOWN ) ; } } catch ( CacheElementNotFoundException cacheEx ) { LOGGER . warn ( "Failed to locate alive timer in cache on expiration check (may happen exceptionally if just removed)." , cacheEx ) ; } catch ( Exception e ) { LOGGER . error ( "Unexpected exception when checking the alive timers" , e ) ; } lastCheck = Long . valueOf ( System . currentTimeMillis ( ) ) ; clusterCache . put ( LAST_ALIVE_TIMER_CHECK_LONG , lastCheck ) ; if ( LOGGER . isDebugEnabled ( ) ) { LOGGER . debug ( "run() : finished checking alive timers ... " ) ; } } } finally { clusterCache . releaseWriteLockOnKey ( LAST_ALIVE_TIMER_CHECK_LONG ) ; } }
run method of the alivetimermanager thread .
