lastTime = now;
      protected void doThrottle()      {         if (rate == 0)         {            return;         }         long now = System.currentTimeMillis();         if (log.isTraceEnabled()) { log.trace("doThrottle(" + now + ")"); }         if (lastTime != 0)         {            long elapsedTime = now - lastTime;                        if (elapsedTime >= SAMPLE_PERIOD)            {               long msgs = currentMessageCount - lastCount;                              //log.info("elapsedTime is " + elapsedTime);               //log.info("msgs:" + msgs);                              double targetMsgs = rate * (double)elapsedTime / 1000;                              //log.info("Target msgs:" + targetMsgs);                              if (msgs > targetMsgs)               {                  //Need to throttle                  //log.info("throttling");                                    long throttleTime = (long)((1000 * (double)msgs / rate) - elapsedTime);                                                      //log.info("Throttle time is:" + throttleTime);                  try                  {                     Thread.sleep(throttleTime);                  }                  catch (InterruptedException e)                  {                     //Ignore                  }               }                              lastTime = now;                              lastCount = currentMessageCount;            }         }         else         {            lastTime = now;         }      }