/**
* This helper method provides a comparison implementation to order or compare two distinct
* sequence ids by their internal timestamp <b>and</b> counter value.
*
* @param sequenceId1 the first sequence id to be compared
* @param sequenceId2 the second sequence if to be compared
* @param maxLogicalNodeCount the maximum node count that was specified at generation time
* @return a negative integer, zero, or a positive integer as the first argument is less than,
* equal to, or greater than the second.
* @throws SnowcastMaxLogicalNodeIdOutOfBoundsException when maxLogicalNodeCount is outside of the legal range
*/
public static int compareSequence(long sequenceId1, long sequenceId2, @Min(128) @Max(8192) int maxLogicalNodeCount) {
int nodeCount = calculateBoundedMaxLogicalNodeCount(maxLogicalNodeCount);
int nodeIdShifting = calculateLogicalNodeShifting(nodeCount);
long counterMask = calculateCounterMask(nodeCount, nodeIdShifting);
long timestampValue1 = timestampValue(sequenceId1);
long timestampValue2 = timestampValue(sequenceId2);
int compare = Long.compare(timestampValue1, timestampValue2);
if (compare != 0) {
return compare;
}
int counterValue1 = InternalSequencerUtils.counterValue(sequenceId1, counterMask);
int counterValue2 = InternalSequencerUtils.counterValue(sequenceId2, counterMask);
return Integer.compare(counterValue1, counterValue2);
}
SnowcastSequenceUtils.java 文件源码
java
阅读 28
收藏 0
点赞 0
评论 0
项目:snowcast
作者:
评论列表
文章目录