本文整理了Java中org.apache.kafka.common.utils.Utils.abs()
方法的一些代码示例,展示了Utils.abs()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.abs()
方法的具体详情如下:
包路径:org.apache.kafka.common.utils.Utils
类名称:Utils
方法名:abs
[英]Get the absolute value of the given number. If the number is Int.MinValue return 0. This is different from java.lang.Math.abs or scala.math.abs in that they return Int.MinValue (!).
[中]获取给定数字的绝对值。如果数字为Int.MinValue,则返回0。这与java不同。朗,数学。abs或scala。数学因为它们返回Int.MinValue(!)。
代码示例来源:origin: apache/kafka
@Test
public void testAbs() {
assertEquals(0, Utils.abs(Integer.MIN_VALUE));
assertEquals(10, Utils.abs(-10));
assertEquals(10, Utils.abs(10));
assertEquals(0, Utils.abs(0));
assertEquals(1, Utils.abs(-1));
}
代码示例来源:origin: me.jeffshaw.kafka/kafka-clients
List<PartitionInfo> availablePartitions = cluster.availablePartitionsForTopic(record.topic());
if (availablePartitions.size() > 0) {
int part = Utils.abs(nextValue) % availablePartitions.size();
return availablePartitions.get(part).partition();
} else {
return Utils.abs(nextValue) % numPartitions;
return Utils.abs(Utils.murmur2(record.key())) % numPartitions;
代码示例来源:origin: me.jeffshaw.kafka/kafka-clients
/**
* Choose the node with the fewest outstanding requests which is at least eligible for connection. This method will
* prefer a node with an existing connection, but will potentially choose a node for which we don't yet have a
* connection if all existing connections are in use. This method will never choose a node for which there is no
* existing connection and from which we have disconnected within the reconnect backoff period.
* @return The node with the fewest in-flight requests.
*/
public Node leastLoadedNode(long now) {
List<Node> nodes = this.metadata.fetch().nodes();
int inflight = Integer.MAX_VALUE;
Node found = null;
for (int i = 0; i < nodes.size(); i++) {
int idx = Utils.abs((this.nodeIndexOffset + i) % nodes.size());
Node node = nodes.get(idx);
int currInflight = this.inFlightRequests.inFlightRequestCount(node.id());
if (currInflight == 0 && this.connectionStates.isConnected(node.id())) {
// if we find an established connection with no in-flight requests we can stop right away
return node;
} else if (!this.connectionStates.isBlackedOut(node.id(), now) && currInflight < inflight) {
// otherwise if this is the best we have found so far, record that
inflight = currInflight;
found = node;
}
}
return found;
}
内容来源于网络,如有侵权,请联系作者删除!