From 40adaf76df73b00ee9d761c96a0ab2bc039de0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=9A=AE=E7=9A=AE?= <363230482@qq.com> Date: Sat, 20 Feb 2021 15:40:52 +0800 Subject: [PATCH] [ISSUE #2652] change the method name to incrementAndGet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 张玻 --- .../rocketmq/client/common/ThreadLocalIndex.java | 2 +- .../client/impl/producer/TopicPublishInfo.java | 4 ++-- .../client/latency/LatencyFaultToleranceImpl.java | 2 +- .../rocketmq/client/latency/MQFaultStrategy.java | 4 ++-- .../rocketmq/client/trace/AsyncTraceDispatcher.java | 2 +- .../rocketmq/client/common/ThreadLocalIndexTest.java | 10 +++++----- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/client/src/main/java/org/apache/rocketmq/client/common/ThreadLocalIndex.java b/client/src/main/java/org/apache/rocketmq/client/common/ThreadLocalIndex.java index 8f0f63f3..c0b04cae 100644 --- a/client/src/main/java/org/apache/rocketmq/client/common/ThreadLocalIndex.java +++ b/client/src/main/java/org/apache/rocketmq/client/common/ThreadLocalIndex.java @@ -23,7 +23,7 @@ public class ThreadLocalIndex { private final ThreadLocal threadLocalIndex = new ThreadLocal(); private final Random random = new Random(); - public int getAndIncrement() { + public int incrementAndGet() { Integer index = this.threadLocalIndex.get(); if (null == index) { index = Math.abs(random.nextInt()); diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/producer/TopicPublishInfo.java b/client/src/main/java/org/apache/rocketmq/client/impl/producer/TopicPublishInfo.java index 2de91b49..2f8337ed 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/producer/TopicPublishInfo.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/producer/TopicPublishInfo.java @@ -71,7 +71,7 @@ public class TopicPublishInfo { return selectOneMessageQueue(); } else { for (int i = 0; i < this.messageQueueList.size(); i++) { - int index = this.sendWhichQueue.getAndIncrement(); + int index = this.sendWhichQueue.incrementAndGet(); int pos = Math.abs(index) % this.messageQueueList.size(); if (pos < 0) pos = 0; @@ -85,7 +85,7 @@ public class TopicPublishInfo { } public MessageQueue selectOneMessageQueue() { - int index = this.sendWhichQueue.getAndIncrement(); + int index = this.sendWhichQueue.incrementAndGet(); int pos = Math.abs(index) % this.messageQueueList.size(); if (pos < 0) pos = 0; diff --git a/client/src/main/java/org/apache/rocketmq/client/latency/LatencyFaultToleranceImpl.java b/client/src/main/java/org/apache/rocketmq/client/latency/LatencyFaultToleranceImpl.java index 72d43476..827d9726 100644 --- a/client/src/main/java/org/apache/rocketmq/client/latency/LatencyFaultToleranceImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/latency/LatencyFaultToleranceImpl.java @@ -80,7 +80,7 @@ public class LatencyFaultToleranceImpl implements LatencyFaultTolerance if (half <= 0) { return tmpList.get(0).getName(); } else { - final int i = this.whichItemWorst.getAndIncrement() % half; + final int i = this.whichItemWorst.incrementAndGet() % half; return tmpList.get(i).getName(); } } diff --git a/client/src/main/java/org/apache/rocketmq/client/latency/MQFaultStrategy.java b/client/src/main/java/org/apache/rocketmq/client/latency/MQFaultStrategy.java index 651d043a..ea3d07e6 100644 --- a/client/src/main/java/org/apache/rocketmq/client/latency/MQFaultStrategy.java +++ b/client/src/main/java/org/apache/rocketmq/client/latency/MQFaultStrategy.java @@ -58,7 +58,7 @@ public class MQFaultStrategy { public MessageQueue selectOneMessageQueue(final TopicPublishInfo tpInfo, final String lastBrokerName) { if (this.sendLatencyFaultEnable) { try { - int index = tpInfo.getSendWhichQueue().getAndIncrement(); + int index = tpInfo.getSendWhichQueue().incrementAndGet(); for (int i = 0; i < tpInfo.getMessageQueueList().size(); i++) { int pos = Math.abs(index++) % tpInfo.getMessageQueueList().size(); if (pos < 0) @@ -74,7 +74,7 @@ public class MQFaultStrategy { final MessageQueue mq = tpInfo.selectOneMessageQueue(); if (notBestBroker != null) { mq.setBrokerName(notBestBroker); - mq.setQueueId(tpInfo.getSendWhichQueue().getAndIncrement() % writeQueueNums); + mq.setQueueId(tpInfo.getSendWhichQueue().incrementAndGet() % writeQueueNums); } return mq; } else { diff --git a/client/src/main/java/org/apache/rocketmq/client/trace/AsyncTraceDispatcher.java b/client/src/main/java/org/apache/rocketmq/client/trace/AsyncTraceDispatcher.java index 1af6e60a..05a95e86 100644 --- a/client/src/main/java/org/apache/rocketmq/client/trace/AsyncTraceDispatcher.java +++ b/client/src/main/java/org/apache/rocketmq/client/trace/AsyncTraceDispatcher.java @@ -387,7 +387,7 @@ public class AsyncTraceDispatcher implements TraceDispatcher { filterMqs.add(queue); } } - int index = sendWhichQueue.getAndIncrement(); + int index = sendWhichQueue.incrementAndGet(); int pos = Math.abs(index) % filterMqs.size(); if (pos < 0) { pos = 0; diff --git a/client/src/test/java/org/apache/rocketmq/client/common/ThreadLocalIndexTest.java b/client/src/test/java/org/apache/rocketmq/client/common/ThreadLocalIndexTest.java index 6ff5dad2..de35b918 100644 --- a/client/src/test/java/org/apache/rocketmq/client/common/ThreadLocalIndexTest.java +++ b/client/src/test/java/org/apache/rocketmq/client/common/ThreadLocalIndexTest.java @@ -22,17 +22,17 @@ import static org.assertj.core.api.Assertions.assertThat; public class ThreadLocalIndexTest { @Test - public void testGetAndIncrement() throws Exception { + public void testIncrementAndGet() throws Exception { ThreadLocalIndex localIndex = new ThreadLocalIndex(); - int initialVal = localIndex.getAndIncrement(); + int initialVal = localIndex.incrementAndGet(); - assertThat(localIndex.getAndIncrement()).isEqualTo(initialVal + 1); + assertThat(localIndex.incrementAndGet()).isEqualTo(initialVal + 1); } @Test - public void testGetAndIncrement2() throws Exception { + public void testIncrementAndGet2() throws Exception { ThreadLocalIndex localIndex = new ThreadLocalIndex(); - int initialVal = localIndex.getAndIncrement(); + int initialVal = localIndex.incrementAndGet(); assertThat(initialVal >= 0); } -- GitLab