public void runOnce(){
  List<MetricDatumWithKey<KeyType>> dataToPublish=null;
synchronized (queue) {
    long timeSinceFlush=Math.max(0,getTime() - lastFlushTime);
    if (timeSinceFlush >= bufferTimeMillis || queue.size() >= flushSize || shuttingDown) {
      dataToPublish=queue.drain(flushSize);
      LOG.debug("Drained {} datums from queue",dataToPublish.size());
      if (shuttingDown) {
        LOG.debug("Shutting down with {} datums left on the queue",queue.size());
        shutdown=queue.isEmpty();
      }
    }
 else {
      long waitTime=bufferTimeMillis - timeSinceFlush;
      LOG.debug("Waiting up to {}ms for {} more datums to appear.",waitTime,flushSize - queue.size());
      try {
        queue.wait(waitTime);
      }
 catch (      InterruptedException e) {
      }
    }
  }
  if (dataToPublish != null) {
    try {
      metricsPublisher.publishMetrics(dataToPublish);
    }
 catch (    Throwable t) {
      LOG.error("Caught exception thrown by metrics Publisher in CWPublisherRunnable",t);
    }
    lastFlushTime=getTime() + nextJitterValueToUse;
    if (maxJitter != 0) {
      nextJitterValueToUse=maxJitter - rand.nextInt(2 * maxJitter);
    }
  }
}

public void runOnce ( ) { List < MetricDatumWithKey < KeyType > > dataToPublish = null ; synchronized ( queue ) { long timeSinceFlush = Math . max ( 0 , getTime ( ) - lastFlushTime ) ; if ( timeSinceFlush >= bufferTimeMillis || queue . size ( ) >= flushSize || shuttingDown ) { dataToPublish = queue . drain ( flushSize ) ; LOG . debug ( "Drained {} datums from queue" , dataToPublish . size ( ) ) ; if ( shuttingDown ) { LOG . debug ( "Shutting down with {} datums left on the queue" , queue . size ( ) ) ; shutdown = queue . isEmpty ( ) ; } } else { long waitTime = bufferTimeMillis - timeSinceFlush ; LOG . debug ( "Waiting up to {}ms for {} more datums to appear." , waitTime , flushSize - queue . size ( ) ) ; try { queue . wait ( waitTime ) ; } catch ( InterruptedException e ) { } } } if ( dataToPublish != null ) { try { metricsPublisher . publishMetrics ( dataToPublish ) ; } catch ( Throwable t ) { LOG . error ( "Caught exception thrown by metrics Publisher in CWPublisherRunnable" , t ) ; } lastFlushTime = getTime ( ) + nextJitterValueToUse ; if ( maxJitter != 0 ) { nextJitterValueToUse = maxJitter - rand . nextInt ( 2 * maxJitter ) ; } } }
exposed for testing purposes .
