From c8ee3289b7518674bb077773e8b6bab699392984 Mon Sep 17 00:00:00 2001 From: yukon Date: Wed, 28 Dec 2016 10:43:30 +0800 Subject: [PATCH] ROCKETMQ-18 Remove bad practices in client. --- .../rocketmq/client/consumer/DefaultMQPullConsumer.java | 1 + .../rocketmq/client/consumer/DefaultMQPushConsumer.java | 1 + .../org/apache/rocketmq/client/consumer/PullCallback.java | 4 ++-- .../apache/rocketmq/client/consumer/PullTaskCallback.java | 2 +- .../client/consumer/listener/ConsumeReturnType.java | 3 --- .../rebalance/AllocateMessageQueueByMachineRoom.java | 8 ++++---- .../client/consumer/store/RemoteBrokerOffsetStore.java | 2 +- .../apache/rocketmq/client/hook/CheckForbiddenHook.java | 4 ++-- .../apache/rocketmq/client/hook/FilterMessageHook.java | 4 ++-- 9 files changed, 14 insertions(+), 15 deletions(-) diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPullConsumer.java b/client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPullConsumer.java index a8dd766a..aac42074 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPullConsumer.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPullConsumer.java @@ -335,6 +335,7 @@ public class DefaultMQPullConsumer extends ClientConfig implements MQPullConsume MessageDecoder.decodeMessageId(uniqKey); return this.viewMessage(uniqKey); } catch (Exception e) { + // Ignore } return this.defaultMQPullConsumerImpl.queryMessageByUniqKey(topic, uniqKey); } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumer.java b/client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumer.java index 38c4649f..2575827d 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumer.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumer.java @@ -210,6 +210,7 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume MessageDecoder.decodeMessageId(msgId); return this.viewMessage(msgId); } catch (Exception e) { + // Ignore } return this.defaultMQPushConsumerImpl.queryMessageByUniqKey(topic, msgId); } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/PullCallback.java b/client/src/main/java/org/apache/rocketmq/client/consumer/PullCallback.java index fd2be0ef..508050dc 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/PullCallback.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/PullCallback.java @@ -22,7 +22,7 @@ package org.apache.rocketmq.client.consumer; * @author vintagewang@apache.org */ public interface PullCallback { - public void onSuccess(final PullResult pullResult); + void onSuccess(final PullResult pullResult); - public void onException(final Throwable e); + void onException(final Throwable e); } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/PullTaskCallback.java b/client/src/main/java/org/apache/rocketmq/client/consumer/PullTaskCallback.java index f0e9b252..dc74bcab 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/PullTaskCallback.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/PullTaskCallback.java @@ -20,5 +20,5 @@ import org.apache.rocketmq.common.message.MessageQueue; public interface PullTaskCallback { - public void doPullTask(final MessageQueue mq, final PullTaskContext context); + void doPullTask(final MessageQueue mq, final PullTaskContext context); } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeReturnType.java b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeReturnType.java index 82570ab3..99083b4c 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeReturnType.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/ConsumeReturnType.java @@ -17,9 +17,6 @@ package org.apache.rocketmq.client.consumer.listener; -/** - * Created by alvin on 16-11-30. - */ public enum ConsumeReturnType { /** * consume return success diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueByMachineRoom.java b/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueByMachineRoom.java index d3448c9c..adfc124b 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueByMachineRoom.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueByMachineRoom.java @@ -45,12 +45,12 @@ public class AllocateMessageQueueByMachineRoom implements AllocateMessageQueueSt premqAll.add(mq); } } - // Todo cid + int mod = premqAll.size() / cidAll.size(); int rem = premqAll.size() % cidAll.size(); - int startindex = mod * currentIndex; - int endindex = startindex + mod; - for (int i = startindex; i < endindex; i++) { + int startIndex = mod * currentIndex; + int endIndex = startIndex + mod; + for (int i = startIndex; i < endIndex; i++) { result.add(mqAll.get(i)); } if (rem > currentIndex) { diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/store/RemoteBrokerOffsetStore.java b/client/src/main/java/org/apache/rocketmq/client/consumer/store/RemoteBrokerOffsetStore.java index 4fd69111..de9d0ddf 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/store/RemoteBrokerOffsetStore.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/store/RemoteBrokerOffsetStore.java @@ -125,7 +125,7 @@ public class RemoteBrokerOffsetStore implements OffsetStore { return; final HashSet unusedMQ = new HashSet(); - if (mqs != null && !mqs.isEmpty()) { + if (!mqs.isEmpty()) { for (Map.Entry entry : this.offsetTable.entrySet()) { MessageQueue mq = entry.getKey(); AtomicLong offset = entry.getValue(); diff --git a/client/src/main/java/org/apache/rocketmq/client/hook/CheckForbiddenHook.java b/client/src/main/java/org/apache/rocketmq/client/hook/CheckForbiddenHook.java index 41ed088f..90f164b0 100644 --- a/client/src/main/java/org/apache/rocketmq/client/hook/CheckForbiddenHook.java +++ b/client/src/main/java/org/apache/rocketmq/client/hook/CheckForbiddenHook.java @@ -24,8 +24,8 @@ import org.apache.rocketmq.client.exception.MQClientException; * @author manhong.yqd */ public interface CheckForbiddenHook { - public String hookName(); + String hookName(); - public void checkForbidden(final CheckForbiddenContext context) throws MQClientException; + void checkForbidden(final CheckForbiddenContext context) throws MQClientException; } diff --git a/client/src/main/java/org/apache/rocketmq/client/hook/FilterMessageHook.java b/client/src/main/java/org/apache/rocketmq/client/hook/FilterMessageHook.java index 016ff56c..28956ee9 100644 --- a/client/src/main/java/org/apache/rocketmq/client/hook/FilterMessageHook.java +++ b/client/src/main/java/org/apache/rocketmq/client/hook/FilterMessageHook.java @@ -20,8 +20,8 @@ package org.apache.rocketmq.client.hook; * @author manhong.yqd */ public interface FilterMessageHook { - public String hookName(); + String hookName(); - public void filterMessage(final FilterMessageContext context); + void filterMessage(final FilterMessageContext context); } -- GitLab