public void checkThrottle() { // optional throttling if (!config.isThrottled()) { return; } long sleepMillis; double throttledEventsPerSecond = config.getThrottledEventsPerSecond(); boolean isEvents = (throttledEventsPerSecond > 0); int throttledBytesPerSecond = isEvents ? 0 : config.getThrottledBytesPerSecond(); logger.fine( "throttling " + (isEvents // events ? (timer.getEventsPerSecond() + " tps to " + throttledEventsPerSecond + " tps") // bytes : (timer.getBytesPerSecond() + " B/sec to " + throttledBytesPerSecond + " B/sec"))); // call the methods every time while ((throttledEventsPerSecond > 0 && (throttledEventsPerSecond < timer.getEventsPerSecond())) || (throttledBytesPerSecond > 0 && (throttledBytesPerSecond < timer.getBytesPerSecond()))) { if (isEvents) { sleepMillis = (long) Math.ceil( Timer.MILLISECONDS_PER_SECOND * ((timer.getEventCount() / throttledEventsPerSecond) - timer.getDurationSeconds())); } else { sleepMillis = (long) Math.ceil( Timer.MILLISECONDS_PER_SECOND * ((timer.getBytes() / throttledBytesPerSecond) - timer.getDurationSeconds())); } sleepMillis = Math.max(sleepMillis, 1); logger.finer("sleeping " + sleepMillis); try { Thread.sleep(sleepMillis); } catch (InterruptedException e) { // reset interrupt status and continue Thread.interrupted(); logger.logException("interrupted", e); } } logger.fine( "throttled to " + (isEvents ? (timer.getEventsPerSecond() + " tps") : (timer.getBytesPerSecond() + " B/sec"))); }
/** @param _count */ public void setFinalTaskCount(long _count) { synchronized (taskCountMutex) { if (taskCountFinal) { // get the stack trace to track this down throw new FatalException("BUG!", new SyncException("setter on final task count " + _count)); } if (_count != taskCount) { // get the stack trace to track this down throw new FatalException( "BUG!", new SyncException("setter on final task count " + _count + " != " + taskCount)); } logger.fine("setting " + _count); taskCountFinal = true; } }