public void checkQueueState(){
  LOGGER.debug("checkQueueState - Check the state of the local queue depending on the tier we are in ");
  int unfinishedJobs=statsUtil.getUnfinishedJobs();
  LOGGER.debug("checkQueueState - maxUnfinishedJobs: " + maxUnfinishedJobs + ",  unfinishedJobs: "+ unfinishedJobs);
  if (jobCount == 4) {
    LOGGER.info("checkQueueState - First 4 jobs : maxUnfinishedJobs: " + maxUnfinishedJobs + ",  unfinishedJobs: "+ unfinishedJobs);
    long now=System.currentTimeMillis();
    if ((now - timeFirstMessageReceived) < 10 * 1000) {
      final long expectedSynchTime=statsUtil.getCurrentMasterClockTime() + (25 * 1000);
      final long waitMasterSyncTime=expectedSynchTime - now;
      if (waitMasterSyncTime > 0) {
        try {
          LOGGER.debug("First 4 messages ... ");
          Utilities.verboseLog("Master clock sync: wake up at " + expectedSynchTime + " i.e. in "+ waitMasterSyncTime+ " millis");
          Thread.sleep(waitMasterSyncTime);
        }
 catch (        InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
  }
  if (statsUtil.isStopRemoteQueueJmsContainer()) {
    LOGGER.debug("checkQueueState : isStopRemoteQueueJmsContainer = true");
    return;
  }
 else {
    boolean stopRemoteQueue=false;
    if ((jobCount % (maxUnfinishedJobs / (Math.pow(2,statsUtil.getTier() - 1))) == 0)) {
      statsUtil.updateStatsUtilJobCounts();
      unfinishedJobs=statsUtil.getUnfinishedJobs();
    }
switch (statsUtil.getTier()) {
case 1:
      if (unfinishedJobs > maxUnfinishedJobs) {
        stopRemoteQueue=true;
      }
    break;
case 2:
  if (unfinishedJobs > maxUnfinishedJobs / 2) {
    stopRemoteQueue=true;
  }
break;
default :
if (unfinishedJobs > maxUnfinishedJobs / (Math.pow(2,statsUtil.getTier()))) {
stopRemoteQueue=true;
}
}
if (stopRemoteQueue) {
LOGGER.debug("checkQueueState - Disable remote listener ");
statsUtil.setStopRemoteQueueJmsContainer(true);
try {
Thread.sleep(15 * 1000);
}
 catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

public void checkQueueState ( ) { LOGGER . debug ( "checkQueueState - Check the state of the local queue depending on the tier we are in " ) ; int unfinishedJobs = statsUtil . getUnfinishedJobs ( ) ; LOGGER . debug ( "checkQueueState - maxUnfinishedJobs: " + maxUnfinishedJobs + ",  unfinishedJobs: " + unfinishedJobs ) ; if ( jobCount == 4 ) { LOGGER . info ( "checkQueueState - First 4 jobs : maxUnfinishedJobs: " + maxUnfinishedJobs + ",  unfinishedJobs: " + unfinishedJobs ) ; long now = System . currentTimeMillis ( ) ; if ( ( now - timeFirstMessageReceived ) < 10 * 1000 ) { final long expectedSynchTime = statsUtil . getCurrentMasterClockTime ( ) + ( 25 * 1000 ) ; final long waitMasterSyncTime = expectedSynchTime - now ; if ( waitMasterSyncTime > 0 ) { try { LOGGER . debug ( "First 4 messages ... " ) ; Utilities . verboseLog ( "Master clock sync: wake up at " + expectedSynchTime + " i.e. in " + waitMasterSyncTime + " millis" ) ; Thread . sleep ( waitMasterSyncTime ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } } } } if ( statsUtil . isStopRemoteQueueJmsContainer ( ) ) { LOGGER . debug ( "checkQueueState : isStopRemoteQueueJmsContainer = true" ) ; return ; } else { boolean stopRemoteQueue = false ; if ( ( jobCount % ( maxUnfinishedJobs / ( Math . pow ( 2 , statsUtil . getTier ( ) - 1 ) ) ) == 0 ) ) { statsUtil . updateStatsUtilJobCounts ( ) ; unfinishedJobs = statsUtil . getUnfinishedJobs ( ) ; } switch ( statsUtil . getTier ( ) ) { case 1 : if ( unfinishedJobs > maxUnfinishedJobs ) { stopRemoteQueue = true ; } break ; case 2 : if ( unfinishedJobs > maxUnfinishedJobs / 2 ) { stopRemoteQueue = true ; } break ; default : if ( unfinishedJobs > maxUnfinishedJobs / ( Math . pow ( 2 , statsUtil . getTier ( ) ) ) ) { stopRemoteQueue = true ; } } if ( stopRemoteQueue ) { LOGGER . debug ( "checkQueueState - Disable remote listener " ) ; statsUtil . setStopRemoteQueueJmsContainer ( true ) ; try { Thread . sleep ( 15 * 1000 ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } } } }
check if the message quota for this worker has been reached and then block for a few seconds
