class RateControl {

  protected long sleepToMaintainRate(long duration) throws InterruptedException, DatabusException
  {
    if (duration <= 0 )
    {
      throw new DatabusException("Negative duration specified");
    }

    long remainingTimeNSec = duration;
    long remainingTimeMSec = remainingTimeNSec / DbusConstants.NUM_NSECS_IN_MSEC;
    remainingTimeNSec -= (remainingTimeMSec * DbusConstants.NUM_NSECS_IN_MSEC);

    // Make sleep at msec resolution. Err on the side of sleeping for a msec resolution instead of nsecs
    // to keep rate strictly less than specified rate
    if (remainingTimeNSec > 0)
      remainingTimeMSec++;

    boolean needToSleep = (remainingTimeMSec > 0);
    if (needToSleep)
    {
      if (LOG.isDebugEnabled())
      {
        LOG.debug("Sleeping for remainingTimeMSec = " + remainingTimeMSec);        	
      }
      _ra.sleep(remainingTimeMSec);
      _numSleeps++;
    }
    else
    {
      if (LOG.isDebugEnabled())
      {
        LOG.debug("No need to sleep. remainingTimeMSec = " + remainingTimeMSec);
      }
    }

    return remainingTimeMSec;
  }

  public  RateControl(long numEventsPerSec, long throttleDurationInSecs);

}