import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
-import com.google.common.base.Stopwatch;
/**
* Channel handler which bypasses wraps on top of normal Netty pipeline, allowing
*/
this.queue = new LinkedBlockingQueue<>(queueDepth);
this.channel = Preconditions.checkNotNull(channel);
- this.maxWorkTime = DEFAULT_WORKTIME_MICROS;
+ this.maxWorkTime = TimeUnit.MICROSECONDS.toNanos(DEFAULT_WORKTIME_MICROS);
}
/**
* uncontended.
*/
private synchronized void flush() {
- final Stopwatch w = new Stopwatch().start();
+ final long start = System.nanoTime();
+ final long deadline = start + maxWorkTime;
LOG.debug("Dequeuing messages to channel {}", channel);
* should be able to perform dynamic adjustments here.
* is that additional complexity needed, though?
*/
- if ((messages % WORKTIME_RECHECK_MSGS) == 0 &&
- w.elapsed(TimeUnit.MICROSECONDS) >= maxWorkTime) {
- LOG.trace("Exceeded allotted work time {}us", maxWorkTime);
- break;
+ if ((messages % WORKTIME_RECHECK_MSGS) == 0) {
+ if (System.nanoTime() >= deadline) {
+ LOG.trace("Exceeded allotted work time {}us",
+ TimeUnit.NANOSECONDS.toMicros(maxWorkTime));
+ break;
+ }
}
}
channel.flush();
}
- w.stop();
+ final long stop = System.nanoTime();
LOG.debug("Flushed {} messages in {}us to channel {}",
- messages, w.elapsed(TimeUnit.MICROSECONDS), channel);
+ messages, TimeUnit.NANOSECONDS.toMicros(stop - start), channel);
/*
* We are almost ready to terminate. This is a bit tricky, because