com.javanut.pronghorn.pipe.PipeRegulator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pronghorn-pipes Show documentation
Show all versions of pronghorn-pipes Show documentation
Ring buffer based queuing utility for applications that require high performance and/or a small
footprint. Well suited for embedded and stream based processing.
package com.javanut.pronghorn.pipe;
public class PipeRegulator {
private long regulatorTimeBaseNS = System.currentTimeMillis()*MS_TO_NS;
private long regulatorPositionBase = 0;
private long divisorSizeNS;
private static final long MS_TO_NS = 1_000_000L;
/**
* Helper method so the scheduler can get the number of nanos that this stage should wait before reschedule.
*
* This supports both regulating the consumer/producer of data based on contract requirements of the connected software.
*
* @param maxMsgPerMs
*/
public PipeRegulator(int maxMsgPerMs, int avgMsgSize) {
this.divisorSizeNS = MS_TO_NS*(long)avgMsgSize*(long)maxMsgPerMs;
}
public static > long computeRateLimitDelay(Pipe pipe, long position, PipeRegulator regulator) {
long expectedNow = regulator.regulatorTimeBaseNS + ((position-regulator.regulatorPositionBase)/regulator.divisorSizeNS);
return expectedNow-(System.currentTimeMillis()*MS_TO_NS);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy