diff --git a/.travis.yml b/.travis.yml index 2bc2296681c75e9513c6873b56dd9cfdc01429c8..daa88a2caf42d6dc56fe629b688ecbad315aa184 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,10 +14,6 @@ matrix: # On Linux, run with specific JDKs only. - os: linux env: CUSTOM_JDK="oraclejdk8" - - os: linux - env: CUSTOM_JDK="oraclejdk7" - - os: linux - env: CUSTOM_JDK="openjdk7" before_install: - echo 'MAVEN_OPTS="$MAVEN_OPTS -Xmx1024m -XX:MaxPermSize=512m -XX:+BytecodeVerificationLocal"' >> ~/.mavenrc @@ -25,15 +21,6 @@ before_install: - if [ "$TRAVIS_OS_NAME" == "osx" ]; then export JAVA_HOME=$(/usr/libexec/java_home); fi - if [ "$TRAVIS_OS_NAME" == "linux" ]; then jdk_switcher use "$CUSTOM_JDK"; fi -#os: -# - linux -# - osx -#jdk: -# - oraclejdk8 -# - oraclejdk7 -# - openjdk7 - - script: - travis_retry mvn -B clean apache-rat:check - travis_retry mvn -B package jacoco:report coveralls:report diff --git a/broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java b/broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java index c8624c4f55b284994138ddbea85eb024473d0c62..cd68552bd27bae4ff69632ffb0306006bcebc0df 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/BrokerController.java @@ -135,11 +135,11 @@ public class BrokerController { private BrokerFastFailure brokerFastFailure; private Configuration configuration; - public BrokerController(// - final BrokerConfig brokerConfig, // - final NettyServerConfig nettyServerConfig, // - final NettyClientConfig nettyClientConfig, // - final MessageStoreConfig messageStoreConfig // + public BrokerController( + final BrokerConfig brokerConfig, + final NettyServerConfig nettyServerConfig, + final NettyClientConfig nettyClientConfig, + final MessageStoreConfig messageStoreConfig ) { this.brokerConfig = brokerConfig; this.nettyServerConfig = nettyServerConfig; @@ -255,7 +255,6 @@ public class BrokerController { this.registerProcessor(); - // TODO remove in future final long initialDelay = UtilAll.computNextMorningTimeMillis() - System.currentTimeMillis(); final long period = 1000 * 60 * 60 * 24; this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/BrokerPathConfigHelper.java b/broker/src/main/java/org/apache/rocketmq/broker/BrokerPathConfigHelper.java index 0a323ee80c84b4b88f3b8276f1275044330db15b..42c8da9f3fba7ab563a898b6191dc0b4246b9df2 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/BrokerPathConfigHelper.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/BrokerPathConfigHelper.java @@ -19,7 +19,6 @@ package org.apache.rocketmq.broker; import java.io.File; - public class BrokerPathConfigHelper { private static String brokerConfigPath = System.getProperty("user.home") + File.separator + "store" + File.separator + "config" + File.separator + "broker.properties"; diff --git a/broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java b/broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java index 85d2e3af514ba1c1a106882042bff7c408c018f1..e0a3b69923053cb2ef651fccf3ad92b73cc890f0 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java @@ -190,10 +190,10 @@ public class BrokerStartup { MixAll.printObjectProperties(log, nettyClientConfig); MixAll.printObjectProperties(log, messageStoreConfig); - final BrokerController controller = new BrokerController(// - brokerConfig, // - nettyServerConfig, // - nettyClientConfig, // + final BrokerController controller = new BrokerController( + brokerConfig, + nettyServerConfig, + nettyClientConfig, messageStoreConfig); // remember all configs to prevent discard controller.getConfiguration().registerConfig(properties); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerManager.java b/broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerManager.java index 4a262e52286eb401521c8e2e83c55d8df736d290..32632fc5149e3cb25a3e24042588e748009acdf4 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerManager.java @@ -122,7 +122,8 @@ public class ConsumerManager { return r1 || r2; } - public void unregisterConsumer(final String group, final ClientChannelInfo clientChannelInfo, boolean isNotifyConsumerIdsChangedEnable) { + public void unregisterConsumer(final String group, final ClientChannelInfo clientChannelInfo, + boolean isNotifyConsumerIdsChangedEnable) { ConsumerGroupInfo consumerGroupInfo = this.consumerTable.get(group); if (null != consumerGroupInfo) { consumerGroupInfo.unregisterChannel(clientChannelInfo); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/client/rebalance/RebalanceLockManager.java b/broker/src/main/java/org/apache/rocketmq/broker/client/rebalance/RebalanceLockManager.java index ed5a87582946b355ebbeda9757b5f8410ff112fd..519745e09192f0547a45ee155a76be808503cbea 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/client/rebalance/RebalanceLockManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/client/rebalance/RebalanceLockManager.java @@ -52,9 +52,9 @@ public class RebalanceLockManager { lockEntry = new LockEntry(); lockEntry.setClientId(clientId); groupValue.put(mq, lockEntry); - log.info("tryLock, message queue not locked, I got it. Group: {} NewClientId: {} {}", // - group, // - clientId, // + log.info("tryLock, message queue not locked, I got it. Group: {} NewClientId: {} {}", + group, + clientId, mq); } @@ -69,19 +69,19 @@ public class RebalanceLockManager { lockEntry.setClientId(clientId); lockEntry.setLastUpdateTimestamp(System.currentTimeMillis()); log.warn( - "tryLock, message queue lock expired, I got it. Group: {} OldClientId: {} NewClientId: {} {}", // - group, // - oldClientId, // - clientId, // + "tryLock, message queue lock expired, I got it. Group: {} OldClientId: {} NewClientId: {} {}", + group, + oldClientId, + clientId, mq); return true; } log.warn( - "tryLock, message queue locked by other client. Group: {} OtherClientId: {} NewClientId: {} {}", // - group, // - oldClientId, // - clientId, // + "tryLock, message queue locked by other client. Group: {} OtherClientId: {} NewClientId: {} {}", + group, + oldClientId, + clientId, mq); return false; } finally { @@ -144,9 +144,9 @@ public class RebalanceLockManager { lockEntry.setClientId(clientId); groupValue.put(mq, lockEntry); log.info( - "tryLockBatch, message queue not locked, I got it. Group: {} NewClientId: {} {}", // - group, // - clientId, // + "tryLockBatch, message queue not locked, I got it. Group: {} NewClientId: {} {}", + group, + clientId, mq); } @@ -162,20 +162,20 @@ public class RebalanceLockManager { lockEntry.setClientId(clientId); lockEntry.setLastUpdateTimestamp(System.currentTimeMillis()); log.warn( - "tryLockBatch, message queue lock expired, I got it. Group: {} OldClientId: {} NewClientId: {} {}", // - group, // - oldClientId, // - clientId, // + "tryLockBatch, message queue lock expired, I got it. Group: {} OldClientId: {} NewClientId: {} {}", + group, + oldClientId, + clientId, mq); lockedMqs.add(mq); continue; } log.warn( - "tryLockBatch, message queue locked by other client. Group: {} OtherClientId: {} NewClientId: {} {}", // - group, // - oldClientId, // - clientId, // + "tryLockBatch, message queue locked by other client. Group: {} OtherClientId: {} NewClientId: {} {}", + group, + oldClientId, + clientId, mq); } } finally { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/filter/ConsumerFilterData.java b/broker/src/main/java/org/apache/rocketmq/broker/filter/ConsumerFilterData.java index 4db02e26f8cf9720c5e015a95d97b447477d7c91..ee16a61ecea71062bfdfd5aec2b602804891fd62 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/filter/ConsumerFilterData.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/filter/ConsumerFilterData.java @@ -54,9 +54,6 @@ public class ConsumerFilterData { /** * Check this filter data has been used to calculate bit map when msg was stored in server. - * - * @param msgStoreTime - * @return */ public boolean isMsgInLive(long msgStoreTime) { return msgStoreTime > getBornTime(); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/filter/ConsumerFilterManager.java b/broker/src/main/java/org/apache/rocketmq/broker/filter/ConsumerFilterManager.java index f50db86308c8cdeed6a8dceacaf199c6535545c4..482893f7cee9e2186228b208dd940951f95ae870 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/filter/ConsumerFilterManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/filter/ConsumerFilterManager.java @@ -72,16 +72,11 @@ public class ConsumerFilterManager extends ConfigManager { /** * Build consumer filter data.Be care, bloom filter data is not included. * - * @param topic - * @param consumerGroup - * @param expression - * @param type - * @param clientVersion * @return maybe null */ public static ConsumerFilterData build(final String topic, final String consumerGroup, - final String expression, final String type, - final long clientVersion) { + final String expression, final String type, + final long clientVersion) { if (ExpressionType.isTagType(type)) { return null; } @@ -140,7 +135,7 @@ public class ConsumerFilterManager extends ConfigManager { } public boolean register(final String topic, final String consumerGroup, final String expression, - final String type, final long clientVersion) { + final String type, final long clientVersion) { if (ExpressionType.isTagType(type)) { return false; } @@ -357,7 +352,8 @@ public class ConsumerFilterManager extends ConfigManager { data.setDeadTime(now); } - public boolean register(String consumerGroup, String expression, String type, BloomFilterData bloomFilterData, long clientVersion) { + public boolean register(String consumerGroup, String expression, String type, BloomFilterData bloomFilterData, + long clientVersion) { ConsumerFilterData old = this.groupFilterData.get(consumerGroup); if (old == null) { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/filter/ExpressionForRetryMessageFilter.java b/broker/src/main/java/org/apache/rocketmq/broker/filter/ExpressionForRetryMessageFilter.java index 95181789517c2565aa72a30eeea28d0cc7c4f680..7f7da05dd02bd6b60b8fd8e4ac6be9f6fe4e64a9 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/filter/ExpressionForRetryMessageFilter.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/filter/ExpressionForRetryMessageFilter.java @@ -17,7 +17,6 @@ package org.apache.rocketmq.broker.filter; - import org.apache.rocketmq.common.MixAll; import org.apache.rocketmq.common.filter.ExpressionType; import org.apache.rocketmq.common.message.MessageConst; @@ -32,7 +31,8 @@ import java.util.Map; *
It will decode properties first in order to get real topic. */ public class ExpressionForRetryMessageFilter extends ExpressionMessageFilter { - public ExpressionForRetryMessageFilter(SubscriptionData subscriptionData, ConsumerFilterData consumerFilterData, ConsumerFilterManager consumerFilterManager) { + public ExpressionForRetryMessageFilter(SubscriptionData subscriptionData, ConsumerFilterData consumerFilterData, + ConsumerFilterManager consumerFilterManager) { super(subscriptionData, consumerFilterData, consumerFilterManager); } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/filter/ExpressionMessageFilter.java b/broker/src/main/java/org/apache/rocketmq/broker/filter/ExpressionMessageFilter.java index 893df0d7c6b94d0892b6d358facfcbef887d28b7..2f94de20c34213d426a91f913ce6abb7fed6f690 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/filter/ExpressionMessageFilter.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/filter/ExpressionMessageFilter.java @@ -41,7 +41,7 @@ public class ExpressionMessageFilter implements MessageFilter { protected final boolean bloomDataValid; public ExpressionMessageFilter(SubscriptionData subscriptionData, ConsumerFilterData consumerFilterData, - ConsumerFilterManager consumerFilterManager) { + ConsumerFilterManager consumerFilterManager) { this.subscriptionData = subscriptionData; this.consumerFilterData = consumerFilterData; this.consumerFilterManager = consumerFilterManager; diff --git a/broker/src/main/java/org/apache/rocketmq/broker/filtersrv/FilterServerManager.java b/broker/src/main/java/org/apache/rocketmq/broker/filtersrv/FilterServerManager.java index 52cb9199931a03fe251c459dd5f3ed92d9bf00b9..f8f9943e82669309a84155e5a41fe5c97d7b26ed 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/filtersrv/FilterServerManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/filtersrv/FilterServerManager.java @@ -111,9 +111,6 @@ public class FilterServerManager { } } - /** - - */ public void scanNotActiveChannel() { Iterator> it = this.filterServerTable.entrySet().iterator(); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/latency/BrokerFastFailure.java b/broker/src/main/java/org/apache/rocketmq/broker/latency/BrokerFastFailure.java index a2a1aa095f727593494aef799a20b165a69187db..2d4bedcb96e76ba1f723287d2c110f80470722ff 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/latency/BrokerFastFailure.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/latency/BrokerFastFailure.java @@ -103,6 +103,7 @@ public class BrokerFastFailure { } } } + public void shutdown() { this.scheduledExecutorService.shutdown(); } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/latency/BrokerFixedThreadPoolExecutor.java b/broker/src/main/java/org/apache/rocketmq/broker/latency/BrokerFixedThreadPoolExecutor.java index 238fe1c62f9e99eb740379e745371246f3e71048..8060fd00c79756fe648053e4266bd313360c967e 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/latency/BrokerFixedThreadPoolExecutor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/latency/BrokerFixedThreadPoolExecutor.java @@ -25,23 +25,28 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; public class BrokerFixedThreadPoolExecutor extends ThreadPoolExecutor { - public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit, + public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, + final TimeUnit unit, final BlockingQueue workQueue) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); } - public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit, + public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, + final TimeUnit unit, final BlockingQueue workQueue, final ThreadFactory threadFactory) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory); } - public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit, + public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, + final TimeUnit unit, final BlockingQueue workQueue, final RejectedExecutionHandler handler) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler); } - public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, final TimeUnit unit, - final BlockingQueue workQueue, final ThreadFactory threadFactory, final RejectedExecutionHandler handler) { + public BrokerFixedThreadPoolExecutor(final int corePoolSize, final int maximumPoolSize, final long keepAliveTime, + final TimeUnit unit, + final BlockingQueue workQueue, final ThreadFactory threadFactory, + final RejectedExecutionHandler handler) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler); } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/longpolling/NotifyMessageArrivingListener.java b/broker/src/main/java/org/apache/rocketmq/broker/longpolling/NotifyMessageArrivingListener.java index fd38c4fb7660d358cc7ffe87544f267e32a3aced..ff0901126f2771b58136208d6012722a9b20f037 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/longpolling/NotifyMessageArrivingListener.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/longpolling/NotifyMessageArrivingListener.java @@ -30,7 +30,7 @@ public class NotifyMessageArrivingListener implements MessageArrivingListener { @Override public void arriving(String topic, int queueId, long logicOffset, long tagsCode, - long msgStoreTime, byte[] filterBitMap, Map properties) { + long msgStoreTime, byte[] filterBitMap, Map properties) { this.pullRequestHoldService.notifyMessageArriving(topic, queueId, logicOffset, tagsCode, msgStoreTime, filterBitMap, properties); } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/longpolling/PullRequestHoldService.java b/broker/src/main/java/org/apache/rocketmq/broker/longpolling/PullRequestHoldService.java index b1bd86f5a783c5552bae20001e13fec6df07beeb..d0668cb45b0852ad55f3cc3c317bb31442a1cd5a 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/longpolling/PullRequestHoldService.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/longpolling/PullRequestHoldService.java @@ -114,7 +114,7 @@ public class PullRequestHoldService extends ServiceThread { } public void notifyMessageArriving(final String topic, final int queueId, final long maxOffset, final Long tagsCode, - long msgStoreTime, byte[] filterBitMap, Map properties) { + long msgStoreTime, byte[] filterBitMap, Map properties) { String key = this.buildKey(topic, queueId); ManyPullRequest mpr = this.pullRequestTable.get(key); if (mpr != null) { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/offset/ConsumerOffsetManager.java b/broker/src/main/java/org/apache/rocketmq/broker/offset/ConsumerOffsetManager.java index 57565a6401edfe0d3ce58bd3e56ad56d6a3136bf..0257f94b73755e54d10f3e29d13383ebac5d3d3c 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/offset/ConsumerOffsetManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/offset/ConsumerOffsetManager.java @@ -118,7 +118,8 @@ public class ConsumerOffsetManager extends ConfigManager { return groups; } - public void commitOffset(final String clientHost, final String group, final String topic, final int queueId, final long offset) { + public void commitOffset(final String clientHost, final String group, final String topic, final int queueId, + final long offset) { // topic@group String key = topic + TOPIC_GROUP_SEPARATOR + group; this.commitOffset(clientHost, key, queueId, offset); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/out/BrokerOuterAPI.java b/broker/src/main/java/org/apache/rocketmq/broker/out/BrokerOuterAPI.java index 6c2a987d29eea590f7d485499262592c44b69feb..cba70a0ee8a6a3f69d28dd2a98e91c6ca284f326 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/out/BrokerOuterAPI.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/out/BrokerOuterAPI.java @@ -231,7 +231,8 @@ public class BrokerOuterAPI { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public TopicConfigSerializeWrapper getAllTopicConfig(final String addr) throws RemotingConnectException, RemotingSendRequestException, + public TopicConfigSerializeWrapper getAllTopicConfig( + final String addr) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_TOPIC_CONFIG, null); @@ -248,7 +249,8 @@ public class BrokerOuterAPI { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public ConsumerOffsetSerializeWrapper getAllConsumerOffset(final String addr) throws InterruptedException, RemotingTimeoutException, + public ConsumerOffsetSerializeWrapper getAllConsumerOffset( + final String addr) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_CONSUMER_OFFSET, null); RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000); @@ -264,7 +266,8 @@ public class BrokerOuterAPI { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public String getAllDelayOffset(final String addr) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, + public String getAllDelayOffset( + final String addr) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException, UnsupportedEncodingException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_DELAY_OFFSET, null); RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000); @@ -280,7 +283,8 @@ public class BrokerOuterAPI { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public SubscriptionGroupWrapper getAllSubscriptionGroupConfig(final String addr) throws InterruptedException, RemotingTimeoutException, + public SubscriptionGroupWrapper getAllSubscriptionGroupConfig( + final String addr) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null); RemotingCommand response = this.remotingClient.invokeSync(addr, request, 3000); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/pagecache/ManyMessageTransfer.java b/broker/src/main/java/org/apache/rocketmq/broker/pagecache/ManyMessageTransfer.java index 5b9df3e2ab77c83f04f494bfc13f3bc96f4a68cb..968bcfb564f9fe67e48d84371a47089a4572783a 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/pagecache/ManyMessageTransfer.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/pagecache/ManyMessageTransfer.java @@ -28,7 +28,9 @@ public class ManyMessageTransfer extends AbstractReferenceCounted implements Fil private final ByteBuffer byteBufferHeader; private final GetMessageResult getMessageResult; - /** Bytes which were transferred already. */ + /** + * Bytes which were transferred already. + */ private long transferred; public ManyMessageTransfer(ByteBuffer byteBufferHeader, GetMessageResult getMessageResult) { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/pagecache/OneMessageTransfer.java b/broker/src/main/java/org/apache/rocketmq/broker/pagecache/OneMessageTransfer.java index 254c2ab81aafe6085b02abc8f88b3afe08668db7..b795d2d253bd3ade2d7a102ecdbbe596321d8d15 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/pagecache/OneMessageTransfer.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/pagecache/OneMessageTransfer.java @@ -27,7 +27,9 @@ public class OneMessageTransfer extends AbstractReferenceCounted implements File private final ByteBuffer byteBufferHeader; private final SelectMappedBufferResult selectMappedBufferResult; - /** Bytes which were transferred already. */ + /** + * Bytes which were transferred already. + */ private long transferred; public OneMessageTransfer(ByteBuffer byteBufferHeader, SelectMappedBufferResult selectMappedBufferResult) { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/pagecache/QueryMessageTransfer.java b/broker/src/main/java/org/apache/rocketmq/broker/pagecache/QueryMessageTransfer.java index aaa1304d06f3936f5410c2650d24014b5812da08..e8f30996677a72cd2159baec3375ad42ad9a6c1a 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/pagecache/QueryMessageTransfer.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/pagecache/QueryMessageTransfer.java @@ -28,7 +28,9 @@ public class QueryMessageTransfer extends AbstractReferenceCounted implements Fi private final ByteBuffer byteBufferHeader; private final QueryMessageResult queryMessageResult; - /** Bytes which were transferred already. */ + /** + * Bytes which were transferred already. + */ private long transferred; public QueryMessageTransfer(ByteBuffer byteBufferHeader, QueryMessageResult queryMessageResult) { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/plugin/AbstractPluginMessageStore.java b/broker/src/main/java/org/apache/rocketmq/broker/plugin/AbstractPluginMessageStore.java index 690f70bfc88d4333252390c99976d186376075cb..f6f8a80afb6d48e178f6d27ead85bac5464e820a 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/plugin/AbstractPluginMessageStore.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/plugin/AbstractPluginMessageStore.java @@ -87,7 +87,7 @@ public abstract class AbstractPluginMessageStore implements MessageStore { @Override public GetMessageResult getMessage(String group, String topic, int queueId, long offset, - int maxMsgNums, final MessageFilter messageFilter) { + int maxMsgNums, final MessageFilter messageFilter) { return next.getMessage(group, topic, queueId, offset, maxMsgNums, messageFilter); } diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/AbstractSendMessageProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/AbstractSendMessageProcessor.java index 3faa7ae3b270fc5c5f2831ce93b9c7d209f3401d..410192f3b05b66c4f4f39a9186d2a81d6eeef998 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/AbstractSendMessageProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/AbstractSendMessageProcessor.java @@ -189,10 +189,10 @@ public abstract class AbstractSendMessageProcessor implements NettyRequestProces } log.warn("the topic {} not exist, producer: {}", requestHeader.getTopic(), ctx.channel().remoteAddress()); - topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageMethod(// - requestHeader.getTopic(), // - requestHeader.getDefaultTopic(), // - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), // + topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageMethod( + requestHeader.getTopic(), + requestHeader.getDefaultTopic(), + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getDefaultTopicQueueNums(), topicSysFlag); if (null == topicConfig) { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java index 71fdda931ff29fbec56b9f28ddbfbc84c3d07a52..abea4ec9e0dbbe351e0535384e68596853d28d1d 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java @@ -125,7 +125,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { } @Override - public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand processRequest(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { switch (request.getCode()) { case RequestCode.UPDATE_AND_CREATE_TOPIC: return this.updateAndCreateTopic(ctx, request); @@ -211,7 +212,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return false; } - private RemotingCommand updateAndCreateTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand updateAndCreateTopic(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final CreateTopicRequestHeader requestHeader = (CreateTopicRequestHeader) request.decodeCommandCustomHeader(CreateTopicRequestHeader.class); @@ -248,7 +250,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return null; } - private RemotingCommand deleteTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand deleteTopic(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); DeleteTopicRequestHeader requestHeader = (DeleteTopicRequestHeader) request.decodeCommandCustomHeader(DeleteTopicRequestHeader.class); @@ -354,7 +357,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand searchOffsetByTimestamp(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand searchOffsetByTimestamp(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(SearchOffsetResponseHeader.class); final SearchOffsetResponseHeader responseHeader = (SearchOffsetResponseHeader) response.readCustomHeader(); final SearchOffsetRequestHeader requestHeader = @@ -370,7 +374,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getMaxOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand getMaxOffset(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(GetMaxOffsetResponseHeader.class); final GetMaxOffsetResponseHeader responseHeader = (GetMaxOffsetResponseHeader) response.readCustomHeader(); final GetMaxOffsetRequestHeader requestHeader = @@ -385,7 +390,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getMinOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand getMinOffset(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(GetMinOffsetResponseHeader.class); final GetMinOffsetResponseHeader responseHeader = (GetMinOffsetResponseHeader) response.readCustomHeader(); final GetMinOffsetRequestHeader requestHeader = @@ -399,7 +405,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getEarliestMsgStoretime(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand getEarliestMsgStoretime(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(GetEarliestMsgStoretimeResponseHeader.class); final GetEarliestMsgStoretimeResponseHeader responseHeader = (GetEarliestMsgStoretimeResponseHeader) response.readCustomHeader(); final GetEarliestMsgStoretimeRequestHeader requestHeader = @@ -428,13 +435,14 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand lockBatchMQ(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand lockBatchMQ(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); LockBatchRequestBody requestBody = LockBatchRequestBody.decode(request.getBody(), LockBatchRequestBody.class); - Set lockOKMQSet = this.brokerController.getRebalanceLockManager().tryLockBatch(// - requestBody.getConsumerGroup(), // - requestBody.getMqSet(), // + Set lockOKMQSet = this.brokerController.getRebalanceLockManager().tryLockBatch( + requestBody.getConsumerGroup(), + requestBody.getMqSet(), requestBody.getClientId()); LockBatchResponseBody responseBody = new LockBatchResponseBody(); @@ -446,13 +454,14 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand unlockBatchMQ(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand unlockBatchMQ(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); UnlockBatchRequestBody requestBody = UnlockBatchRequestBody.decode(request.getBody(), UnlockBatchRequestBody.class); - this.brokerController.getRebalanceLockManager().unlockBatch(// - requestBody.getConsumerGroup(), // - requestBody.getMqSet(), // + this.brokerController.getRebalanceLockManager().unlockBatch( + requestBody.getConsumerGroup(), + requestBody.getMqSet(), requestBody.getClientId()); response.setCode(ResponseCode.SUCCESS); @@ -476,7 +485,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getAllSubscriptionGroup(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand getAllSubscriptionGroup(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); String content = this.brokerController.getSubscriptionGroupManager().encode(); if (content != null && content.length() > 0) { @@ -502,7 +512,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand deleteSubscriptionGroup(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand deleteSubscriptionGroup(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); DeleteSubscriptionGroupRequestHeader requestHeader = (DeleteSubscriptionGroupRequestHeader) request.decodeCommandCustomHeader(DeleteSubscriptionGroupRequestHeader.class); @@ -516,7 +527,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getTopicStatsInfo(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand getTopicStatsInfo(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetTopicStatsInfoRequestHeader requestHeader = (GetTopicStatsInfoRequestHeader) request.decodeCommandCustomHeader(GetTopicStatsInfoRequestHeader.class); @@ -564,7 +576,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand getConsumerConnectionList(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumerConnectionListRequestHeader requestHeader = (GetConsumerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetConsumerConnectionListRequestHeader.class); @@ -603,7 +616,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getProducerConnectionList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand getProducerConnectionList(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetProducerConnectionListRequestHeader requestHeader = (GetProducerConnectionListRequestHeader) request.decodeCommandCustomHeader(GetProducerConnectionListRequestHeader.class); @@ -636,7 +650,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumeStatsRequestHeader requestHeader = (GetConsumeStatsRequestHeader) request.decodeCommandCustomHeader(GetConsumeStatsRequestHeader.class); @@ -657,14 +672,11 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { continue; } - /** - - */ { SubscriptionData findSubscriptionData = this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getConsumerGroup(), topic); - if (null == findSubscriptionData // + if (null == findSubscriptionData && this.brokerController.getConsumerManager().findSubscriptionDataCount(requestHeader.getConsumerGroup()) > 0) { log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", requestHeader.getConsumerGroup(), topic); continue; @@ -683,9 +695,9 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { if (brokerOffset < 0) brokerOffset = 0; - long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(// - requestHeader.getConsumerGroup(), // - topic, // + long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset( + requestHeader.getConsumerGroup(), + topic, i); if (consumerOffset < 0) consumerOffset = 0; @@ -771,7 +783,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - public RemotingCommand resetOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand resetOffset(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final ResetOffsetRequestHeader requestHeader = (ResetOffsetRequestHeader) request.decodeCommandCustomHeader(ResetOffsetRequestHeader.class); log.info("[reset-offset] reset offset started by {}. topic={}, group={}, timestamp={}, isForce={}", @@ -788,7 +801,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { requestHeader.getTimestamp(), requestHeader.isForce(), isC); } - public RemotingCommand getConsumerStatus(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand getConsumerStatus(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final GetConsumerStatusRequestHeader requestHeader = (GetConsumerStatusRequestHeader) request.decodeCommandCustomHeader(GetConsumerStatusRequestHeader.class); @@ -799,7 +813,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { requestHeader.getClientAddr()); } - private RemotingCommand queryTopicConsumeByWho(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand queryTopicConsumeByWho(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); QueryTopicConsumeByWhoRequestHeader requestHeader = (QueryTopicConsumeByWhoRequestHeader) request.decodeCommandCustomHeader(QueryTopicConsumeByWhoRequestHeader.class); @@ -821,7 +836,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand registerFilterServer(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand registerFilterServer(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(RegisterFilterServerResponseHeader.class); final RegisterFilterServerResponseHeader responseHeader = (RegisterFilterServerResponseHeader) response.readCustomHeader(); final RegisterFilterServerRequestHeader requestHeader = @@ -837,7 +853,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand queryConsumeTimeSpan(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand queryConsumeTimeSpan(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); QueryConsumeTimeSpanRequestHeader requestHeader = (QueryConsumeTimeSpanRequestHeader) request.decodeCommandCustomHeader(QueryConsumeTimeSpanRequestHeader.class); @@ -925,10 +942,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - /** - - */ - private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final GetConsumerRunningInfoRequestHeader requestHeader = (GetConsumerRunningInfoRequestHeader) request.decodeCommandCustomHeader(GetConsumerRunningInfoRequestHeader.class); @@ -936,7 +951,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { requestHeader.getClientId()); } - private RemotingCommand queryCorrectionOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand queryCorrectionOffset(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); QueryCorrectionOffsetHeader requestHeader = (QueryCorrectionOffsetHeader) request.decodeCommandCustomHeader(QueryCorrectionOffsetHeader.class); @@ -963,7 +979,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final ConsumeMessageDirectlyResultRequestHeader requestHeader = (ConsumeMessageDirectlyResultRequestHeader) request .decodeCommandCustomHeader(ConsumeMessageDirectlyResultRequestHeader.class); @@ -987,7 +1004,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { requestHeader.getClientId()); } - private RemotingCommand cloneGroupOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand cloneGroupOffset(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); CloneGroupOffsetRequestHeader requestHeader = (CloneGroupOffsetRequestHeader) request.decodeCommandCustomHeader(CloneGroupOffsetRequestHeader.class); @@ -1007,9 +1025,6 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { continue; } - /** - - */ if (!requestHeader.isOffline()) { SubscriptionData findSubscriptionData = @@ -1030,7 +1045,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand ViewBrokerStatsData(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand ViewBrokerStatsData(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final ViewBrokerStatsDataRequestHeader requestHeader = (ViewBrokerStatsDataRequestHeader) request.decodeCommandCustomHeader(ViewBrokerStatsDataRequestHeader.class); final RemotingCommand response = RemotingCommand.createResponseCommand(null); @@ -1107,13 +1123,11 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { if (isOrder && !topicConfig.isOrder()) { continue; } - /** - */ { SubscriptionData findSubscriptionData = this.brokerController.getConsumerManager().findSubscriptionData(group, topic); - if (null == findSubscriptionData // + if (null == findSubscriptionData && this.brokerController.getConsumerManager().findSubscriptionDataCount(group) > 0) { log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", group, topic); continue; @@ -1129,9 +1143,9 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { long brokerOffset = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i); if (brokerOffset < 0) brokerOffset = 0; - long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(// - group, // - topic, // + long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset( + group, + topic, i); if (consumerOffset < 0) consumerOffset = 0; @@ -1215,10 +1229,10 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { return runtimeInfo; } - private RemotingCommand callConsumer(// - final int requestCode, // - final RemotingCommand request, // - final String consumerGroup, // + private RemotingCommand callConsumer( + final int requestCode, + final RemotingCommand request, + final String consumerGroup, final String clientId) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); ClientChannelInfo clientChannelInfo = this.brokerController.getConsumerManager().findChannel(consumerGroup, clientId); @@ -1231,8 +1245,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { if (clientChannelInfo.getVersion() < MQVersion.Version.V3_1_8_SNAPSHOT.ordinal()) { response.setCode(ResponseCode.SYSTEM_ERROR); - response.setRemark(String.format("The Consumer <%s> Version <%s> too low to finish, please upgrade it to V3_1_8_SNAPSHOT", // - clientId, // + response.setRemark(String.format("The Consumer <%s> Version <%s> too low to finish, please upgrade it to V3_1_8_SNAPSHOT", + clientId, MQVersion.getVersionDesc(clientChannelInfo.getVersion()))); return response; } @@ -1256,7 +1270,8 @@ public class AdminBrokerProcessor implements NettyRequestProcessor { } } - private RemotingCommand queryConsumeQueue(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand queryConsumeQueue(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { QueryConsumeQueueRequestHeader requestHeader = (QueryConsumeQueueRequestHeader) request.decodeCommandCustomHeader(QueryConsumeQueueRequestHeader.class); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/EndTransactionProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/EndTransactionProcessor.java index 68e416768b23b341278517c85f86cfd96eb32c57..fee1420a9e713caef1e21b6d4bf744009ddf82aa 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/EndTransactionProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/EndTransactionProcessor.java @@ -46,7 +46,8 @@ public class EndTransactionProcessor implements NettyRequestProcessor { } @Override - public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand processRequest(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final EndTransactionRequestHeader requestHeader = (EndTransactionRequestHeader) request.decodeCommandCustomHeader(EndTransactionRequestHeader.class); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/PullMessageProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/PullMessageProcessor.java index fb7ea2030a979726202a96a910162600d2b1ddca..a46cbff2ebebfb8ac89998248600011acd7646e9 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/PullMessageProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/PullMessageProcessor.java @@ -76,7 +76,8 @@ public class PullMessageProcessor implements NettyRequestProcessor { } @Override - public RemotingCommand processRequest(final ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand processRequest(final ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { return this.processRequest(ctx.channel(), request, true); } @@ -138,7 +139,7 @@ public class PullMessageProcessor implements NettyRequestProcessor { if (requestHeader.getQueueId() < 0 || requestHeader.getQueueId() >= topicConfig.getReadQueueNums()) { String errorInfo = String.format("queueId[%d] is illegal, topic:[%s] topicConfig.readQueueNums:[%d] consumer:[%s]", - requestHeader.getQueueId(), requestHeader.getTopic(), topicConfig.getReadQueueNums(), channel.remoteAddress()); + requestHeader.getQueueId(), requestHeader.getTopic(), topicConfig.getReadQueueNums(), channel.remoteAddress()); log.warn(errorInfo); response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark(errorInfo); @@ -160,7 +161,7 @@ public class PullMessageProcessor implements NettyRequestProcessor { assert consumerFilterData != null; } } catch (Exception e) { - log.warn("Parse the consumer's subscription[{}] failed, group: {}", requestHeader.getSubscription(), // + log.warn("Parse the consumer's subscription[{}] failed, group: {}", requestHeader.getSubscription(), requestHeader.getConsumerGroup()); response.setCode(ResponseCode.SUBSCRIPTION_PARSE_FAILED); response.setRemark("parse the consumer's subscription failed"); @@ -176,7 +177,7 @@ public class PullMessageProcessor implements NettyRequestProcessor { return response; } - if (!subscriptionGroupConfig.isConsumeBroadcastEnable() // + if (!subscriptionGroupConfig.isConsumeBroadcastEnable() && consumerGroupInfo.getMessageModel() == MessageModel.BROADCASTING) { response.setCode(ResponseCode.NO_PERMISSION); response.setRemark("the consumer group[" + requestHeader.getConsumerGroup() + "] can not consume by broadcast way"); @@ -285,12 +286,12 @@ public class PullMessageProcessor implements NettyRequestProcessor { response.setCode(ResponseCode.PULL_OFFSET_MOVED); // XXX: warn and notify me - log.info("the broker store no queue data, fix the request offset {} to {}, Topic: {} QueueId: {} Consumer Group: {}", // - requestHeader.getQueueOffset(), // - getMessageResult.getNextBeginOffset(), // - requestHeader.getTopic(), // - requestHeader.getQueueId(), // - requestHeader.getConsumerGroup()// + log.info("the broker store no queue data, fix the request offset {} to {}, Topic: {} QueueId: {} Consumer Group: {}", + requestHeader.getQueueOffset(), + getMessageResult.getNextBeginOffset(), + requestHeader.getTopic(), + requestHeader.getQueueId(), + requestHeader.getConsumerGroup() ); } else { response.setCode(ResponseCode.PULL_NOT_FOUND); @@ -314,8 +315,8 @@ public class PullMessageProcessor implements NettyRequestProcessor { case OFFSET_TOO_SMALL: response.setCode(ResponseCode.PULL_OFFSET_MOVED); log.info("the request offset too small. group={}, topic={}, requestOffset={}, brokerMinOffset={}, clientIp={}", - requestHeader.getConsumerGroup(), requestHeader.getTopic(), requestHeader.getQueueOffset(), - getMessageResult.getMinOffset(), channel.remoteAddress()); + requestHeader.getConsumerGroup(), requestHeader.getTopic(), requestHeader.getQueueOffset(), + getMessageResult.getMinOffset(), channel.remoteAddress()); break; default: assert false; @@ -437,15 +438,15 @@ public class PullMessageProcessor implements NettyRequestProcessor { event.setOffsetNew(getMessageResult.getNextBeginOffset()); this.generateOffsetMovedEvent(event); log.warn( - "PULL_OFFSET_MOVED:correction offset. topic={}, groupId={}, requestOffset={}, newOffset={}, suggestBrokerId={}", - requestHeader.getTopic(), requestHeader.getConsumerGroup(), event.getOffsetRequest(), event.getOffsetNew(), - responseHeader.getSuggestWhichBrokerId()); + "PULL_OFFSET_MOVED:correction offset. topic={}, groupId={}, requestOffset={}, newOffset={}, suggestBrokerId={}", + requestHeader.getTopic(), requestHeader.getConsumerGroup(), event.getOffsetRequest(), event.getOffsetNew(), + responseHeader.getSuggestWhichBrokerId()); } else { responseHeader.setSuggestWhichBrokerId(subscriptionGroupConfig.getBrokerId()); response.setCode(ResponseCode.PULL_RETRY_IMMEDIATELY); log.warn("PULL_OFFSET_MOVED:none correction. topic={}, groupId={}, requestOffset={}, suggestBrokerId={}", - requestHeader.getTopic(), requestHeader.getConsumerGroup(), requestHeader.getQueueOffset(), - responseHeader.getSuggestWhichBrokerId()); + requestHeader.getTopic(), requestHeader.getConsumerGroup(), requestHeader.getQueueOffset(), + responseHeader.getSuggestWhichBrokerId()); } break; @@ -483,7 +484,8 @@ public class PullMessageProcessor implements NettyRequestProcessor { } } - private byte[] readGetMessageResult(final GetMessageResult getMessageResult, final String group, final String topic, final int queueId) { + private byte[] readGetMessageResult(final GetMessageResult getMessageResult, final String group, final String topic, + final int queueId) { final ByteBuffer byteBuffer = ByteBuffer.allocate(getMessageResult.getBufferTotalSize()); long storeTimestamp = 0; @@ -528,7 +530,8 @@ public class PullMessageProcessor implements NettyRequestProcessor { } } - public void executeRequestWhenWakeup(final Channel channel, final RemotingCommand request) throws RemotingCommandException { + public void executeRequestWhenWakeup(final Channel channel, + final RemotingCommand request) throws RemotingCommandException { Runnable run = new Runnable() { @Override public void run() { diff --git a/broker/src/main/java/org/apache/rocketmq/broker/processor/SendMessageProcessor.java b/broker/src/main/java/org/apache/rocketmq/broker/processor/SendMessageProcessor.java index 5c716cc865bb098579f73038d43c275f5f132dfe..227a23e6b495a1506ab3c22695c0960da26028dc 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/processor/SendMessageProcessor.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/processor/SendMessageProcessor.java @@ -60,7 +60,8 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement } @Override - public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand processRequest(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { SendMessageContext mqtraceContext; switch (request.getCode()) { case RequestCode.CONSUMER_SEND_MSG_BACK: @@ -139,9 +140,9 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement topicSysFlag = TopicSysFlag.buildSysFlag(false, true); } - TopicConfig topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(// - newTopic, // - subscriptionGroupConfig.getRetryQueueNums(), // + TopicConfig topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod( + newTopic, + subscriptionGroupConfig.getRetryQueueNums(), PermName.PERM_WRITE | PermName.PERM_READ, topicSysFlag); if (null == topicConfig) { response.setCode(ResponseCode.SYSTEM_ERROR); @@ -175,13 +176,13 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement maxReconsumeTimes = requestHeader.getMaxReconsumeTimes(); } - if (msgExt.getReconsumeTimes() >= maxReconsumeTimes// + if (msgExt.getReconsumeTimes() >= maxReconsumeTimes || delayLevel < 0) { newTopic = MixAll.getDLQTopic(requestHeader.getGroup()); queueIdInt = Math.abs(this.random.nextInt() % 99999999) % DLQ_NUMS_PER_GROUP; - topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(newTopic, // - DLQ_NUMS_PER_GROUP, // + topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(newTopic, + DLQ_NUMS_PER_GROUP, PermName.PERM_WRITE, 0 ); if (null == topicConfig) { @@ -245,8 +246,8 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement return response; } - - private boolean handleRetryAndDLQ(SendMessageRequestHeader requestHeader, RemotingCommand response, RemotingCommand request, + private boolean handleRetryAndDLQ(SendMessageRequestHeader requestHeader, RemotingCommand response, + RemotingCommand request, MessageExt msg, TopicConfig topicConfig) { String newTopic = requestHeader.getTopic(); if (null != newTopic && newTopic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) { @@ -268,8 +269,8 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement if (reconsumeTimes >= maxReconsumeTimes) { newTopic = MixAll.getDLQTopic(groupName); int queueIdInt = Math.abs(this.random.nextInt() % 99999999) % DLQ_NUMS_PER_GROUP; - topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(newTopic, // - DLQ_NUMS_PER_GROUP, // + topicConfig = this.brokerController.getTopicConfigManager().createTopicInSendMessageBackMethod(newTopic, + DLQ_NUMS_PER_GROUP, PermName.PERM_WRITE, 0 ); msg.setTopic(newTopic); @@ -289,9 +290,9 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement return true; } - private RemotingCommand sendMessage(final ChannelHandlerContext ctx, // - final RemotingCommand request, // - final SendMessageContext sendMessageContext, // + private RemotingCommand sendMessage(final ChannelHandlerContext ctx, + final RemotingCommand request, + final SendMessageContext sendMessageContext, final SendMessageRequestHeader requestHeader) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(SendMessageResponseHeader.class); @@ -319,8 +320,6 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement final byte[] body = request.getBody(); - - int queueIdInt = requestHeader.getQueueId(); TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(requestHeader.getTopic()); @@ -361,13 +360,14 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement } - - private RemotingCommand handlePutMessageResult(PutMessageResult putMessageResult, RemotingCommand response, RemotingCommand request, MessageExt msg, - SendMessageResponseHeader responseHeader, SendMessageContext sendMessageContext, ChannelHandlerContext ctx, int queueIdInt) { + private RemotingCommand handlePutMessageResult(PutMessageResult putMessageResult, RemotingCommand response, + RemotingCommand request, MessageExt msg, + SendMessageResponseHeader responseHeader, SendMessageContext sendMessageContext, ChannelHandlerContext ctx, + int queueIdInt) { if (putMessageResult == null) { response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("store putMessage return null"); - return response; + return response; } boolean sendOK = false; @@ -462,17 +462,17 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement sendMessageContext.setCommercialOwner(owner); } } - return response; + return response; } - private RemotingCommand sendBatchMessage(final ChannelHandlerContext ctx, // - final RemotingCommand request, // - final SendMessageContext sendMessageContext, // - final SendMessageRequestHeader requestHeader) throws RemotingCommandException { + + private RemotingCommand sendBatchMessage(final ChannelHandlerContext ctx, + final RemotingCommand request, + final SendMessageContext sendMessageContext, + final SendMessageRequestHeader requestHeader) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(SendMessageResponseHeader.class); final SendMessageResponseHeader responseHeader = (SendMessageResponseHeader) response.readCustomHeader(); - response.setOpaque(request.getOpaque()); response.addExtField(MessageConst.PROPERTY_MSG_REGION, this.brokerController.getBrokerConfig().getRegionId()); @@ -493,7 +493,6 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement return response; } - int queueIdInt = requestHeader.getQueueId(); TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(requestHeader.getTopic()); @@ -509,7 +508,7 @@ public class SendMessageProcessor extends AbstractSendMessageProcessor implement if (requestHeader.getTopic() != null && requestHeader.getTopic().startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) { response.setCode(ResponseCode.MESSAGE_ILLEGAL); - response.setRemark("batch request does not support retry group " + requestHeader.getTopic()); + response.setRemark("batch request does not support retry group " + requestHeader.getTopic()); return response; } MessageExtBatch messageExtBatch = new MessageExtBatch(); diff --git a/broker/src/main/java/org/apache/rocketmq/broker/subscription/SubscriptionGroupManager.java b/broker/src/main/java/org/apache/rocketmq/broker/subscription/SubscriptionGroupManager.java index bd4a26ed7dd65ff7252d09987f7cc3b3c4b1c76a..0cbb76172ca4fb39f9d964df0b852c028740c022 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/subscription/SubscriptionGroupManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/subscription/SubscriptionGroupManager.java @@ -143,7 +143,7 @@ public class SubscriptionGroupManager extends ConfigManager { @Override public String configFilePath() { return BrokerPathConfigHelper.getSubscriptionGroupPath(this.brokerController.getMessageStoreConfig() - .getStorePathRootDir()); + .getStorePathRootDir()); } @Override diff --git a/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java b/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java index 0d10a16239e5e8e5ca79ad266619701537f14652..cd30a089b7a7feafa9964838aea2cea77f22bd99 100644 --- a/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java +++ b/broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java @@ -272,7 +272,7 @@ public class TopicConfigManager extends ConfigManager { } log.info("update topic sys flag. oldTopicSysFlag={}, newTopicSysFlag", oldTopicSysFlag, - topicConfig.getTopicSysFlag()); + topicConfig.getTopicSysFlag()); this.topicConfigTable.put(topic, topicConfig); @@ -292,7 +292,7 @@ public class TopicConfigManager extends ConfigManager { } log.info("update topic sys flag. oldTopicSysFlag={}, newTopicSysFlag", oldTopicSysFlag, - topicConfig.getTopicSysFlag()); + topicConfig.getTopicSysFlag()); this.topicConfigTable.put(topic, topicConfig); @@ -384,7 +384,7 @@ public class TopicConfigManager extends ConfigManager { @Override public String configFilePath() { return BrokerPathConfigHelper.getTopicConfigPath(this.brokerController.getMessageStoreConfig() - .getStorePathRootDir()); + .getStorePathRootDir()); } @Override diff --git a/broker/src/test/java/org/apache/rocketmq/broker/BrokerControllerTest.java b/broker/src/test/java/org/apache/rocketmq/broker/BrokerControllerTest.java index 86b9c4ed02091d996a2b63d664cdbb915e67ab56..797e0d882a2600d436a38a2f6c5ba9c40e3fc31b 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/BrokerControllerTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/BrokerControllerTest.java @@ -18,11 +18,15 @@ package org.apache.rocketmq.broker; import org.apache.rocketmq.common.BrokerConfig; +import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.remoting.netty.NettyClientConfig; import org.apache.rocketmq.remoting.netty.NettyServerConfig; import org.apache.rocketmq.store.config.MessageStoreConfig; +import org.junit.After; import org.junit.Test; +import java.io.File; + import static org.assertj.core.api.Assertions.assertThat; public class BrokerControllerTest { @@ -33,15 +37,18 @@ public class BrokerControllerTest { */ @Test public void testBrokerRestart() throws Exception { - for (int i = 0; i < 2; i++) { - BrokerController brokerController = new BrokerController(// - new BrokerConfig(), // - new NettyServerConfig(), // - new NettyClientConfig(), // - new MessageStoreConfig()); - assertThat(brokerController.initialize()); - brokerController.start(); - brokerController.shutdown(); - } + BrokerController brokerController = new BrokerController( + new BrokerConfig(), + new NettyServerConfig(), + new NettyClientConfig(), + new MessageStoreConfig()); + assertThat(brokerController.initialize()); + brokerController.start(); + brokerController.shutdown(); + } + + @After + public void destory() { + UtilAll.deleteFile(new File(new MessageStoreConfig().getStorePathRootDir())); } } diff --git a/broker/src/test/java/org/apache/rocketmq/broker/filter/CommitLogDispatcherCalcBitMapTest.java b/broker/src/test/java/org/apache/rocketmq/broker/filter/CommitLogDispatcherCalcBitMapTest.java index 87f625616cf52987e93931e6ff82f8cec67ee4ea..8f28832c0c76b99214c851333afe76bcbfac4691 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/filter/CommitLogDispatcherCalcBitMapTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/filter/CommitLogDispatcherCalcBitMapTest.java @@ -51,7 +51,6 @@ public class CommitLogDispatcherCalcBitMapTest { ConsumerFilterData nullBloomData = filterManager.get("topic0", "CID_1"); nullBloomData.setBloomFilterData(null); - CommitLogDispatcherCalcBitMap calcBitMap = new CommitLogDispatcherCalcBitMap(brokerConfig, filterManager); diff --git a/broker/src/test/java/org/apache/rocketmq/broker/filter/ConsumerFilterManagerTest.java b/broker/src/test/java/org/apache/rocketmq/broker/filter/ConsumerFilterManagerTest.java index c8412a8bff8911f9a0ff6b4940dbebfdb248e65b..68d60092d8be7a3f16e8c9f175f0f40a132205c3 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/filter/ConsumerFilterManagerTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/filter/ConsumerFilterManagerTest.java @@ -17,6 +17,7 @@ package org.apache.rocketmq.broker.filter; +import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.filter.ExpressionType; import org.apache.rocketmq.common.filter.FilterAPI; import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; @@ -232,7 +233,7 @@ public class ConsumerFilterManagerTest { assertThat(filterData.isDead()).isTrue(); assertThat(filterData.getCompiledExpression()).isNotNull(); } finally { - deleteDirectory("./unit_test"); + UtilAll.deleteFile(new File("./unit_test")); } } @@ -269,23 +270,8 @@ public class ConsumerFilterManagerTest { assertThat(topicData).isNullOrEmpty(); } finally { - deleteDirectory("./unit_test"); + UtilAll.deleteFile(new File("./unit_test")); } } - protected void deleteDirectory(String rootPath) { - File file = new File(rootPath); - deleteFile(file); - } - - protected void deleteFile(File file) { - File[] subFiles = file.listFiles(); - if (subFiles != null) { - for (File sub : subFiles) { - deleteFile(sub); - } - } - - file.delete(); - } } diff --git a/broker/src/test/java/org/apache/rocketmq/broker/filter/MessageStoreWithFilterTest.java b/broker/src/test/java/org/apache/rocketmq/broker/filter/MessageStoreWithFilterTest.java index 53e563edc2fcc40a2160be1d8b1d7739ca91dab5..7978942e5bbdd5f9cbd32176153d0819da221518 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/filter/MessageStoreWithFilterTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/filter/MessageStoreWithFilterTest.java @@ -18,6 +18,7 @@ package org.apache.rocketmq.broker.filter; import org.apache.rocketmq.common.BrokerConfig; +import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.filter.ExpressionType; import org.apache.rocketmq.common.message.MessageDecoder; import org.apache.rocketmq.common.message.MessageExt; @@ -32,6 +33,8 @@ import org.apache.rocketmq.store.MessageExtBrokerInner; import org.apache.rocketmq.store.PutMessageResult; import org.apache.rocketmq.store.config.MessageStoreConfig; import org.apache.rocketmq.store.stats.BrokerStatsManager; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import java.io.File; @@ -62,6 +65,14 @@ public class MessageStoreWithFilterTest { private static SocketAddress StoreHost; + private DefaultMessageStore master; + + private ConsumerFilterManager filterManager; + + private int topicCount = 3; + + private int msgPerTopic = 30; + static { try { StoreHost = new InetSocketAddress(InetAddress.getLocalHost(), 8123); @@ -75,6 +86,24 @@ public class MessageStoreWithFilterTest { } } + @Before + public void init() { + filterManager = ConsumerFilterManagerTest.gen(topicCount, msgPerTopic); + try { + master = gen(filterManager); + } catch (Exception e) { + e.printStackTrace(); + assertThat(true).isFalse(); + } + } + + @After + public void destroy() { + master.shutdown(); + master.destroy(); + UtilAll.deleteFile(new File(storePath)); + } + public MessageExtBrokerInner buildMessage() { MessageExtBrokerInner msg = new MessageExtBrokerInner(); msg.setTopic(topic); @@ -96,7 +125,7 @@ public class MessageStoreWithFilterTest { } public MessageStoreConfig buildStoreConfig(int commitLogFileSize, int cqFileSize, - boolean enableCqExt, int cqExtFileSize) { + boolean enableCqExt, int cqExtFileSize) { MessageStoreConfig messageStoreConfig = new MessageStoreConfig(); messageStoreConfig.setMapedFileSizeCommitLog(commitLogFileSize); messageStoreConfig.setMapedFileSizeConsumeQueue(cqFileSize); @@ -126,7 +155,7 @@ public class MessageStoreWithFilterTest { new MessageArrivingListener() { @Override public void arriving(String topic, int queueId, long logicOffset, long tagsCode, - long msgStoreTime, byte[] filterBitMap, Map properties) { + long msgStoreTime, byte[] filterBitMap, Map properties) { // System.out.println(String.format("Msg coming: %s, %d, %d, %d", // topic, queueId, logicOffset, tagsCode)); } @@ -153,7 +182,8 @@ public class MessageStoreWithFilterTest { return master; } - protected List putMsg(DefaultMessageStore master, int topicCount, int msgCountPerTopic) throws Exception { + protected List putMsg(DefaultMessageStore master, int topicCount, + int msgCountPerTopic) throws Exception { List msgs = new ArrayList(); for (int i = 0; i < topicCount; i++) { String realTopic = topic + i; @@ -174,22 +204,6 @@ public class MessageStoreWithFilterTest { return msgs; } - protected void deleteDirectory(String rootPath) { - File file = new File(rootPath); - deleteFile(file); - } - - protected void deleteFile(File file) { - File[] subFiles = file.listFiles(); - if (subFiles != null) { - for (File sub : subFiles) { - deleteFile(sub); - } - } - - file.delete(); - } - protected List filtered(List msgs, ConsumerFilterData filterData) { List filteredMsgs = new ArrayList(); @@ -216,177 +230,143 @@ public class MessageStoreWithFilterTest { @Test public void testGetMessage_withFilterBitMapAndConsumerChanged() { - int topicCount = 10, msgPerTopic = 10; - ConsumerFilterManager filterManager = ConsumerFilterManagerTest.gen(topicCount, msgPerTopic); - - DefaultMessageStore master = null; + List msgs = null; try { - master = gen(filterManager); + msgs = putMsg(master, topicCount, msgPerTopic); } catch (Exception e) { e.printStackTrace(); assertThat(true).isFalse(); } + // sleep to wait for consume queue has been constructed. try { - List msgs = null; - try { - msgs = putMsg(master, topicCount, msgPerTopic); - } catch (Exception e) { - e.printStackTrace(); - assertThat(true).isFalse(); - } - - // sleep to wait for consume queue has been constructed. - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - assertThat(true).isFalse(); - } + Thread.sleep(200); + } catch (InterruptedException e) { + e.printStackTrace(); + assertThat(true).isFalse(); + } - // reset consumer; - String topic = "topic" + 0; - String resetGroup = "CID_" + 2; - String normalGroup = "CID_" + 3; + // reset consumer; + String topic = "topic" + 0; + String resetGroup = "CID_" + 2; + String normalGroup = "CID_" + 3; - { - // reset CID_2@topic0 to get all messages. - SubscriptionData resetSubData = new SubscriptionData(); - resetSubData.setExpressionType(ExpressionType.SQL92); - resetSubData.setTopic(topic); - resetSubData.setClassFilterMode(false); - resetSubData.setSubString("a is not null OR a is null"); + { + // reset CID_2@topic0 to get all messages. + SubscriptionData resetSubData = new SubscriptionData(); + resetSubData.setExpressionType(ExpressionType.SQL92); + resetSubData.setTopic(topic); + resetSubData.setClassFilterMode(false); + resetSubData.setSubString("a is not null OR a is null"); - ConsumerFilterData resetFilterData = ConsumerFilterManager.build(topic, - resetGroup, resetSubData.getSubString(), resetSubData.getExpressionType(), - System.currentTimeMillis()); + ConsumerFilterData resetFilterData = ConsumerFilterManager.build(topic, + resetGroup, resetSubData.getSubString(), resetSubData.getExpressionType(), + System.currentTimeMillis()); - GetMessageResult resetGetResult = master.getMessage(resetGroup, topic, queueId, 0, 1000, - new ExpressionMessageFilter(resetSubData, resetFilterData, filterManager)); + GetMessageResult resetGetResult = master.getMessage(resetGroup, topic, queueId, 0, 1000, + new ExpressionMessageFilter(resetSubData, resetFilterData, filterManager)); - try { - assertThat(resetGetResult).isNotNull(); + try { + assertThat(resetGetResult).isNotNull(); - List filteredMsgs = filtered(msgs, resetFilterData); + List filteredMsgs = filtered(msgs, resetFilterData); - assertThat(resetGetResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size()); - } finally { - resetGetResult.release(); - } + assertThat(resetGetResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size()); + } finally { + resetGetResult.release(); } + } - { - ConsumerFilterData normalFilterData = filterManager.get(topic, normalGroup); - assertThat(normalFilterData).isNotNull(); - assertThat(normalFilterData.getBornTime()).isLessThan(System.currentTimeMillis()); + { + ConsumerFilterData normalFilterData = filterManager.get(topic, normalGroup); + assertThat(normalFilterData).isNotNull(); + assertThat(normalFilterData.getBornTime()).isLessThan(System.currentTimeMillis()); - SubscriptionData normalSubData = new SubscriptionData(); - normalSubData.setExpressionType(normalFilterData.getExpressionType()); - normalSubData.setTopic(topic); - normalSubData.setClassFilterMode(false); - normalSubData.setSubString(normalFilterData.getExpression()); + SubscriptionData normalSubData = new SubscriptionData(); + normalSubData.setExpressionType(normalFilterData.getExpressionType()); + normalSubData.setTopic(topic); + normalSubData.setClassFilterMode(false); + normalSubData.setSubString(normalFilterData.getExpression()); - List filteredMsgs = filtered(msgs, normalFilterData); + List filteredMsgs = filtered(msgs, normalFilterData); - GetMessageResult normalGetResult = master.getMessage(normalGroup, topic, queueId, 0, 1000, - new ExpressionMessageFilter(normalSubData, normalFilterData, filterManager)); + GetMessageResult normalGetResult = master.getMessage(normalGroup, topic, queueId, 0, 1000, + new ExpressionMessageFilter(normalSubData, normalFilterData, filterManager)); - try { - assertThat(normalGetResult).isNotNull(); - assertThat(normalGetResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size()); - } finally { - normalGetResult.release(); - } + try { + assertThat(normalGetResult).isNotNull(); + assertThat(normalGetResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size()); + } finally { + normalGetResult.release(); } - } finally { - master.shutdown(); - master.destroy(); - deleteDirectory(storePath); } } @Test public void testGetMessage_withFilterBitMap() { - int topicCount = 10, msgPerTopic = 500; - ConsumerFilterManager filterManager = ConsumerFilterManagerTest.gen(topicCount, msgPerTopic); - - DefaultMessageStore master = null; + List msgs = null; try { - master = gen(filterManager); + msgs = putMsg(master, topicCount, msgPerTopic); + // sleep to wait for consume queue has been constructed. + Thread.sleep(200); } catch (Exception e) { e.printStackTrace(); assertThat(true).isFalse(); } - try { - List msgs = null; - try { - msgs = putMsg(master, topicCount, msgPerTopic); - // sleep to wait for consume queue has been constructed. - Thread.sleep(1000); - } catch (Exception e) { - e.printStackTrace(); - assertThat(true).isFalse(); - } + for (int i = 0; i < topicCount; i++) { + String realTopic = topic + i; - for (int i = 0; i < topicCount; i++) { - String realTopic = topic + i; - - for (int j = 0; j < msgPerTopic; j++) { - String group = "CID_" + j; - - ConsumerFilterData filterData = filterManager.get(realTopic, group); - assertThat(filterData).isNotNull(); - - List filteredMsgs = filtered(msgs, filterData); - - SubscriptionData subscriptionData = new SubscriptionData(); - subscriptionData.setExpressionType(filterData.getExpressionType()); - subscriptionData.setTopic(filterData.getTopic()); - subscriptionData.setClassFilterMode(false); - subscriptionData.setSubString(filterData.getExpression()); - - GetMessageResult getMessageResult = master.getMessage(group, realTopic, queueId, 0, 10000, - new ExpressionMessageFilter(subscriptionData, filterData, filterManager)); - String assertMsg = group + "-" + realTopic; - try { - assertThat(getMessageResult).isNotNull(); - assertThat(GetMessageStatus.FOUND).isEqualTo(getMessageResult.getStatus()); - assertThat(getMessageResult.getMessageBufferList()).isNotNull().isNotEmpty(); - assertThat(getMessageResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size()); - - for (ByteBuffer buffer : getMessageResult.getMessageBufferList()) { - MessageExt messageExt = MessageDecoder.decode(buffer.slice(), false); - assertThat(messageExt).isNotNull(); - - Object evlRet = null; - try { - evlRet = filterData.getCompiledExpression().evaluate(new MessageEvaluationContext(messageExt.getProperties())); - } catch (Exception e) { - e.printStackTrace(); - assertThat(true).isFalse(); - } + for (int j = 0; j < msgPerTopic; j++) { + String group = "CID_" + j; + + ConsumerFilterData filterData = filterManager.get(realTopic, group); + assertThat(filterData).isNotNull(); + + List filteredMsgs = filtered(msgs, filterData); + + SubscriptionData subscriptionData = new SubscriptionData(); + subscriptionData.setExpressionType(filterData.getExpressionType()); + subscriptionData.setTopic(filterData.getTopic()); + subscriptionData.setClassFilterMode(false); + subscriptionData.setSubString(filterData.getExpression()); - assertThat(evlRet).isNotNull().isEqualTo(Boolean.TRUE); + GetMessageResult getMessageResult = master.getMessage(group, realTopic, queueId, 0, 10000, + new ExpressionMessageFilter(subscriptionData, filterData, filterManager)); + String assertMsg = group + "-" + realTopic; + try { + assertThat(getMessageResult).isNotNull(); + assertThat(GetMessageStatus.FOUND).isEqualTo(getMessageResult.getStatus()); + assertThat(getMessageResult.getMessageBufferList()).isNotNull().isNotEmpty(); + assertThat(getMessageResult.getMessageBufferList().size()).isEqualTo(filteredMsgs.size()); + + for (ByteBuffer buffer : getMessageResult.getMessageBufferList()) { + MessageExt messageExt = MessageDecoder.decode(buffer.slice(), false); + assertThat(messageExt).isNotNull(); + + Object evlRet = null; + try { + evlRet = filterData.getCompiledExpression().evaluate(new MessageEvaluationContext(messageExt.getProperties())); + } catch (Exception e) { + e.printStackTrace(); + assertThat(true).isFalse(); + } - // check - boolean find = false; - for (MessageExtBrokerInner messageExtBrokerInner : filteredMsgs) { - if (messageExtBrokerInner.getMsgId().equals(messageExt.getMsgId())) { - find = true; - } + assertThat(evlRet).isNotNull().isEqualTo(Boolean.TRUE); + + // check + boolean find = false; + for (MessageExtBrokerInner messageExtBrokerInner : filteredMsgs) { + if (messageExtBrokerInner.getMsgId().equals(messageExt.getMsgId())) { + find = true; } - assertThat(find).isTrue(); } - } finally { - getMessageResult.release(); + assertThat(find).isTrue(); } + } finally { + getMessageResult.release(); } } - } finally { - master.shutdown(); - master.destroy(); - deleteDirectory(storePath); } } } diff --git a/broker/src/test/java/org/apache/rocketmq/broker/processor/PullMessageProcessorTest.java b/broker/src/test/java/org/apache/rocketmq/broker/processor/PullMessageProcessorTest.java index 941d4a77feaaba6687840db3a4e59612f7409905..c96f708e85463937ada305d8930c37dc4d83de9d 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/processor/PullMessageProcessorTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/processor/PullMessageProcessorTest.java @@ -142,15 +142,18 @@ public class PullMessageProcessorTest { List consumeMessageHookList = new ArrayList<>(); final ConsumeMessageContext[] messageContext = new ConsumeMessageContext[1]; ConsumeMessageHook consumeMessageHook = new ConsumeMessageHook() { - @Override public String hookName() { + @Override + public String hookName() { return "TestHook"; } - @Override public void consumeMessageBefore(ConsumeMessageContext context) { + @Override + public void consumeMessageBefore(ConsumeMessageContext context) { messageContext[0] = context; } - @Override public void consumeMessageAfter(ConsumeMessageContext context) { + @Override + public void consumeMessageAfter(ConsumeMessageContext context) { } }; consumeMessageHookList.add(consumeMessageHook); diff --git a/broker/src/test/java/org/apache/rocketmq/broker/processor/SendMessageProcessorTest.java b/broker/src/test/java/org/apache/rocketmq/broker/processor/SendMessageProcessorTest.java index 02490a07b0fe51182390666489dd6c8ac73a362b..7828e7a91cdfe03b919b29f928e792fc8324b87e 100644 --- a/broker/src/test/java/org/apache/rocketmq/broker/processor/SendMessageProcessorTest.java +++ b/broker/src/test/java/org/apache/rocketmq/broker/processor/SendMessageProcessorTest.java @@ -94,15 +94,18 @@ public class SendMessageProcessorTest { List sendMessageHookList = new ArrayList<>(); final SendMessageContext[] sendMessageContext = new SendMessageContext[1]; SendMessageHook sendMessageHook = new SendMessageHook() { - @Override public String hookName() { + @Override + public String hookName() { return null; } - @Override public void sendMessageBefore(SendMessageContext context) { + @Override + public void sendMessageBefore(SendMessageContext context) { sendMessageContext[0] = context; } - @Override public void sendMessageAfter(SendMessageContext context) { + @Override + public void sendMessageAfter(SendMessageContext context) { } }; @@ -115,7 +118,6 @@ public class SendMessageProcessorTest { assertThat(sendMessageContext[0].getProducerGroup()).isEqualTo(group); } - @Test public void testProcessRequest_FlushTimeOut() throws RemotingCommandException { when(messageStore.putMessage(any(MessageExtBrokerInner.class))).thenReturn(new PutMessageResult(PutMessageStatus.FLUSH_DISK_TIMEOUT, new AppendMessageResult(AppendMessageStatus.UNKNOWN_ERROR))); @@ -210,7 +212,8 @@ public class SendMessageProcessorTest { final RemotingCommand request = createSendMsgCommand(RequestCode.SEND_MESSAGE); final RemotingCommand[] response = new RemotingCommand[1]; doAnswer(new Answer() { - @Override public Object answer(InvocationOnMock invocation) throws Throwable { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { response[0] = invocation.getArgument(0); return null; } diff --git a/broker/src/test/resources/logback-test.xml b/broker/src/test/resources/logback-test.xml index 908373e86b7817fe17e9dcb13720f6b7efe0b727..1978b73ae07ef26b2a0d8f6d46cd0e7ad13b8404 100644 --- a/broker/src/test/resources/logback-test.xml +++ b/broker/src/test/resources/logback-test.xml @@ -19,7 +19,6 @@ - true %d{yyy-MM-dd HH\:mm\:ss,GMT+8} %p %t - %m%n UTF-8 diff --git a/client/src/main/java/org/apache/rocketmq/client/MQAdmin.java b/client/src/main/java/org/apache/rocketmq/client/MQAdmin.java index a0144a29106310ae5866847ae9bcaa56b4aeca95..019414b9e5c151d29fe6f093a8caf13a6e89efe8 100644 --- a/client/src/main/java/org/apache/rocketmq/client/MQAdmin.java +++ b/client/src/main/java/org/apache/rocketmq/client/MQAdmin.java @@ -32,7 +32,6 @@ public interface MQAdmin { * @param key accesskey * @param newTopic topic name * @param queueNum topic's queue number - * @throws MQClientException */ void createTopic(final String key, final String newTopic, final int queueNum) throws MQClientException; @@ -44,7 +43,6 @@ public interface MQAdmin { * @param newTopic topic name * @param queueNum topic's queue number * @param topicSysFlag topic system flag - * @throws MQClientException */ void createTopic(String key, String newTopic, int queueNum, int topicSysFlag) throws MQClientException; @@ -56,7 +54,6 @@ public interface MQAdmin { * @param mq Instance of MessageQueue * @param timestamp from when in milliseconds. * @return offset - * @throws MQClientException */ long searchOffset(final MessageQueue mq, final long timestamp) throws MQClientException; @@ -65,7 +62,6 @@ public interface MQAdmin { * * @param mq Instance of MessageQueue * @return the max offset - * @throws MQClientException */ long maxOffset(final MessageQueue mq) throws MQClientException; @@ -74,7 +70,6 @@ public interface MQAdmin { * * @param mq Instance of MessageQueue * @return the minimum offset - * @throws MQClientException */ long minOffset(final MessageQueue mq) throws MQClientException; @@ -83,7 +78,6 @@ public interface MQAdmin { * * @param mq Instance of MessageQueue * @return the time in microseconds - * @throws MQClientException */ long earliestMsgStoreTime(final MessageQueue mq) throws MQClientException; @@ -92,10 +86,6 @@ public interface MQAdmin { * * @param offsetMsgId message id * @return message - * @throws InterruptedException - * @throws MQBrokerException - * @throws RemotingException - * @throws MQClientException */ MessageExt viewMessage(final String offsetMsgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; @@ -109,21 +99,14 @@ public interface MQAdmin { * @param begin from when * @param end to when * @return Instance of QueryResult - * @throws MQClientException - * @throws InterruptedException */ QueryResult queryMessage(final String topic, final String key, final int maxNum, final long begin, final long end) throws MQClientException, InterruptedException; /** - * @param topic - * @param msgId * @return The {@code MessageExt} of given msgId - * @throws RemotingException - * @throws MQBrokerException - * @throws InterruptedException - * @throws MQClientException */ - MessageExt viewMessage(String topic, String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; + MessageExt viewMessage(String topic, + String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; } \ No newline at end of file diff --git a/client/src/main/java/org/apache/rocketmq/client/MQHelper.java b/client/src/main/java/org/apache/rocketmq/client/MQHelper.java index b78e1cb35a5bf5459af9bfaf3a2cbbf2c677dd28..7f0cef31b4d4eedfad44f65f4f14660bb5a460cc 100644 --- a/client/src/main/java/org/apache/rocketmq/client/MQHelper.java +++ b/client/src/main/java/org/apache/rocketmq/client/MQHelper.java @@ -41,7 +41,6 @@ public class MQHelper { * @param consumerGroup consumer group * @param topic topic * @param timestamp time - * @throws Exception */ public static void resetOffsetByTimestamp( final MessageModel messageModel, diff --git a/client/src/main/java/org/apache/rocketmq/client/Validators.java b/client/src/main/java/org/apache/rocketmq/client/Validators.java index b49537f8c695a97c984ac56661346572ff9224b4..5567e49b558aedba22c2e53241671e3d2d98ed74 100644 --- a/client/src/main/java/org/apache/rocketmq/client/Validators.java +++ b/client/src/main/java/org/apache/rocketmq/client/Validators.java @@ -35,8 +35,6 @@ public class Validators { public static final int CHARACTER_MAX_LENGTH = 255; /** - * @param origin - * @param patternStr * @return The resulting {@code String} */ public static String getGroupWithRegularExpression(String origin, String patternStr) { @@ -50,9 +48,6 @@ public class Validators { /** * Validate group - * - * @param group - * @throws MQClientException */ public static void checkGroup(String group) throws MQClientException { if (UtilAll.isBlank(group)) { @@ -69,8 +64,6 @@ public class Validators { } /** - * @param origin - * @param pattern * @return true if, and only if, the entire origin sequence matches this matcher's pattern */ public static boolean regularExpressionMatcher(String origin, Pattern pattern) { @@ -83,10 +76,6 @@ public class Validators { /** * Validate message - * - * @param msg - * @param defaultMQProducer - * @throws MQClientException */ public static void checkMessage(Message msg, DefaultMQProducer defaultMQProducer) throws MQClientException { @@ -113,9 +102,6 @@ public class Validators { /** * Validate topic - * - * @param topic - * @throws MQClientException */ public static void checkTopic(String topic) throws MQClientException { if (UtilAll.isBlank(topic)) { 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 f5016f82f51c56e9ecd2ea74b5a3a0afaa3908e9..cd70670307846d35208248ca0930d4f1c874fdd3 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 @@ -264,7 +264,8 @@ public class DefaultMQPullConsumer extends ClientConfig implements MQPullConsume } @Override - public void pull(MessageQueue mq, String subExpression, long offset, int maxNums, PullCallback pullCallback, long timeout) + public void pull(MessageQueue mq, String subExpression, long offset, int maxNums, PullCallback pullCallback, + long timeout) throws MQClientException, RemotingException, InterruptedException { this.defaultMQPullConsumerImpl.pull(mq, subExpression, offset, maxNums, pullCallback, timeout); } @@ -276,7 +277,8 @@ public class DefaultMQPullConsumer extends ClientConfig implements MQPullConsume } @Override - public void pullBlockIfNotFound(MessageQueue mq, String subExpression, long offset, int maxNums, PullCallback pullCallback) + public void pullBlockIfNotFound(MessageQueue mq, String subExpression, long offset, int maxNums, + PullCallback pullCallback) throws MQClientException, RemotingException, InterruptedException { this.defaultMQPullConsumerImpl.pullBlockIfNotFound(mq, subExpression, offset, maxNums, pullCallback); } @@ -297,7 +299,8 @@ public class DefaultMQPullConsumer extends ClientConfig implements MQPullConsume } @Override - public MessageExt viewMessage(String topic, String uniqKey) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + public MessageExt viewMessage(String topic, + String uniqKey) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { try { MessageDecoder.decodeMessageId(uniqKey); return this.viewMessage(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 9c9b59ef0762b554c90e5cb7e719aabce2937e48..42ce2f9c0c15306a4896930f7399efc940b3ac11 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 @@ -51,7 +51,7 @@ import org.apache.rocketmq.remoting.exception.RemotingException; *

* *

- * Thread Safety: After initialization, the instance can be regarded as thread-safe. + * Thread Safety: After initialization, the instance can be regarded as thread-safe. *

*/ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsumer { @@ -90,29 +90,29 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume * * There are three consuming points: *
    - *
  • - * CONSUME_FROM_LAST_OFFSET: consumer clients pick up where it stopped previously. - * If it were a newly booting up consumer client, according aging of the consumer group, there are two - * cases: - *
      - *
    1. - * if the consumer group is created so recently that the earliest message being subscribed has yet - * expired, which means the consumer group represents a lately launched business, consuming will - * start from the very beginning; - *
    2. - *
    3. - * if the earliest message being subscribed has expired, consuming will start from the latest - * messages, meaning messages born prior to the booting timestamp would be ignored. - *
    4. - *
    - *
  • - *
  • - * CONSUME_FROM_FIRST_OFFSET: Consumer client will start from earliest messages available. - *
  • - *
  • - * CONSUME_FROM_TIMESTAMP: Consumer client will start from specified timestamp, which means - * messages born prior to {@link #consumeTimestamp} will be ignored - *
  • + *
  • + * CONSUME_FROM_LAST_OFFSET: consumer clients pick up where it stopped previously. + * If it were a newly booting up consumer client, according aging of the consumer group, there are two + * cases: + *
      + *
    1. + * if the consumer group is created so recently that the earliest message being subscribed has yet + * expired, which means the consumer group represents a lately launched business, consuming will + * start from the very beginning; + *
    2. + *
    3. + * if the earliest message being subscribed has expired, consuming will start from the latest + * messages, meaning messages born prior to the booting timestamp would be ignored. + *
    4. + *
    + *
  • + *
  • + * CONSUME_FROM_FIRST_OFFSET: Consumer client will start from earliest messages available. + *
  • + *
  • + * CONSUME_FROM_TIMESTAMP: Consumer client will start from specified timestamp, which means + * messages born prior to {@link #consumeTimestamp} will be ignored + *
  • *
*/ private ConsumeFromWhere consumeFromWhere = ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET; @@ -223,11 +223,13 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume /** * Constructor specifying consumer group, RPC hook and message queue allocating algorithm. + * * @param consumerGroup Consume queue. * @param rpcHook RPC hook to execute before each remoting command. * @param allocateMessageQueueStrategy message queue allocating algorithm. */ - public DefaultMQPushConsumer(final String consumerGroup, RPCHook rpcHook, AllocateMessageQueueStrategy allocateMessageQueueStrategy) { + public DefaultMQPushConsumer(final String consumerGroup, RPCHook rpcHook, + AllocateMessageQueueStrategy allocateMessageQueueStrategy) { this.consumerGroup = consumerGroup; this.allocateMessageQueueStrategy = allocateMessageQueueStrategy; defaultMQPushConsumerImpl = new DefaultMQPushConsumerImpl(this, rpcHook); @@ -235,6 +237,7 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume /** * Constructor specifying RPC hook. + * * @param rpcHook RPC hook to execute before each remoting command. */ public DefaultMQPushConsumer(RPCHook rpcHook) { @@ -243,6 +246,7 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume /** * Constructor specifying consumer group. + * * @param consumerGroup Consumer group. */ public DefaultMQPushConsumer(final String consumerGroup) { @@ -280,7 +284,8 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume } @Override - public MessageExt viewMessage(String offsetMsgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + public MessageExt viewMessage( + String offsetMsgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { return this.defaultMQPushConsumerImpl.viewMessage(offsetMsgId); } @@ -291,7 +296,8 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume } @Override - public MessageExt viewMessage(String topic, String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + public MessageExt viewMessage(String topic, + String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { try { MessageDecoder.decodeMessageId(msgId); return this.viewMessage(msgId); @@ -411,6 +417,7 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume /** * Send message back to broker which will be re-delivered in future. + * * @param msg Message to send back. * @param delayLevel delay level. * @throws RemotingException if there is any network-tier error. @@ -449,6 +456,7 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume /** * This method gets internal infrastructure readily to serve. Instances must call this method after configuration. + * * @throws MQClientException if there is any client error. */ @Override @@ -498,7 +506,7 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume * * @param topic topic to subscribe. * @param subExpression subscription expression.it only support or operation such as "tag1 || tag2 || tag3"
- * if null or * expression,meaning subscribe all + * if null or * expression,meaning subscribe all * @throws MQClientException if there is any client error. */ @Override @@ -508,10 +516,10 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume /** * Subscribe a topic to consuming subscription. + * * @param topic topic to consume. * @param fullClassName full class name,must extend org.apache.rocketmq.common.filter. MessageFilter * @param filterClassSource class source code,used UTF-8 file encoding,must be responsible for your code safety - * @throws MQClientException */ @Override public void subscribe(String topic, String fullClassName, String filterClassSource) throws MQClientException { @@ -521,12 +529,10 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume /** * Subscribe a topic by message selector. * - * @see org.apache.rocketmq.client.consumer.MessageSelector#bySql - * @see org.apache.rocketmq.client.consumer.MessageSelector#byTag - * * @param topic topic to consume. * @param messageSelector {@link org.apache.rocketmq.client.consumer.MessageSelector} - * @throws MQClientException + * @see org.apache.rocketmq.client.consumer.MessageSelector#bySql + * @see org.apache.rocketmq.client.consumer.MessageSelector#byTag */ @Override public void subscribe(final String topic, final MessageSelector messageSelector) throws MQClientException { @@ -535,6 +541,7 @@ public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsume /** * Un-subscribe the specified topic from subscription. + * * @param topic message topic */ @Override diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/MQConsumer.java b/client/src/main/java/org/apache/rocketmq/client/consumer/MQConsumer.java index 03ee4d96654ab4b7631b60710c1703829bd400d3..f4a8eda23a495df3f16e9475b6dbea4357b03fe8 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/MQConsumer.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/MQConsumer.java @@ -30,13 +30,6 @@ import org.apache.rocketmq.remoting.exception.RemotingException; public interface MQConsumer extends MQAdmin { /** * If consuming failure,message will be send back to the brokers,and delay consuming some time - * - * @param msg - * @param delayLevel - * @throws InterruptedException - * @throws MQBrokerException - * @throws RemotingException - * @throws MQClientException */ @Deprecated void sendMessageBack(final MessageExt msg, final int delayLevel) throws RemotingException, @@ -44,14 +37,6 @@ public interface MQConsumer extends MQAdmin { /** * If consuming failure,message will be send back to the broker,and delay consuming some time - * - * @param msg - * @param delayLevel - * @param brokerName - * @throws RemotingException - * @throws MQBrokerException - * @throws InterruptedException - * @throws MQClientException */ void sendMessageBack(final MessageExt msg, final int delayLevel, final String brokerName) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; @@ -61,7 +46,6 @@ public interface MQConsumer extends MQAdmin { * * @param topic message topic * @return queue set - * @throws MQClientException */ Set fetchSubscribeMessageQueues(final String topic) throws MQClientException; } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/MQPullConsumer.java b/client/src/main/java/org/apache/rocketmq/client/consumer/MQPullConsumer.java index da43aa9dd5793d6b84b2db1030a630c9dd6fc4e0..33002c9837176982f9015093a6b945a512b04111 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/MQPullConsumer.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/MQPullConsumer.java @@ -29,8 +29,6 @@ import org.apache.rocketmq.remoting.exception.RemotingException; public interface MQPullConsumer extends MQConsumer { /** * Start the consumer - * - * @throws MQClientException */ void start() throws MQClientException; @@ -41,9 +39,6 @@ public interface MQPullConsumer extends MQConsumer { /** * Register the message queue listener - * - * @param topic - * @param listener */ void registerMessageQueueListener(final String topic, final MessageQueueListener listener); @@ -51,15 +46,12 @@ public interface MQPullConsumer extends MQConsumer { * Pulling the messages,not blocking * * @param mq from which message queue - * @param subExpression subscription expression.it only support or operation such as "tag1 || tag2 || tag3"
if null or * expression,meaning subscribe + * @param subExpression subscription expression.it only support or operation such as "tag1 || tag2 || tag3"
if + * null or * expression,meaning subscribe * all * @param offset from where to pull * @param maxNums max pulling numbers * @return The resulting {@code PullRequest} - * @throws MQClientException - * @throws InterruptedException - * @throws MQBrokerException - * @throws RemotingException */ PullResult pull(final MessageQueue mq, final String subExpression, final long offset, final int maxNums) throws MQClientException, RemotingException, MQBrokerException, @@ -68,16 +60,7 @@ public interface MQPullConsumer extends MQConsumer { /** * Pulling the messages in the specified timeout * - * @param mq - * @param subExpression - * @param offset - * @param maxNums - * @param timeout * @return The resulting {@code PullRequest} - * @throws MQClientException - * @throws RemotingException - * @throws MQBrokerException - * @throws InterruptedException */ PullResult pull(final MessageQueue mq, final String subExpression, final long offset, final int maxNums, final long timeout) throws MQClientException, RemotingException, @@ -85,15 +68,6 @@ public interface MQPullConsumer extends MQConsumer { /** * Pulling the messages in a async. way - * - * @param mq - * @param subExpression - * @param offset - * @param maxNums - * @param pullCallback - * @throws MQClientException - * @throws RemotingException - * @throws InterruptedException */ void pull(final MessageQueue mq, final String subExpression, final long offset, final int maxNums, final PullCallback pullCallback) throws MQClientException, RemotingException, @@ -101,16 +75,6 @@ public interface MQPullConsumer extends MQConsumer { /** * Pulling the messages in a async. way - * - * @param mq - * @param subExpression - * @param offset - * @param maxNums - * @param pullCallback - * @param timeout - * @throws MQClientException - * @throws RemotingException - * @throws InterruptedException */ void pull(final MessageQueue mq, final String subExpression, final long offset, final int maxNums, final PullCallback pullCallback, long timeout) throws MQClientException, RemotingException, @@ -119,15 +83,7 @@ public interface MQPullConsumer extends MQConsumer { /** * Pulling the messages,if no message arrival,blocking some time * - * @param mq - * @param subExpression - * @param offset - * @param maxNums * @return The resulting {@code PullRequest} - * @throws MQClientException - * @throws RemotingException - * @throws MQBrokerException - * @throws InterruptedException */ PullResult pullBlockIfNotFound(final MessageQueue mq, final String subExpression, final long offset, final int maxNums) throws MQClientException, RemotingException, @@ -135,15 +91,6 @@ public interface MQPullConsumer extends MQConsumer { /** * Pulling the messages through callback function,if no message arrival,blocking. - * - * @param mq - * @param subExpression - * @param offset - * @param maxNums - * @param pullCallback - * @throws MQClientException - * @throws RemotingException - * @throws InterruptedException */ void pullBlockIfNotFound(final MessageQueue mq, final String subExpression, final long offset, final int maxNums, final PullCallback pullCallback) throws MQClientException, RemotingException, @@ -151,20 +98,13 @@ public interface MQPullConsumer extends MQConsumer { /** * Update the offset - * - * @param mq - * @param offset - * @throws MQClientException */ void updateConsumeOffset(final MessageQueue mq, final long offset) throws MQClientException; /** * Fetch the offset * - * @param mq - * @param fromStore * @return The fetched offset of given queue - * @throws MQClientException */ long fetchConsumeOffset(final MessageQueue mq, final boolean fromStore) throws MQClientException; @@ -173,22 +113,12 @@ public interface MQPullConsumer extends MQConsumer { * * @param topic message topic * @return message queue set - * @throws MQClientException */ Set fetchMessageQueuesInBalance(final String topic) throws MQClientException; /** * If consuming failure,message will be send back to the broker,and delay consuming in some time later.
* Mind! message can only be consumed in the same group. - * - * @param msg - * @param delayLevel - * @param brokerName - * @param consumerGroup - * @throws RemotingException - * @throws MQBrokerException - * @throws InterruptedException - * @throws MQClientException */ void sendMessageBack(MessageExt msg, int delayLevel, String brokerName, String consumerGroup) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/MQPushConsumer.java b/client/src/main/java/org/apache/rocketmq/client/consumer/MQPushConsumer.java index 9c6c1f17805ec9b2c1490304d9dffdbdfa3175b0..d56075c6097bddac6216e41796e4fb295b599722 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/MQPushConsumer.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/MQPushConsumer.java @@ -27,8 +27,6 @@ import org.apache.rocketmq.client.exception.MQClientException; public interface MQPushConsumer extends MQConsumer { /** * Start the consumer - * - * @throws MQClientException */ void start() throws MQClientException; @@ -39,8 +37,6 @@ public interface MQPushConsumer extends MQConsumer { /** * Register the message listener - * - * @param messageListener */ @Deprecated void registerMessageListener(MessageListener messageListener); @@ -52,22 +48,20 @@ public interface MQPushConsumer extends MQConsumer { /** * Subscribe some topic * - * @param topic - * @param subExpression subscription expression.it only support or operation such as "tag1 || tag2 || tag3"
if null or * expression,meaning subscribe + * @param subExpression subscription expression.it only support or operation such as "tag1 || tag2 || tag3"
if + * null or * expression,meaning subscribe * all - * @throws MQClientException */ void subscribe(final String topic, final String subExpression) throws MQClientException; /** * Subscribe some topic * - * @param topic * @param fullClassName full class name,must extend org.apache.rocketmq.common.filter. MessageFilter * @param filterClassSource class source code,used UTF-8 file encoding,must be responsible for your code safety - * @throws MQClientException */ - void subscribe(final String topic, final String fullClassName, final String filterClassSource) throws MQClientException; + void subscribe(final String topic, final String fullClassName, + final String filterClassSource) throws MQClientException; /** * Subscribe some topic with selector. @@ -84,9 +78,7 @@ public interface MQPushConsumer extends MQConsumer { * Choose SQL92: {@link MessageSelector#bySql(java.lang.String)} *

* - * @param topic * @param selector message selector({@link MessageSelector}), can be null. - * @throws MQClientException */ void subscribe(final String topic, final MessageSelector selector) throws MQClientException; @@ -99,8 +91,6 @@ public interface MQPushConsumer extends MQConsumer { /** * Update the consumer thread pool size Dynamically - * - * @param corePoolSize */ void updateCorePoolSize(int corePoolSize); diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/MessageSelector.java b/client/src/main/java/org/apache/rocketmq/client/consumer/MessageSelector.java index 35a5181fd96de3228ccbe4e82ea8cdfda9b52f06..03983413aa55ebbb490692b92e291b8e6b2ef092 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/MessageSelector.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/MessageSelector.java @@ -20,14 +20,13 @@ package org.apache.rocketmq.client.consumer; import org.apache.rocketmq.common.filter.ExpressionType; /** - * * Message selector: select message at server. *

- * Now, support: - *

  • Tag: {@link org.apache.rocketmq.common.filter.ExpressionType#TAG} - *
  • - *
  • SQL92: {@link org.apache.rocketmq.common.filter.ExpressionType#SQL92} - *
  • + * Now, support: + *
  • Tag: {@link org.apache.rocketmq.common.filter.ExpressionType#TAG} + *
  • + *
  • SQL92: {@link org.apache.rocketmq.common.filter.ExpressionType#SQL92} + *
  • *

    */ public class MessageSelector { @@ -51,7 +50,6 @@ public class MessageSelector { * Use SLQ92 to select message. * * @param sql if null or empty, will be treated as select all message. - * @return */ public static MessageSelector bySql(String sql) { return new MessageSelector(ExpressionType.SQL92, sql); @@ -61,7 +59,6 @@ public class MessageSelector { * Use tag to select message. * * @param tag if null or empty or "*", will be treated as select all message. - * @return */ public static MessageSelector byTag(String tag) { return new MessageSelector(ExpressionType.TAG, tag); diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListenerConcurrently.java b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListenerConcurrently.java index 4eef1a8ad9101bd51503b586ed4477853eec3be8..cb39d7e482cd1880026929f5840cc936a8055825 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListenerConcurrently.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListenerConcurrently.java @@ -24,10 +24,10 @@ import org.apache.rocketmq.common.message.MessageExt; */ public interface MessageListenerConcurrently extends MessageListener { /** - * It is not recommend to throw exception,rather than returning ConsumeConcurrentlyStatus.RECONSUME_LATER if consumption failure + * It is not recommend to throw exception,rather than returning ConsumeConcurrentlyStatus.RECONSUME_LATER if + * consumption failure * * @param msgs msgs.size() >= 1
    DefaultMQPushConsumer.consumeMessageBatchMaxSize=1,you can modify here - * @param context * @return The consume status */ ConsumeConcurrentlyStatus consumeMessage(final List msgs, diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListenerOrderly.java b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListenerOrderly.java index 74dbb45a8de4a6d81e8c2da92972fbb615c0427c..d148df5c674d7eada8caa564139f01823cfeb50a 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListenerOrderly.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/listener/MessageListenerOrderly.java @@ -20,14 +20,15 @@ import java.util.List; import org.apache.rocketmq.common.message.MessageExt; /** - * A MessageListenerConcurrently object is used to receive asynchronously delivered messages orderly.one queue,one thread + * A MessageListenerConcurrently object is used to receive asynchronously delivered messages orderly.one queue,one + * thread */ public interface MessageListenerOrderly extends MessageListener { /** - * It is not recommend to throw exception,rather than returning ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT if consumption failure + * It is not recommend to throw exception,rather than returning ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT + * if consumption failure * * @param msgs msgs.size() >= 1
    DefaultMQPushConsumer.consumeMessageBatchMaxSize=1,you can modify here - * @param context * @return The consume status */ ConsumeOrderlyStatus consumeMessage(final List msgs, diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueConsistentHash.java b/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueConsistentHash.java index 09d940a1cfaf59741210e59274ef5b66f005aad6..b00326e6fef7843fd3d44d52583acabd32dbc00f 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueConsistentHash.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueConsistentHash.java @@ -30,7 +30,7 @@ import org.slf4j.Logger; /** * Consistent Hashing queue algorithm */ -public class AllocateMessageQueueConsistentHash implements AllocateMessageQueueStrategy { +public class AllocateMessageQueueConsistentHash implements AllocateMessageQueueStrategy { private final Logger log = ClientLogger.getLog(); private final int virtualNodeCnt; @@ -41,7 +41,7 @@ public class AllocateMessageQueueConsistentHash implements AllocateMessageQueue } public AllocateMessageQueueConsistentHash(int virtualNodeCnt) { - this(virtualNodeCnt,null); + this(virtualNodeCnt, null); } public AllocateMessageQueueConsistentHash(int virtualNodeCnt, HashFunction customHashFunction) { @@ -75,7 +75,6 @@ public class AllocateMessageQueueConsistentHash implements AllocateMessageQueue return result; } - Collection cidNodes = new ArrayList(); for (String cid : cidAll) { cidNodes.add(new ClientNode(cid)); @@ -105,7 +104,6 @@ public class AllocateMessageQueueConsistentHash implements AllocateMessageQueue return "CONSISTENT_HASH"; } - private static class ClientNode implements Node { private final String clientID; @@ -119,6 +117,4 @@ public class AllocateMessageQueueConsistentHash implements AllocateMessageQueue } } - - } diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/store/LocalFileOffsetStore.java b/client/src/main/java/org/apache/rocketmq/client/consumer/store/LocalFileOffsetStore.java index d4b19b234b3074c8d582f02879077d2f2194a6cb..22ec674288c713c58dabbd705f988a51de801ed6 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/store/LocalFileOffsetStore.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/store/LocalFileOffsetStore.java @@ -52,9 +52,9 @@ public class LocalFileOffsetStore implements OffsetStore { public LocalFileOffsetStore(MQClientInstance mQClientFactory, String groupName) { this.mQClientFactory = mQClientFactory; this.groupName = groupName; - this.storePath = LOCAL_OFFSET_STORE_DIR + File.separator + // - this.mQClientFactory.getClientId() + File.separator + // - this.groupName + File.separator + // + this.storePath = LOCAL_OFFSET_STORE_DIR + File.separator + + this.mQClientFactory.getClientId() + File.separator + + this.groupName + File.separator + "offsets.json"; } @@ -217,8 +217,8 @@ public class LocalFileOffsetStore implements OffsetStore { OffsetSerializeWrapper.fromJson(content, OffsetSerializeWrapper.class); } catch (Exception e) { log.warn("readLocalOffset Exception", e); - throw new MQClientException("readLocalOffset Exception, maybe fastjson version too low" // - + FAQUrl.suggestTodo(FAQUrl.LOAD_JSON_EXCEPTION), // + throw new MQClientException("readLocalOffset Exception, maybe fastjson version too low" + + FAQUrl.suggestTodo(FAQUrl.LOAD_JSON_EXCEPTION), e); } return offsetSerializeWrapper; diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/store/OffsetStore.java b/client/src/main/java/org/apache/rocketmq/client/consumer/store/OffsetStore.java index af745fcb87cfad10cd47a6e89e525d1105bda910..9deed0e3dfe8b400ef4aafa77523bcd70ffee833 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/store/OffsetStore.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/store/OffsetStore.java @@ -29,52 +29,37 @@ import org.apache.rocketmq.remoting.exception.RemotingException; public interface OffsetStore { /** * Load - * - * @throws MQClientException */ void load() throws MQClientException; /** * Update the offset,store it in memory - * - * @param mq - * @param offset - * @param increaseOnly */ void updateOffset(final MessageQueue mq, final long offset, final boolean increaseOnly); /** * Get offset from local storage * - * @param mq - * @param type * @return The fetched offset */ long readOffset(final MessageQueue mq, final ReadOffsetType type); /** * Persist all offsets,may be in local storage or remote name server - * - * @param mqs */ void persistAll(final Set mqs); /** * Persist the offset,may be in local storage or remote name server - * - * @param mq */ void persist(final MessageQueue mq); /** * Remove offset - * - * @param mq */ void removeOffset(MessageQueue mq); /** - * @param topic * @return The cloned offset table of given topic */ Map cloneOffsetTable(String topic); 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 5bd5749ea093d2fde9c7f78dbc3321b8a4e4d642..b82e992875e2914ffe961f97c451f34a4ffcaa66 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 @@ -204,7 +204,7 @@ public class RemoteBrokerOffsetStore implements OffsetStore { MQBrokerException, InterruptedException, MQClientException { FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName()); if (null == findBrokerResult) { - // TODO Here may be heavily overhead for Name Server,need tuning + this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic()); findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName()); } @@ -232,7 +232,7 @@ public class RemoteBrokerOffsetStore implements OffsetStore { InterruptedException, MQClientException { FindBrokerResult findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName()); if (null == findBrokerResult) { - // TODO Here may be heavily overhead for Name Server,need tuning + this.mQClientFactory.updateTopicRouteInfoFromNameServer(mq.getTopic()); findBrokerResult = this.mQClientFactory.findBrokerAddressInAdmin(mq.getBrokerName()); } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/ClientRemotingProcessor.java b/client/src/main/java/org/apache/rocketmq/client/impl/ClientRemotingProcessor.java index 2aadc896321838571eb5240f3c063e5aeb8d7861..69478cf328710766c6900c9454efc08a82a10c5c 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/ClientRemotingProcessor.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/ClientRemotingProcessor.java @@ -55,7 +55,8 @@ public class ClientRemotingProcessor implements NettyRequestProcessor { } @Override - public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand processRequest(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { switch (request.getCode()) { case RequestCode.CHECK_TRANSACTION_STATE: return this.checkTransactionState(ctx, request); @@ -82,7 +83,8 @@ public class ClientRemotingProcessor implements NettyRequestProcessor { return false; } - public RemotingCommand checkTransactionState(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand checkTransactionState(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final CheckTransactionStateRequestHeader requestHeader = (CheckTransactionStateRequestHeader) request.decodeCommandCustomHeader(CheckTransactionStateRequestHeader.class); final ByteBuffer byteBuffer = ByteBuffer.wrap(request.getBody()); @@ -107,7 +109,8 @@ public class ClientRemotingProcessor implements NettyRequestProcessor { return null; } - public RemotingCommand notifyConsumerIdsChanged(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand notifyConsumerIdsChanged(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { try { final NotifyConsumerIdsChangedRequestHeader requestHeader = (NotifyConsumerIdsChangedRequestHeader) request.decodeCommandCustomHeader(NotifyConsumerIdsChangedRequestHeader.class); @@ -121,12 +124,13 @@ public class ClientRemotingProcessor implements NettyRequestProcessor { return null; } - public RemotingCommand resetOffset(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand resetOffset(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final ResetOffsetRequestHeader requestHeader = (ResetOffsetRequestHeader) request.decodeCommandCustomHeader(ResetOffsetRequestHeader.class); log.info("invoke reset offset operation from broker. brokerAddr={}, topic={}, group={}, timestamp={}", - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), requestHeader.getGroup(), - requestHeader.getTimestamp()); + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), requestHeader.getTopic(), requestHeader.getGroup(), + requestHeader.getTimestamp()); Map offsetTable = new HashMap(); if (request.getBody() != null) { ResetOffsetBody body = ResetOffsetBody.decode(request.getBody(), ResetOffsetBody.class); @@ -137,7 +141,8 @@ public class ClientRemotingProcessor implements NettyRequestProcessor { } @Deprecated - public RemotingCommand getConsumeStatus(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand getConsumeStatus(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumerStatusRequestHeader requestHeader = (GetConsumerStatusRequestHeader) request.decodeCommandCustomHeader(GetConsumerStatusRequestHeader.class); @@ -150,7 +155,8 @@ public class ClientRemotingProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand getConsumerRunningInfo(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetConsumerRunningInfoRequestHeader requestHeader = (GetConsumerRunningInfoRequestHeader) request.decodeCommandCustomHeader(GetConsumerRunningInfoRequestHeader.class); @@ -173,7 +179,8 @@ public class ClientRemotingProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand consumeMessageDirectly(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final ConsumeMessageDirectlyResultRequestHeader requestHeader = (ConsumeMessageDirectlyResultRequestHeader) request diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/MQAdminImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/MQAdminImpl.java index 983e5157ea9491d587b77917849ead29eae2c4a4..b582b81e00dcbe6cb0f0609b2dff2651a74255ad 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/MQAdminImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/MQAdminImpl.java @@ -159,7 +159,7 @@ public class MQAdminImpl { } } catch (Exception e) { throw new MQClientException( - "Can not find Message Queue for this topic, " + topic + FAQUrl.suggestTodo(FAQUrl.MQLIST_NOT_EXIST), // + "Can not find Message Queue for this topic, " + topic + FAQUrl.suggestTodo(FAQUrl.MQLIST_NOT_EXIST), e); } @@ -240,7 +240,8 @@ public class MQAdminImpl { throw new MQClientException("The broker[" + mq.getBrokerName() + "] not exist", null); } - public MessageExt viewMessage(String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + public MessageExt viewMessage( + String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { MessageId messageId = null; try { @@ -252,12 +253,14 @@ public class MQAdminImpl { messageId.getOffset(), timeoutMillis); } - public QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end) throws MQClientException, + public QueryResult queryMessage(String topic, String key, int maxNum, long begin, + long end) throws MQClientException, InterruptedException { return queryMessage(topic, key, maxNum, begin, end, false); } - public MessageExt queryMessageByUniqKey(String topic, String uniqKey) throws InterruptedException, MQClientException { + public MessageExt queryMessageByUniqKey(String topic, + String uniqKey) throws InterruptedException, MQClientException { QueryResult qr = this.queryMessage(topic, uniqKey, 32, MessageClientIDSetter.getNearlyTimeFromID(uniqKey).getTime() - 1000, Long.MAX_VALUE, true); @@ -268,7 +271,8 @@ public class MQAdminImpl { } } - protected QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end, boolean isUniqKey) throws MQClientException, + protected QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end, + boolean isUniqKey) throws MQClientException, InterruptedException { TopicRouteData topicRouteData = this.mQClientFactory.getAnExistTopicRouteData(topic); if (null == topicRouteData) { diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java index 4244bddcf2f2a1edf3b196c5fb9026180bf6d123..c5abc36bf6706a1a92c433225de8795060d61bca 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/MQClientAPIImpl.java @@ -18,14 +18,14 @@ package org.apache.rocketmq.client.impl; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; -import java.util.Iterator; -import java.util.Collections; -import java.util.ArrayList; -import java.util.HashMap; import java.util.concurrent.atomic.AtomicInteger; import org.apache.rocketmq.client.ClientConfig; import org.apache.rocketmq.client.consumer.PullCallback; @@ -49,12 +49,12 @@ import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.admin.ConsumeStats; import org.apache.rocketmq.common.admin.TopicStatsTable; import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.common.message.MessageBatch; import org.apache.rocketmq.common.message.MessageClientIDSetter; -import org.apache.rocketmq.common.message.MessageExt; -import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.message.MessageConst; import org.apache.rocketmq.common.message.MessageDecoder; -import org.apache.rocketmq.common.message.MessageBatch; +import org.apache.rocketmq.common.message.MessageExt; +import org.apache.rocketmq.common.message.MessageQueue; import org.apache.rocketmq.common.namesrv.TopAddressing; import org.apache.rocketmq.common.protocol.RequestCode; import org.apache.rocketmq.common.protocol.ResponseCode; @@ -152,7 +152,6 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.apache.rocketmq.remoting.protocol.RemotingSerializable; import org.slf4j.Logger; - public class MQClientAPIImpl { private final static Logger log = ClientLogger.getLog(); @@ -169,7 +168,8 @@ public class MQClientAPIImpl { private String nameSrvAddr = null; private ClientConfig clientConfig; - public MQClientAPIImpl(final NettyClientConfig nettyClientConfig, final ClientRemotingProcessor clientRemotingProcessor, + public MQClientAPIImpl(final NettyClientConfig nettyClientConfig, + final ClientRemotingProcessor clientRemotingProcessor, RPCHook rpcHook, final ClientConfig clientConfig) { this.clientConfig = clientConfig; topAddressing = new TopAddressing(MixAll.getWSAddr(), clientConfig.getUnitName()); @@ -233,7 +233,8 @@ public class MQClientAPIImpl { this.remotingClient.shutdown(); } - public void createSubscriptionGroup(final String addr, final SubscriptionGroupConfig config, final long timeoutMillis) + public void createSubscriptionGroup(final String addr, final SubscriptionGroupConfig config, + final long timeoutMillis) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UPDATE_AND_CREATE_SUBSCRIPTIONGROUP, null); @@ -255,7 +256,8 @@ public class MQClientAPIImpl { } - public void createTopic(final String addr, final String defaultTopic, final TopicConfig topicConfig, final long timeoutMillis) + public void createTopic(final String addr, final String defaultTopic, final TopicConfig topicConfig, + final long timeoutMillis) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { CreateTopicRequestHeader requestHeader = new CreateTopicRequestHeader(); requestHeader.setTopic(topicConfig.getTopicName()); @@ -283,32 +285,32 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public SendResult sendMessage(// - final String addr, // 1 - final String brokerName, // 2 - final Message msg, // 3 - final SendMessageRequestHeader requestHeader, // 4 - final long timeoutMillis, // 5 - final CommunicationMode communicationMode, // 6 - final SendMessageContext context, // 7 - final DefaultMQProducerImpl producer // 8 + public SendResult sendMessage( + final String addr, + final String brokerName, + final Message msg, + final SendMessageRequestHeader requestHeader, + final long timeoutMillis, + final CommunicationMode communicationMode, + final SendMessageContext context, + final DefaultMQProducerImpl producer ) throws RemotingException, MQBrokerException, InterruptedException { return sendMessage(addr, brokerName, msg, requestHeader, timeoutMillis, communicationMode, null, null, null, 0, context, producer); } - public SendResult sendMessage(// - final String addr, // 1 - final String brokerName, // 2 - final Message msg, // 3 - final SendMessageRequestHeader requestHeader, // 4 - final long timeoutMillis, // 5 - final CommunicationMode communicationMode, // 6 - final SendCallback sendCallback, // 7 - final TopicPublishInfo topicPublishInfo, // 8 - final MQClientInstance instance, // 9 - final int retryTimesWhenSendFailed, // 10 - final SendMessageContext context, // 11 - final DefaultMQProducerImpl producer // 12 + public SendResult sendMessage( + final String addr, + final String brokerName, + final Message msg, + final SendMessageRequestHeader requestHeader, + final long timeoutMillis, + final CommunicationMode communicationMode, + final SendCallback sendCallback, + final TopicPublishInfo topicPublishInfo, + final MQClientInstance instance, + final int retryTimesWhenSendFailed, + final SendMessageContext context, + final DefaultMQProducerImpl producer ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = null; if (sendSmartMsg || msg instanceof MessageBatch) { @@ -339,31 +341,31 @@ public class MQClientAPIImpl { return null; } - private SendResult sendMessageSync(// - final String addr, // - final String brokerName, // - final Message msg, // - final long timeoutMillis, // - final RemotingCommand request// + private SendResult sendMessageSync( + final String addr, + final String brokerName, + final Message msg, + final long timeoutMillis, + final RemotingCommand request ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); assert response != null; return this.processSendResponse(brokerName, msg, response); } - private void sendMessageAsync(// - final String addr, // - final String brokerName, // - final Message msg, // - final long timeoutMillis, // - final RemotingCommand request, // - final SendCallback sendCallback, // - final TopicPublishInfo topicPublishInfo, // - final MQClientInstance instance, // - final int retryTimesWhenSendFailed, // - final AtomicInteger times, // - final SendMessageContext context, // - final DefaultMQProducerImpl producer // + private void sendMessageAsync( + final String addr, + final String brokerName, + final Message msg, + final long timeoutMillis, + final RemotingCommand request, + final SendCallback sendCallback, + final TopicPublishInfo topicPublishInfo, + final MQClientInstance instance, + final int retryTimesWhenSendFailed, + final AtomicInteger times, + final SendMessageContext context, + final DefaultMQProducerImpl producer ) throws InterruptedException, RemotingException { this.remotingClient.invokeAsync(addr, request, timeoutMillis, new InvokeCallback() { @Override @@ -378,7 +380,6 @@ public class MQClientAPIImpl { context.getProducer().executeSendMessageHookAfter(context); } } catch (Throwable e) { - // } producer.updateFaultItem(brokerName, System.currentTimeMillis() - responseFuture.getBeginTimestamp(), false); @@ -426,19 +427,19 @@ public class MQClientAPIImpl { }); } - private void onExceptionImpl(final String brokerName, // - final Message msg, // - final long timeoutMillis, // - final RemotingCommand request, // - final SendCallback sendCallback, // - final TopicPublishInfo topicPublishInfo, // - final MQClientInstance instance, // - final int timesTotal, // - final AtomicInteger curTimes, // - final Exception e, // - final SendMessageContext context, // - final boolean needRetry, // - final DefaultMQProducerImpl producer // 12 + private void onExceptionImpl(final String brokerName, + final Message msg, + final long timeoutMillis, + final RemotingCommand request, + final SendCallback sendCallback, + final TopicPublishInfo topicPublishInfo, + final MQClientInstance instance, + final int timesTotal, + final AtomicInteger curTimes, + final Exception e, + final SendMessageContext context, + final boolean needRetry, + final DefaultMQProducerImpl producer ) { int tmp = curTimes.incrementAndGet(); if (needRetry && tmp <= timesTotal) { @@ -483,16 +484,15 @@ public class MQClientAPIImpl { } } - private SendResult processSendResponse(// - final String brokerName, // - final Message msg, // - final RemotingCommand response// + private SendResult processSendResponse( + final String brokerName, + final Message msg, + final RemotingCommand response ) throws MQBrokerException, RemotingCommandException { switch (response.getCode()) { case ResponseCode.FLUSH_DISK_TIMEOUT: case ResponseCode.FLUSH_SLAVE_TIMEOUT: case ResponseCode.SLAVE_NOT_AVAILABLE: { - // TODO LOG } case ResponseCode.SUCCESS: { SendStatus sendStatus = SendStatus.SEND_OK; @@ -551,12 +551,12 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public PullResult pullMessage(// - final String addr, // - final PullMessageRequestHeader requestHeader, // - final long timeoutMillis, // - final CommunicationMode communicationMode, // - final PullCallback pullCallback// + public PullResult pullMessage( + final String addr, + final PullMessageRequestHeader requestHeader, + final long timeoutMillis, + final CommunicationMode communicationMode, + final PullCallback pullCallback ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.PULL_MESSAGE, requestHeader); @@ -577,11 +577,11 @@ public class MQClientAPIImpl { return null; } - private void pullMessageAsync(// - final String addr, // 1 - final RemotingCommand request, // - final long timeoutMillis, // - final PullCallback pullCallback// + private void pullMessageAsync( + final String addr, + final RemotingCommand request, + final long timeoutMillis, + final PullCallback pullCallback ) throws RemotingException, InterruptedException { this.remotingClient.invokeAsync(addr, request, timeoutMillis, new InvokeCallback() { @Override @@ -609,17 +609,18 @@ public class MQClientAPIImpl { }); } - private PullResult pullMessageSync(// - final String addr, // 1 - final RemotingCommand request, // 2 - final long timeoutMillis// 3 + private PullResult pullMessageSync( + final String addr, + final RemotingCommand request, + final long timeoutMillis ) throws RemotingException, InterruptedException, MQBrokerException { RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis); assert response != null; return this.processPullResponse(response); } - private PullResult processPullResponse(final RemotingCommand response) throws MQBrokerException, RemotingCommandException { + private PullResult processPullResponse( + final RemotingCommand response) throws MQBrokerException, RemotingCommandException { PullStatus pullStatus = PullStatus.NO_NEW_MSG; switch (response.getCode()) { case ResponseCode.SUCCESS: @@ -668,7 +669,8 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public long searchOffset(final String addr, final String topic, final int queueId, final long timestamp, final long timeoutMillis) + public long searchOffset(final String addr, final String topic, final int queueId, final long timestamp, + final long timeoutMillis) throws RemotingException, MQBrokerException, InterruptedException { SearchOffsetRequestHeader requestHeader = new SearchOffsetRequestHeader(); requestHeader.setTopic(topic); @@ -716,9 +718,9 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public List getConsumerIdListByGroup(// - final String addr, // - final String consumerGroup, // + public List getConsumerIdListByGroup( + final String addr, + final String consumerGroup, final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQBrokerException, InterruptedException { GetConsumerListByGroupRequestHeader requestHeader = new GetConsumerListByGroupRequestHeader(); @@ -767,7 +769,8 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public long getEarliestMsgStoretime(final String addr, final String topic, final int queueId, final long timeoutMillis) + public long getEarliestMsgStoretime(final String addr, final String topic, final int queueId, + final long timeoutMillis) throws RemotingException, MQBrokerException, InterruptedException { GetEarliestMsgStoretimeRequestHeader requestHeader = new GetEarliestMsgStoretimeRequestHeader(); requestHeader.setTopic(topic); @@ -791,10 +794,10 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public long queryConsumerOffset(// - final String addr, // - final QueryConsumerOffsetRequestHeader requestHeader, // - final long timeoutMillis// + public long queryConsumerOffset( + final String addr, + final QueryConsumerOffsetRequestHeader requestHeader, + final long timeoutMillis ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.QUERY_CONSUMER_OFFSET, requestHeader); @@ -815,10 +818,10 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public void updateConsumerOffset(// - final String addr, // - final UpdateConsumerOffsetRequestHeader requestHeader, // - final long timeoutMillis// + public void updateConsumerOffset( + final String addr, + final UpdateConsumerOffsetRequestHeader requestHeader, + final long timeoutMillis ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UPDATE_CONSUMER_OFFSET, requestHeader); @@ -836,10 +839,10 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public void updateConsumerOffsetOneway(// - final String addr, // - final UpdateConsumerOffsetRequestHeader requestHeader, // - final long timeoutMillis// + public void updateConsumerOffsetOneway( + final String addr, + final UpdateConsumerOffsetRequestHeader requestHeader, + final long timeoutMillis ) throws RemotingConnectException, RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UPDATE_CONSUMER_OFFSET, requestHeader); @@ -847,10 +850,10 @@ public class MQClientAPIImpl { this.remotingClient.invokeOneway(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis); } - public int sendHearbeat(// - final String addr, // - final HeartbeatData heartbeatData, // - final long timeoutMillis// + public int sendHearbeat( + final String addr, + final HeartbeatData heartbeatData, + final long timeoutMillis ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.HEART_BEAT, null); @@ -868,12 +871,12 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public void unregisterClient(// - final String addr, // - final String clientID, // - final String producerGroup, // - final String consumerGroup, // - final long timeoutMillis// + public void unregisterClient( + final String addr, + final String clientID, + final String producerGroup, + final String consumerGroup, + final long timeoutMillis ) throws RemotingException, MQBrokerException, InterruptedException { final UnregisterClientRequestHeader requestHeader = new UnregisterClientRequestHeader(); requestHeader.setClientID(clientID); @@ -894,11 +897,11 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public void endTransactionOneway(// - final String addr, // - final EndTransactionRequestHeader requestHeader, // - final String remark, // - final long timeoutMillis// + public void endTransactionOneway( + final String addr, + final EndTransactionRequestHeader requestHeader, + final String remark, + final long timeoutMillis ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.END_TRANSACTION, requestHeader); @@ -960,9 +963,9 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public Set lockBatchMQ(// - final String addr, // - final LockBatchRequestBody requestBody, // + public Set lockBatchMQ( + final String addr, + final LockBatchRequestBody requestBody, final long timeoutMillis) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.LOCK_BATCH_MQ, null); @@ -982,11 +985,11 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public void unlockBatchMQ(// - final String addr, // - final UnlockBatchRequestBody requestBody, // - final long timeoutMillis, // - final boolean oneway// + public void unlockBatchMQ( + final String addr, + final UnlockBatchRequestBody requestBody, + final long timeoutMillis, + final boolean oneway ) throws RemotingException, MQBrokerException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.UNLOCK_BATCH_MQ, null); @@ -1009,7 +1012,8 @@ public class MQClientAPIImpl { } } - public TopicStatsTable getTopicStatsInfo(final String addr, final String topic, final long timeoutMillis) throws InterruptedException, + public TopicStatsTable getTopicStatsInfo(final String addr, final String topic, + final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { GetTopicStatsInfoRequestHeader requestHeader = new GetTopicStatsInfoRequestHeader(); requestHeader.setTopic(topic); @@ -1036,7 +1040,8 @@ public class MQClientAPIImpl { return getConsumeStats(addr, consumerGroup, null, timeoutMillis); } - public ConsumeStats getConsumeStats(final String addr, final String consumerGroup, final String topic, final long timeoutMillis) + public ConsumeStats getConsumeStats(final String addr, final String consumerGroup, final String topic, + final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { GetConsumeStatsRequestHeader requestHeader = new GetConsumeStatsRequestHeader(); @@ -1059,7 +1064,8 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public ProducerConnection getProducerConnectionList(final String addr, final String producerGroup, final long timeoutMillis) + public ProducerConnection getProducerConnectionList(final String addr, final String producerGroup, + final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { GetProducerConnectionListRequestHeader requestHeader = new GetProducerConnectionListRequestHeader(); @@ -1080,7 +1086,8 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public ConsumerConnection getConsumerConnectionList(final String addr, final String consumerGroup, final long timeoutMillis) + public ConsumerConnection getConsumerConnectionList(final String addr, final String consumerGroup, + final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { GetConsumerConnectionListRequestHeader requestHeader = new GetConsumerConnectionListRequestHeader(); @@ -1160,7 +1167,8 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public ClusterInfo getBrokerClusterInfo(final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, + public ClusterInfo getBrokerClusterInfo( + final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_CLUSTER_INFO, null); @@ -1179,33 +1187,18 @@ public class MQClientAPIImpl { public TopicRouteData getDefaultTopicRouteInfoFromNameServer(final String topic, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { - GetRouteInfoRequestHeader requestHeader = new GetRouteInfoRequestHeader(); - requestHeader.setTopic(topic); - - RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ROUTEINTO_BY_TOPIC, requestHeader); - RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis); - assert response != null; - switch (response.getCode()) { - case ResponseCode.TOPIC_NOT_EXIST: { - // TODO LOG - break; - } - case ResponseCode.SUCCESS: { - byte[] body = response.getBody(); - if (body != null) { - return TopicRouteData.decode(body, TopicRouteData.class); - } - } - default: - break; - } - - throw new MQClientException(response.getCode(), response.getRemark()); + return getTopicRouteInfoFromNameServer(topic, timeoutMillis, false); } public TopicRouteData getTopicRouteInfoFromNameServer(final String topic, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { + + return getTopicRouteInfoFromNameServer(topic, timeoutMillis, true); + } + + public TopicRouteData getTopicRouteInfoFromNameServer(final String topic, final long timeoutMillis, + boolean allowTopicNotExist) throws MQClientException, InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException { GetRouteInfoRequestHeader requestHeader = new GetRouteInfoRequestHeader(); requestHeader.setTopic(topic); @@ -1215,8 +1208,10 @@ public class MQClientAPIImpl { assert response != null; switch (response.getCode()) { case ResponseCode.TOPIC_NOT_EXIST: { - if (!topic.equals(MixAll.DEFAULT_TOPIC)) + if (allowTopicNotExist && !topic.equals(MixAll.DEFAULT_TOPIC)) { log.warn("get Topic [{}] RouteInfoFromNameServer is not exist value", topic); + } + break; } case ResponseCode.SUCCESS: { @@ -1252,7 +1247,8 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public int wipeWritePermOfBroker(final String namesrvAddr, String brokerName, final long timeoutMillis) throws RemotingCommandException, + public int wipeWritePermOfBroker(final String namesrvAddr, String brokerName, + final long timeoutMillis) throws RemotingCommandException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQClientException { WipeWritePermOfBrokerRequestHeader requestHeader = new WipeWritePermOfBrokerRequestHeader(); requestHeader.setBrokerName(brokerName); @@ -1471,8 +1467,10 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public Map> invokeBrokerToGetConsumerStatus(final String addr, final String topic, final String group, - final String clientAddr, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { + public Map> invokeBrokerToGetConsumerStatus(final String addr, final String topic, + final String group, + final String clientAddr, + final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { GetConsumerStatusRequestHeader requestHeader = new GetConsumerStatusRequestHeader(); requestHeader.setTopic(topic); requestHeader.setGroup(group); @@ -1519,7 +1517,8 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public List queryConsumeTimeSpan(final String addr, final String topic, final String group, final long timeoutMillis) + public List queryConsumeTimeSpan(final String addr, final String topic, final String group, + final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { QueryConsumeTimeSpanRequestHeader requestHeader = new QueryConsumeTimeSpanRequestHeader(); @@ -1565,12 +1564,12 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public void registerMessageFilterClass(final String addr, // - final String consumerGroup, // - final String topic, // - final String className, // - final int classCRC, // - final byte[] classBody, // + public void registerMessageFilterClass(final String addr, + final String consumerGroup, + final String topic, + final String className, + final int classCRC, + final byte[] classBody, final long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { RegisterMessageFilterClassRequestHeader requestHeader = new RegisterMessageFilterClassRequestHeader(); @@ -1593,7 +1592,8 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public TopicList getSystemTopicList(final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { + public TopicList getSystemTopicList( + final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_SYSTEM_TOPIC_LIST_FROM_NS, null); RemotingCommand response = this.remotingClient.invokeSync(null, request, timeoutMillis); @@ -1642,7 +1642,8 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public boolean cleanExpiredConsumeQueue(final String addr, long timeoutMillis) throws MQClientException, RemotingConnectException, + public boolean cleanExpiredConsumeQueue(final String addr, + long timeoutMillis) throws MQClientException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CLEAN_EXPIRED_CONSUMEQUEUE, null); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), @@ -1658,7 +1659,8 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public boolean cleanUnusedTopicByAddr(final String addr, long timeoutMillis) throws MQClientException, RemotingConnectException, + public boolean cleanUnusedTopicByAddr(final String addr, + long timeoutMillis) throws MQClientException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CLEAN_UNUSED_TOPIC, null); RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), @@ -1674,7 +1676,8 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public ConsumerRunningInfo getConsumerRunningInfo(final String addr, String consumerGroup, String clientId, boolean jstack, + public ConsumerRunningInfo getConsumerRunningInfo(final String addr, String consumerGroup, String clientId, + boolean jstack, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { GetConsumerRunningInfoRequestHeader requestHeader = new GetConsumerRunningInfoRequestHeader(); requestHeader.setConsumerGroup(consumerGroup); @@ -1701,10 +1704,10 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public ConsumeMessageDirectlyResult consumeMessageDirectly(final String addr, // - String consumerGroup, // - String clientId, // - String msgId, // + public ConsumeMessageDirectlyResult consumeMessageDirectly(final String addr, + String consumerGroup, + String clientId, + String msgId, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { ConsumeMessageDirectlyResultRequestHeader requestHeader = new ConsumeMessageDirectlyResultRequestHeader(); requestHeader.setConsumerGroup(consumerGroup); @@ -1731,7 +1734,8 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public Map queryCorrectionOffset(final String addr, final String topic, final String group, Set filterGroup, + public Map queryCorrectionOffset(final String addr, final String topic, final String group, + Set filterGroup, long timeoutMillis) throws MQClientException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException { QueryCorrectionOffsetHeader requestHeader = new QueryCorrectionOffsetHeader(); @@ -1854,7 +1858,8 @@ public class MQClientAPIImpl { } public void cloneGroupOffset(final String addr, final String srcGroup, final String destGroup, final String topic, - final boolean isOffline, final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { + final boolean isOffline, + final long timeoutMillis) throws RemotingException, MQClientException, InterruptedException { CloneGroupOffsetRequestHeader requestHeader = new CloneGroupOffsetRequestHeader(); requestHeader.setSrcGroup(srcGroup); requestHeader.setDestGroup(destGroup); @@ -1902,13 +1907,14 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public Set getClusterList(String topic, long timeoutMillis) throws MQClientException, RemotingConnectException, + public Set getClusterList(String topic, + long timeoutMillis) throws MQClientException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException { - // todo:jodie return Collections.EMPTY_SET; } - public ConsumeStatsList fetchConsumeStatsInBroker(String brokerAddr, boolean isOrder, long timeoutMillis) throws MQClientException, + public ConsumeStatsList fetchConsumeStatsInBroker(String brokerAddr, boolean isOrder, + long timeoutMillis) throws MQClientException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException { GetConsumeStatsInBrokerHeader requestHeader = new GetConsumeStatsInBrokerHeader(); requestHeader.setIsOrder(isOrder); @@ -1932,7 +1938,8 @@ public class MQClientAPIImpl { throw new MQClientException(response.getCode(), response.getRemark()); } - public SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr, long timeoutMillis) throws InterruptedException, + public SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr, + long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null); RemotingCommand response = this.remotingClient @@ -1948,7 +1955,8 @@ public class MQClientAPIImpl { throw new MQBrokerException(response.getCode(), response.getRemark()); } - public TopicConfigSerializeWrapper getAllTopicConfig(final String addr, long timeoutMillis) throws RemotingConnectException, + public TopicConfigSerializeWrapper getAllTopicConfig(final String addr, + long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_TOPIC_CONFIG, null); @@ -2028,9 +2036,10 @@ public class MQClientAPIImpl { return configMap; } - public QueryConsumeQueueResponseBody queryConsumeQueue(final String brokerAddr, final String topic, final int queueId, - final long index, final int count, final String consumerGroup, - final long timeoutMillis) throws InterruptedException, + public QueryConsumeQueueResponseBody queryConsumeQueue(final String brokerAddr, final String topic, + final int queueId, + final long index, final int count, final String consumerGroup, + final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQClientException { QueryConsumeQueueRequestHeader requestHeader = new QueryConsumeQueueRequestHeader(); @@ -2054,8 +2063,8 @@ public class MQClientAPIImpl { } public void checkClientInBroker(final String brokerAddr, final String consumerGroup, - final String clientId, final SubscriptionData subscriptionData, - final long timeoutMillis) + final String clientId, final SubscriptionData subscriptionData, + final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQClientException { RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.CHECK_CLIENT_CONFIG, null); diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageConcurrentlyService.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageConcurrentlyService.java index f566ed0fcca4781d0eb7cca0b62ad059d286cc0f..961e062bb548e075c46832b75a693b83701f1e38 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageConcurrentlyService.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageConcurrentlyService.java @@ -69,12 +69,12 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService this.consumerGroup = this.defaultMQPushConsumer.getConsumerGroup(); this.consumeRequestQueue = new LinkedBlockingQueue(); - this.consumeExecutor = new ThreadPoolExecutor(// - this.defaultMQPushConsumer.getConsumeThreadMin(), // - this.defaultMQPushConsumer.getConsumeThreadMax(), // - 1000 * 60, // - TimeUnit.MILLISECONDS, // - this.consumeRequestQueue, // + this.consumeExecutor = new ThreadPoolExecutor( + this.defaultMQPushConsumer.getConsumeThreadMin(), + this.defaultMQPushConsumer.getConsumeThreadMax(), + 1000 * 60, + TimeUnit.MILLISECONDS, + this.consumeRequestQueue, new ThreadFactoryImpl("ConsumeMessageThread_")); this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl("ConsumeMessageScheduledThread_")); @@ -100,8 +100,8 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService @Override public void updateCorePoolSize(int corePoolSize) { - if (corePoolSize > 0 // - && corePoolSize <= Short.MAX_VALUE // + if (corePoolSize > 0 + && corePoolSize <= Short.MAX_VALUE && corePoolSize < this.defaultMQPushConsumer.getConsumeThreadMax()) { this.consumeExecutor.setCorePoolSize(corePoolSize); } @@ -115,11 +115,10 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService // this.consumeExecutor.setCorePoolSize(this.consumeExecutor.getCorePoolSize() // + 1); // } - // // log.info("incCorePoolSize Concurrently from {} to {}, ConsumerGroup: - // {}", // - // corePoolSize,// - // this.consumeExecutor.getCorePoolSize(),// + // {}", + // corePoolSize, + // this.consumeExecutor.getCorePoolSize(), // this.consumerGroup); } @@ -131,11 +130,10 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService // this.consumeExecutor.setCorePoolSize(this.consumeExecutor.getCorePoolSize() // - 1); // } - // // log.info("decCorePoolSize Concurrently from {} to {}, ConsumerGroup: - // {}", // - // corePoolSize,// - // this.consumeExecutor.getCorePoolSize(),// + // {}", + // corePoolSize, + // this.consumeExecutor.getCorePoolSize(), // this.consumerGroup); } @@ -185,10 +183,10 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService result.setConsumeResult(CMResult.CR_THROW_EXCEPTION); result.setRemark(RemotingHelper.exceptionSimpleDesc(e)); - log.warn(String.format("consumeMessageDirectly exception: %s Group: %s Msgs: %s MQ: %s", // - RemotingHelper.exceptionSimpleDesc(e), // - ConsumeMessageConcurrentlyService.this.consumerGroup, // - msgs, // + log.warn(String.format("consumeMessageDirectly exception: %s Group: %s Msgs: %s MQ: %s", + RemotingHelper.exceptionSimpleDesc(e), + ConsumeMessageConcurrentlyService.this.consumerGroup, + msgs, mq), e); } @@ -200,10 +198,10 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService } @Override - public void submitConsumeRequest(// - final List msgs, // - final ProcessQueue processQueue, // - final MessageQueue messageQueue, // + public void submitConsumeRequest( + final List msgs, + final ProcessQueue processQueue, + final MessageQueue messageQueue, final boolean dispatchToConsume) { final int consumeBatchSize = this.defaultMQPushConsumer.getConsumeMessageBatchMaxSize(); if (msgs.size() <= consumeBatchSize) { @@ -258,10 +256,10 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService } } - public void processConsumeResult(// - final ConsumeConcurrentlyStatus status, // - final ConsumeConcurrentlyContext context, // - final ConsumeRequest consumeRequest// + public void processConsumeResult( + final ConsumeConcurrentlyStatus status, + final ConsumeConcurrentlyContext context, + final ConsumeRequest consumeRequest ) { int ackIndex = context.getAckIndex(); @@ -338,10 +336,10 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService return false; } - private void submitConsumeRequestLater(// - final List msgs, // - final ProcessQueue processQueue, // - final MessageQueue messageQueue// + private void submitConsumeRequestLater( + final List msgs, + final ProcessQueue processQueue, + final MessageQueue messageQueue ) { this.scheduledExecutorService.schedule(new Runnable() { @@ -353,7 +351,7 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService }, 5000, TimeUnit.MILLISECONDS); } - private void submitConsumeRequestLater(final ConsumeRequest consumeRequest// + private void submitConsumeRequestLater(final ConsumeRequest consumeRequest ) { this.scheduledExecutorService.schedule(new Runnable() { @@ -419,7 +417,7 @@ public class ConsumeMessageConcurrentlyService implements ConsumeMessageService status = listener.consumeMessage(Collections.unmodifiableList(msgs), context); } catch (Throwable e) { log.warn("consumeMessage exception: {} Group: {} Msgs: {} MQ: {}", - RemotingHelper.exceptionSimpleDesc(e), // + RemotingHelper.exceptionSimpleDesc(e), ConsumeMessageConcurrentlyService.this.consumerGroup, msgs, messageQueue); diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageOrderlyService.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageOrderlyService.java index 1fa474caa1d256920ee7aa2ff23ef87ef1a5990a..27b02da3bbcd4e0407f070605b3e76fad1ca1054 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageOrderlyService.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageOrderlyService.java @@ -62,7 +62,8 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { private final ScheduledExecutorService scheduledExecutorService; private volatile boolean stopped = false; - public ConsumeMessageOrderlyService(DefaultMQPushConsumerImpl defaultMQPushConsumerImpl, MessageListenerOrderly messageListener) { + public ConsumeMessageOrderlyService(DefaultMQPushConsumerImpl defaultMQPushConsumerImpl, + MessageListenerOrderly messageListener) { this.defaultMQPushConsumerImpl = defaultMQPushConsumerImpl; this.messageListener = messageListener; @@ -70,12 +71,12 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { this.consumerGroup = this.defaultMQPushConsumer.getConsumerGroup(); this.consumeRequestQueue = new LinkedBlockingQueue(); - this.consumeExecutor = new ThreadPoolExecutor(// - this.defaultMQPushConsumer.getConsumeThreadMin(), // - this.defaultMQPushConsumer.getConsumeThreadMax(), // - 1000 * 60, // - TimeUnit.MILLISECONDS, // - this.consumeRequestQueue, // + this.consumeExecutor = new ThreadPoolExecutor( + this.defaultMQPushConsumer.getConsumeThreadMin(), + this.defaultMQPushConsumer.getConsumeThreadMax(), + 1000 * 60, + TimeUnit.MILLISECONDS, + this.consumeRequestQueue, new ThreadFactoryImpl("ConsumeMessageThread_")); this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl("ConsumeMessageScheduledThread_")); @@ -107,8 +108,8 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { @Override public void updateCorePoolSize(int corePoolSize) { - if (corePoolSize > 0 // - && corePoolSize <= Short.MAX_VALUE // + if (corePoolSize > 0 + && corePoolSize <= Short.MAX_VALUE && corePoolSize < this.defaultMQPushConsumer.getConsumeThreadMax()) { this.consumeExecutor.setCorePoolSize(corePoolSize); } @@ -171,10 +172,10 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { result.setConsumeResult(CMResult.CR_THROW_EXCEPTION); result.setRemark(RemotingHelper.exceptionSimpleDesc(e)); - log.warn(String.format("consumeMessageDirectly exception: %s Group: %s Msgs: %s MQ: %s", // - RemotingHelper.exceptionSimpleDesc(e), // - ConsumeMessageOrderlyService.this.consumerGroup, // - msgs, // + log.warn(String.format("consumeMessageDirectly exception: %s Group: %s Msgs: %s MQ: %s", + RemotingHelper.exceptionSimpleDesc(e), + ConsumeMessageOrderlyService.this.consumerGroup, + msgs, mq), e); } @@ -187,10 +188,10 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { } @Override - public void submitConsumeRequest(// - final List msgs, // - final ProcessQueue processQueue, // - final MessageQueue messageQueue, // + public void submitConsumeRequest( + final List msgs, + final ProcessQueue processQueue, + final MessageQueue messageQueue, final boolean dispathToConsume) { if (dispathToConsume) { ConsumeRequest consumeRequest = new ConsumeRequest(processQueue, messageQueue); @@ -204,7 +205,8 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { } } - public void tryLockLaterAndReconsume(final MessageQueue mq, final ProcessQueue processQueue, final long delayMills) { + public void tryLockLaterAndReconsume(final MessageQueue mq, final ProcessQueue processQueue, + final long delayMills) { this.scheduledExecutorService.schedule(new Runnable() { @Override public void run() { @@ -226,10 +228,10 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { return false; } - private void submitConsumeRequestLater(// - final ProcessQueue processQueue, // - final MessageQueue messageQueue, // - final long suspendTimeMillis// + private void submitConsumeRequestLater( + final ProcessQueue processQueue, + final MessageQueue messageQueue, + final long suspendTimeMillis ) { long timeMillis = suspendTimeMillis; if (timeMillis == -1) { @@ -251,11 +253,11 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { }, timeMillis, TimeUnit.MILLISECONDS); } - public boolean processConsumeResult(// - final List msgs, // - final ConsumeOrderlyStatus status, // - final ConsumeOrderlyContext context, // - final ConsumeRequest consumeRequest// + public boolean processConsumeResult( + final List msgs, + final ConsumeOrderlyStatus status, + final ConsumeOrderlyContext context, + final ConsumeRequest consumeRequest ) { boolean continueConsume = true; long commitOffset = -1L; @@ -273,9 +275,9 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { this.getConsumerStatsManager().incConsumeFailedTPS(consumerGroup, consumeRequest.getMessageQueue().getTopic(), msgs.size()); if (checkReconsumeTimes(msgs)) { consumeRequest.getProcessQueue().makeMessageToCosumeAgain(msgs); - this.submitConsumeRequestLater(// - consumeRequest.getProcessQueue(), // - consumeRequest.getMessageQueue(), // + this.submitConsumeRequestLater( + consumeRequest.getProcessQueue(), + consumeRequest.getMessageQueue(), context.getSuspendCurrentQueueTimeMillis()); continueConsume = false; } else { @@ -295,9 +297,9 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { break; case ROLLBACK: consumeRequest.getProcessQueue().rollback(); - this.submitConsumeRequestLater(// - consumeRequest.getProcessQueue(), // - consumeRequest.getMessageQueue(), // + this.submitConsumeRequestLater( + consumeRequest.getProcessQueue(), + consumeRequest.getMessageQueue(), context.getSuspendCurrentQueueTimeMillis()); continueConsume = false; break; @@ -305,9 +307,9 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { this.getConsumerStatsManager().incConsumeFailedTPS(consumerGroup, consumeRequest.getMessageQueue().getTopic(), msgs.size()); if (checkReconsumeTimes(msgs)) { consumeRequest.getProcessQueue().makeMessageToCosumeAgain(msgs); - this.submitConsumeRequestLater(// - consumeRequest.getProcessQueue(), // - consumeRequest.getMessageQueue(), // + this.submitConsumeRequestLater( + consumeRequest.getProcessQueue(), + consumeRequest.getMessageQueue(), context.getSuspendCurrentQueueTimeMillis()); continueConsume = false; } @@ -468,22 +470,22 @@ public class ConsumeMessageOrderlyService implements ConsumeMessageService { status = messageListener.consumeMessage(Collections.unmodifiableList(msgs), context); } catch (Throwable e) { - log.warn("consumeMessage exception: {} Group: {} Msgs: {} MQ: {}", // - RemotingHelper.exceptionSimpleDesc(e), // - ConsumeMessageOrderlyService.this.consumerGroup, // - msgs, // + log.warn("consumeMessage exception: {} Group: {} Msgs: {} MQ: {}", + RemotingHelper.exceptionSimpleDesc(e), + ConsumeMessageOrderlyService.this.consumerGroup, + msgs, messageQueue); hasException = true; } finally { this.processQueue.getLockConsume().unlock(); } - if (null == status // - || ConsumeOrderlyStatus.ROLLBACK == status// + if (null == status + || ConsumeOrderlyStatus.ROLLBACK == status || ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT == status) { - log.warn("consumeMessage Orderly return not OK, Group: {} Msgs: {} MQ: {}", // - ConsumeMessageOrderlyService.this.consumerGroup, // - msgs, // + log.warn("consumeMessage Orderly return not OK, Group: {} Msgs: {} MQ: {}", + ConsumeMessageOrderlyService.this.consumerGroup, + msgs, messageQueue); } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageService.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageService.java index 8742191b59d534427a3d90ca33eea14686b8d4b9..0f6f3bb38af6d22e02044bdaa738d2a8d45c2e8c 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageService.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageService.java @@ -36,9 +36,9 @@ public interface ConsumeMessageService { ConsumeMessageDirectlyResult consumeMessageDirectly(final MessageExt msg, final String brokerName); - void submitConsumeRequest(// - final List msgs, // - final ProcessQueue processQueue, // - final MessageQueue messageQueue, // + void submitConsumeRequest( + final List msgs, + final ProcessQueue processQueue, + final MessageQueue messageQueue, final boolean dispathToConsume); } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java index 35ee16fe3b3a36f8cb02465ccf0a7cb85574d360..8640d2d6b526b900317a8820011f164bee6dedef 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java @@ -97,8 +97,8 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { private void makeSureStateOK() throws MQClientException { if (this.serviceState != ServiceState.RUNNING) { - throw new MQClientException("The consumer service state not OK, "// - + this.serviceState// + throw new MQClientException("The consumer service state not OK, " + + this.serviceState + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), null); } @@ -185,7 +185,7 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { SubscriptionData subscriptionData; try { - subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), // + subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), mq.getTopic(), subExpression); } catch (Exception e) { throw new MQClientException("parse subscription error", e); @@ -193,18 +193,18 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { long timeoutMillis = block ? this.defaultMQPullConsumer.getConsumerTimeoutMillisWhenSuspend() : timeout; - PullResult pullResult = this.pullAPIWrapper.pullKernelImpl(// - mq, // 1 - subscriptionData.getSubString(), // 2 - 0L, // 3 - offset, // 4 - maxNums, // 5 - sysFlag, // 6 - 0, // 7 - this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis(), // 8 - timeoutMillis, // 9 - CommunicationMode.SYNC, // 10 - null// 11 + PullResult pullResult = this.pullAPIWrapper.pullKernelImpl( + mq, + subscriptionData.getSubString(), + 0L, + offset, + maxNums, + sysFlag, + 0, + this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis(), + timeoutMillis, + CommunicationMode.SYNC, + null ); this.pullAPIWrapper.processPullResult(mq, pullResult, subscriptionData); if (!this.consumeMessageHookList.isEmpty()) { @@ -225,7 +225,7 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { public void subscriptionAutomatically(final String topic) { if (!this.rebalanceImpl.getSubscriptionInner().containsKey(topic)) { try { - SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), // + SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), topic, SubscriptionData.SUB_ALL); this.rebalanceImpl.subscriptionInner.putIfAbsent(topic, subscriptionData); } catch (Exception ignore) { @@ -372,13 +372,13 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { this.pullAsyncImpl(mq, subExpression, offset, maxNums, pullCallback, false, timeout); } - private void pullAsyncImpl(// - final MessageQueue mq, // - final String subExpression, // - final long offset, // - final int maxNums, // - final PullCallback pullCallback, // - final boolean block, // + private void pullAsyncImpl( + final MessageQueue mq, + final String subExpression, + final long offset, + final int maxNums, + final PullCallback pullCallback, + final boolean block, final long timeout) throws MQClientException, RemotingException, InterruptedException { this.makeSureStateOK(); @@ -405,7 +405,7 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { final SubscriptionData subscriptionData; try { - subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), // + subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), mq.getTopic(), subExpression); } catch (Exception e) { throw new MQClientException("parse subscription error", e); @@ -413,17 +413,17 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { long timeoutMillis = block ? this.defaultMQPullConsumer.getConsumerTimeoutMillisWhenSuspend() : timeout; - this.pullAPIWrapper.pullKernelImpl(// - mq, // 1 - subscriptionData.getSubString(), // 2 - 0L, // 3 - offset, // 4 - maxNums, // 5 - sysFlag, // 6 - 0, // 7 - this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis(), // 8 - timeoutMillis, // 9 - CommunicationMode.ASYNC, // 10 + this.pullAPIWrapper.pullKernelImpl( + mq, + subscriptionData.getSubString(), + 0L, + offset, + maxNums, + sysFlag, + 0, + this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis(), + timeoutMillis, + CommunicationMode.ASYNC, new PullCallback() { @Override @@ -551,8 +551,8 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { this.rebalanceImpl.setAllocateMessageQueueStrategy(this.defaultMQPullConsumer.getAllocateMessageQueueStrategy()); this.rebalanceImpl.setmQClientFactory(this.mQClientFactory); - this.pullAPIWrapper = new PullAPIWrapper(// - mQClientFactory, // + this.pullAPIWrapper = new PullAPIWrapper( + mQClientFactory, this.defaultMQPullConsumer.getConsumerGroup(), isUnitMode()); this.pullAPIWrapper.registerFilterMessageHook(filterMessageHookList); @@ -589,8 +589,8 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { case RUNNING: case START_FAILED: case SHUTDOWN_ALREADY: - throw new MQClientException("The PullConsumer service state not OK, maybe started once, "// - + this.serviceState// + throw new MQClientException("The PullConsumer service state not OK, maybe started once, " + + this.serviceState + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), null); default: @@ -606,42 +606,42 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { // consumerGroup if (null == this.defaultMQPullConsumer.getConsumerGroup()) { throw new MQClientException( - "consumerGroup is null" // - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), // + "consumerGroup is null" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null); } // consumerGroup if (this.defaultMQPullConsumer.getConsumerGroup().equals(MixAll.DEFAULT_CONSUMER_GROUP)) { throw new MQClientException( - "consumerGroup can not equal "// - + MixAll.DEFAULT_CONSUMER_GROUP // - + ", please specify another one."// - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), // + "consumerGroup can not equal " + + MixAll.DEFAULT_CONSUMER_GROUP + + ", please specify another one." + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null); } // messageModel if (null == this.defaultMQPullConsumer.getMessageModel()) { throw new MQClientException( - "messageModel is null" // - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), // + "messageModel is null" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null); } // allocateMessageQueueStrategy if (null == this.defaultMQPullConsumer.getAllocateMessageQueueStrategy()) { throw new MQClientException( - "allocateMessageQueueStrategy is null" // - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), // + "allocateMessageQueueStrategy is null" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null); } // allocateMessageQueueStrategy if (this.defaultMQPullConsumer.getConsumerTimeoutMillisWhenSuspend() < this.defaultMQPullConsumer.getBrokerSuspendMaxTimeMillis()) { throw new MQClientException( - "Long polling mode, the consumer consumerTimeoutMillisWhenSuspend must greater than brokerSuspendMaxTimeMillis" // - + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), // + "Long polling mode, the consumer consumerTimeoutMillisWhenSuspend must greater than brokerSuspendMaxTimeMillis" + + FAQUrl.suggestTodo(FAQUrl.CLIENT_PARAMETER_CHECK_URL), null); } } @@ -651,7 +651,7 @@ public class DefaultMQPullConsumerImpl implements MQConsumerInner { Set registerTopics = this.defaultMQPullConsumer.getRegisterTopics(); if (registerTopics != null) { for (final String topic : registerTopics) { - SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), // + SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPullConsumer.getConsumerGroup(), topic, SubscriptionData.SUB_ALL); this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData); } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPushConsumerImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPushConsumerImpl.java index 9bf34be8cdf3e9db713982f2edf40fd7c9b8e3b2..7eda7c1b51b23b6cb71a86c9f887a32f4ee9735f 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPushConsumerImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPushConsumerImpl.java @@ -297,10 +297,10 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { pullRequest.getMessageQueue().getTopic(), pullResult.getMsgFoundList().size()); boolean dispathToConsume = processQueue.putMessage(pullResult.getMsgFoundList()); - DefaultMQPushConsumerImpl.this.consumeMessageService.submitConsumeRequest(// - pullResult.getMsgFoundList(), // - processQueue, // - pullRequest.getMessageQueue(), // + DefaultMQPushConsumerImpl.this.consumeMessageService.submitConsumeRequest( + pullResult.getMsgFoundList(), + processQueue, + pullRequest.getMessageQueue(), dispathToConsume); if (DefaultMQPushConsumerImpl.this.defaultMQPushConsumer.getPullInterval() > 0) { @@ -311,12 +311,12 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { } } - if (pullResult.getNextBeginOffset() < prevRequestOffset// + if (pullResult.getNextBeginOffset() < prevRequestOffset || firstMsgOffset < prevRequestOffset) { log.warn( - "[BUG] pull message result maybe data wrong, nextBeginOffset: {} firstMsgOffset: {} prevRequestOffset: {}", // - pullResult.getNextBeginOffset(), // - firstMsgOffset, // + "[BUG] pull message result maybe data wrong, nextBeginOffset: {} firstMsgOffset: {} prevRequestOffset: {}", + pullResult.getNextBeginOffset(), + firstMsgOffset, prevRequestOffset); } @@ -336,7 +336,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { DefaultMQPushConsumerImpl.this.executePullRequestImmediately(pullRequest); break; case OFFSET_ILLEGAL: - log.warn("the pull request offset illegal, {} {}", // + log.warn("the pull request offset illegal, {} {}", pullRequest.toString(), pullResult.toString()); pullRequest.setNextOffset(pullResult.getNextBeginOffset()); @@ -396,26 +396,26 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { classFilter = sd.isClassFilterMode(); } - int sysFlag = PullSysFlag.buildSysFlag(// + int sysFlag = PullSysFlag.buildSysFlag( commitOffsetEnable, // commitOffset true, // suspend subExpression != null, // subscription classFilter // class filter ); try { - this.pullAPIWrapper.pullKernelImpl(// - pullRequest.getMessageQueue(), // 1 - subExpression, // 2 - subscriptionData.getExpressionType(), // 3 - subscriptionData.getSubVersion(), // 4 - pullRequest.getNextOffset(), // 5 - this.defaultMQPushConsumer.getPullBatchSize(), // 6 - sysFlag, // 7 - commitOffsetValue, // 8 - BROKER_SUSPEND_MAX_TIME_MILLIS, // 9 - CONSUMER_TIMEOUT_MILLIS_WHEN_SUSPEND, // 10 - CommunicationMode.ASYNC, // 11 - pullCallback // 12 + this.pullAPIWrapper.pullKernelImpl( + pullRequest.getMessageQueue(), + subExpression, + subscriptionData.getExpressionType(), + subscriptionData.getSubVersion(), + pullRequest.getNextOffset(), + this.defaultMQPushConsumer.getPullBatchSize(), + sysFlag, + commitOffsetValue, + BROKER_SUSPEND_MAX_TIME_MILLIS, + CONSUMER_TIMEOUT_MILLIS_WHEN_SUSPEND, + CommunicationMode.ASYNC, + pullCallback ); } catch (Exception e) { log.error("pullKernelImpl exception", e); @@ -425,8 +425,8 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { private void makeSureStateOK() throws MQClientException { if (this.serviceState != ServiceState.RUNNING) { - throw new MQClientException("The consumer service state not OK, "// - + this.serviceState// + throw new MQClientException("The consumer service state not OK, " + + this.serviceState + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), null); } @@ -608,8 +608,8 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { case RUNNING: case START_FAILED: case SHUTDOWN_ALREADY: - throw new MQClientException("The PushConsumer service state not OK, maybe started once, "// - + this.serviceState// + throw new MQClientException("The PushConsumer service state not OK, maybe started once, " + + this.serviceState + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), null); default: @@ -764,7 +764,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { for (final Map.Entry entry : sub.entrySet()) { final String topic = entry.getKey(); final String subString = entry.getValue(); - SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), // + SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), topic, subString); this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData); } @@ -779,7 +779,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { break; case CLUSTERING: final String retryTopic = MixAll.getRetryTopic(this.defaultMQPushConsumer.getConsumerGroup()); - SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), // + SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), retryTopic, SubscriptionData.SUB_ALL); this.rebalanceImpl.getSubscriptionInner().put(retryTopic, subscriptionData); break; @@ -811,7 +811,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { public void subscribe(String topic, String subExpression) throws MQClientException { try { - SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), // + SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), topic, subExpression); this.rebalanceImpl.getSubscriptionInner().put(topic, subscriptionData); if (this.mQClientFactory != null) { @@ -824,7 +824,7 @@ public class DefaultMQPushConsumerImpl implements MQConsumerInner { public void subscribe(String topic, String fullClassName, String filterClassSource) throws MQClientException { try { - SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), // + SubscriptionData subscriptionData = FilterAPI.buildSubscriptionData(this.defaultMQPushConsumer.getConsumerGroup(), topic, "*"); subscriptionData.setSubString(fullClassName); subscriptionData.setClassFilterMode(true); diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalanceImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalanceImpl.java index 634e0f0e51b61b5b23e98fcfdfb8286ae857d334..b555771c1418a921d800e49a2fcb7646f68fa61b 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalanceImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalanceImpl.java @@ -55,7 +55,8 @@ public abstract class RebalanceImpl { protected AllocateMessageQueueStrategy allocateMessageQueueStrategy; protected MQClientInstance mQClientFactory; - public RebalanceImpl(String consumerGroup, MessageModel messageModel, AllocateMessageQueueStrategy allocateMessageQueueStrategy, + public RebalanceImpl(String consumerGroup, MessageModel messageModel, + AllocateMessageQueueStrategy allocateMessageQueueStrategy, MQClientInstance mQClientFactory) { this.consumerGroup = consumerGroup; this.messageModel = messageModel; @@ -73,9 +74,9 @@ public abstract class RebalanceImpl { try { this.mQClientFactory.getMQClientAPIImpl().unlockBatchMQ(findBrokerResult.getBrokerAddr(), requestBody, 1000, oneway); - log.warn("unlock messageQueue. group:{}, clientId:{}, mq:{}", // - this.consumerGroup, // - this.mQClientFactory.getClientId(), // + log.warn("unlock messageQueue. group:{}, clientId:{}, mq:{}", + this.consumerGroup, + this.mQClientFactory.getClientId(), mq); } catch (Exception e) { log.error("unlockBatchMQ exception, " + mq, e); @@ -245,10 +246,10 @@ public abstract class RebalanceImpl { boolean changed = this.updateProcessQueueTableInRebalance(topic, mqSet, isOrder); if (changed) { this.messageQueueChanged(topic, mqSet, mqSet); - log.info("messageQueueChanged {} {} {} {}", // - consumerGroup, // - topic, // - mqSet, // + log.info("messageQueueChanged {} {} {} {}", + consumerGroup, + topic, + mqSet, mqSet); } } else { @@ -280,10 +281,10 @@ public abstract class RebalanceImpl { List allocateResult = null; try { - allocateResult = strategy.allocate(// - this.consumerGroup, // - this.mQClientFactory.getClientId(), // - mqAll, // + allocateResult = strategy.allocate( + this.consumerGroup, + this.mQClientFactory.getClientId(), + mqAll, cidAll); } catch (Throwable e) { log.error("AllocateMessageQueueStrategy.allocate Exception. allocateMessageQueueStrategyName={}", strategy.getName(), @@ -327,7 +328,8 @@ public abstract class RebalanceImpl { } } - private boolean updateProcessQueueTableInRebalance(final String topic, final Set mqSet, final boolean isOrder) { + private boolean updateProcessQueueTableInRebalance(final String topic, final Set mqSet, + final boolean isOrder) { boolean changed = false; Iterator> it = this.processQueueTable.entrySet().iterator(); @@ -400,7 +402,8 @@ public abstract class RebalanceImpl { return changed; } - public abstract void messageQueueChanged(final String topic, final Set mqAll, final Set mqDivided); + public abstract void messageQueueChanged(final String topic, final Set mqAll, + final Set mqDivided); public abstract boolean removeUnnecessaryMessageQueue(final MessageQueue mq, final ProcessQueue pq); diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePullImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePullImpl.java index 57bfe2b81ad71f8c745f199cfe12b8a952a168fe..9dd408c1d140ea4f7ce4aa31df5e5181c997b753 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePullImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePullImpl.java @@ -32,7 +32,8 @@ public class RebalancePullImpl extends RebalanceImpl { this(null, null, null, null, defaultMQPullConsumerImpl); } - public RebalancePullImpl(String consumerGroup, MessageModel messageModel, AllocateMessageQueueStrategy allocateMessageQueueStrategy, + public RebalancePullImpl(String consumerGroup, MessageModel messageModel, + AllocateMessageQueueStrategy allocateMessageQueueStrategy, MQClientInstance mQClientFactory, DefaultMQPullConsumerImpl defaultMQPullConsumerImpl) { super(consumerGroup, messageModel, allocateMessageQueueStrategy, mQClientFactory); this.defaultMQPullConsumerImpl = defaultMQPullConsumerImpl; diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePushImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePushImpl.java index 112bceeb81ed0fe25e9fbb9c92d8cec55ae8d602..39e025172d4f8333880de09b8d74596b04fc69c3 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePushImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalancePushImpl.java @@ -40,7 +40,8 @@ public class RebalancePushImpl extends RebalanceImpl { this(null, null, null, null, defaultMQPushConsumerImpl); } - public RebalancePushImpl(String consumerGroup, MessageModel messageModel, AllocateMessageQueueStrategy allocateMessageQueueStrategy, + public RebalancePushImpl(String consumerGroup, MessageModel messageModel, + AllocateMessageQueueStrategy allocateMessageQueueStrategy, MQClientInstance mQClientFactory, DefaultMQPushConsumerImpl defaultMQPushConsumerImpl) { super(consumerGroup, messageModel, allocateMessageQueueStrategy, mQClientFactory); this.defaultMQPushConsumerImpl = defaultMQPushConsumerImpl; @@ -74,8 +75,8 @@ public class RebalancePushImpl extends RebalanceImpl { pq.getLockConsume().unlock(); } } else { - log.warn("[WRONG]mq is consuming, so can not unlock it, {}. maybe hanged for a while, {}", // - mq, // + log.warn("[WRONG]mq is consuming, so can not unlock it, {}. maybe hanged for a while, {}", + mq, pq.getTryUnlockTimes()); pq.incTryUnlockTimes(); diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalanceService.java b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalanceService.java index c4d2951aba8bce0669d006382046ff3b77695d76..fab07cb36e0f0976ca08bf77cb92c4b5eb56ead2 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalanceService.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/consumer/RebalanceService.java @@ -21,9 +21,6 @@ import org.apache.rocketmq.client.log.ClientLogger; import org.apache.rocketmq.common.ServiceThread; import org.slf4j.Logger; -/** - * Rebalance Service - */ public class RebalanceService extends ServiceThread { private static long waitInterval = Long.parseLong(System.getProperty( diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/factory/MQClientInstance.java b/client/src/main/java/org/apache/rocketmq/client/impl/factory/MQClientInstance.java index f146be9bb5cfad6380b8e6544496a669ea2fa4d2..31c2c3cc3ae8c01e5375b389d1ff8420327ac112 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/factory/MQClientInstance.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/factory/MQClientInstance.java @@ -148,10 +148,10 @@ public class MQClientInstance { this.consumerStatsManager = new ConsumerStatsManager(this.scheduledExecutorService); - log.info("created a new client Instance, FactoryIndex: {} ClinetID: {} {} {}, serializeType={}", // - this.instanceIndex, // - this.clientId, // - this.clientConfig, // + log.info("created a new client Instance, FactoryIndex: {} ClinetID: {} {} {}, serializeType={}", + this.instanceIndex, + this.clientId, + this.clientConfig, MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION), RemotingCommand.getSerializeTypeConfigInThisServer()); } @@ -584,7 +584,8 @@ public class MQClientInstance { } } - public boolean updateTopicRouteInfoFromNameServer(final String topic, boolean isDefault, DefaultMQProducer defaultMQProducer) { + public boolean updateTopicRouteInfoFromNameServer(final String topic, boolean isDefault, + DefaultMQProducer defaultMQProducer) { try { if (this.lockNamesrv.tryLock(LOCK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { try { @@ -719,7 +720,8 @@ public class MQClientInstance { return false; } - private void uploadFilterClassToAllFilterServer(final String consumerGroup, final String fullClassName, final String topic, + private void uploadFilterClassToAllFilterServer(final String consumerGroup, final String fullClassName, + final String topic, final String filterClassSource) throws UnsupportedEncodingException { byte[] classBody = null; int classCRC = 0; @@ -727,13 +729,13 @@ public class MQClientInstance { classBody = filterClassSource.getBytes(MixAll.DEFAULT_CHARSET); classCRC = UtilAll.crc32(classBody); } catch (Exception e1) { - log.warn("uploadFilterClassToAllFilterServer Exception, ClassName: {} {}", // - fullClassName, // + log.warn("uploadFilterClassToAllFilterServer Exception, ClassName: {} {}", + fullClassName, RemotingHelper.exceptionSimpleDesc(e1)); } TopicRouteData topicRouteData = this.topicRouteTable.get(topic); - if (topicRouteData != null // + if (topicRouteData != null && topicRouteData.getFilterServerTable() != null && !topicRouteData.getFilterServerTable().isEmpty()) { Iterator>> it = topicRouteData.getFilterServerTable().entrySet().iterator(); while (it.hasNext()) { @@ -1006,10 +1008,10 @@ public class MQClientInstance { return null; } - public FindBrokerResult findBrokerAddressInSubscribe(// - final String brokerName, // - final long brokerId, // - final boolean onlyThisBroker// + public FindBrokerResult findBrokerAddressInSubscribe( + final String brokerName, + final long brokerId, + final boolean onlyThisBroker ) { String brokerAddr = null; boolean slave = false; @@ -1102,7 +1104,6 @@ public class MQClientInstance { try { TimeUnit.SECONDS.sleep(10); } catch (InterruptedException e) { - // } Iterator iterator = processQueueTable.keySet().iterator(); @@ -1171,8 +1172,8 @@ public class MQClientInstance { return topicRouteTable; } - public ConsumeMessageDirectlyResult consumeMessageDirectly(final MessageExt msg, // - final String consumerGroup, // + public ConsumeMessageDirectlyResult consumeMessageDirectly(final MessageExt msg, + final String consumerGroup, final String brokerName) { MQConsumerInner mqConsumerInner = this.consumerTable.get(consumerGroup); if (null != mqConsumerInner) { diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java b/client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java index 12f8a3679e50457f353f21c4bdda3674ad9729f3..db9e51241f15a4a0ee0f6f173b5e392054cb3ca3 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java @@ -116,11 +116,11 @@ public class DefaultMQProducerImpl implements MQProducerInner { public void initTransactionEnv() { TransactionMQProducer producer = (TransactionMQProducer) this.defaultMQProducer; this.checkRequestQueue = new LinkedBlockingQueue(producer.getCheckRequestHoldMax()); - this.checkExecutor = new ThreadPoolExecutor(// - producer.getCheckThreadPoolMinSize(), // - producer.getCheckThreadPoolMaxSize(), // - 1000 * 60, // - TimeUnit.MILLISECONDS, // + this.checkExecutor = new ThreadPoolExecutor( + producer.getCheckThreadPoolMinSize(), + producer.getCheckThreadPoolMaxSize(), + 1000 * 60, + TimeUnit.MILLISECONDS, this.checkRequestQueue); } @@ -172,8 +172,8 @@ public class DefaultMQProducerImpl implements MQProducerInner { case RUNNING: case START_FAILED: case SHUTDOWN_ALREADY: - throw new MQClientException("The producer service state not OK, maybe started once, "// - + this.serviceState// + throw new MQClientException("The producer service state not OK, maybe started once, " + + this.serviceState + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), null); default: @@ -248,7 +248,8 @@ public class DefaultMQProducerImpl implements MQProducerInner { } @Override - public void checkTransactionState(final String addr, final MessageExt msg, final CheckTransactionStateRequestHeader header) { + public void checkTransactionState(final String addr, final MessageExt msg, + final CheckTransactionStateRequestHeader header) { Runnable request = new Runnable() { private final String brokerAddr = addr; private final MessageExt message = msg; @@ -268,18 +269,18 @@ public class DefaultMQProducerImpl implements MQProducerInner { exception = e; } - this.processTransactionState(// - localTransactionState, // - group, // + this.processTransactionState( + localTransactionState, + group, exception); } else { log.warn("checkTransactionState, pick transactionCheckListener by group[{}] failed", group); } } - private void processTransactionState(// - final LocalTransactionState localTransactionState, // - final String producerGroup, // + private void processTransactionState( + final LocalTransactionState localTransactionState, + final String producerGroup, final Throwable exception) { final EndTransactionRequestHeader thisHeader = new EndTransactionRequestHeader(); thisHeader.setCommitLogOffset(checkRequestHeader.getCommitLogOffset()); @@ -354,8 +355,8 @@ public class DefaultMQProducerImpl implements MQProducerInner { private void makeSureStateOK() throws MQClientException { if (this.serviceState != ServiceState.RUNNING) { - throw new MQClientException("The producer service state not OK, "// - + this.serviceState// + throw new MQClientException("The producer service state not OK, " + + this.serviceState + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), null); } @@ -386,7 +387,8 @@ public class DefaultMQProducerImpl implements MQProducerInner { return this.mQClientFactory.getMQAdminImpl().earliestMsgStoreTime(mq); } - public MessageExt viewMessage(String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + public MessageExt viewMessage( + String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { this.makeSureStateOK(); return this.mQClientFactory.getMQAdminImpl().viewMessage(msgId); @@ -407,7 +409,8 @@ public class DefaultMQProducerImpl implements MQProducerInner { /** * DEFAULT ASYNC ------------------------------------------------------- */ - public void send(Message msg, SendCallback sendCallback) throws MQClientException, RemotingException, InterruptedException { + public void send(Message msg, + SendCallback sendCallback) throws MQClientException, RemotingException, InterruptedException { send(msg, sendCallback, this.defaultMQProducer.getSendMsgTimeout()); } @@ -428,11 +431,11 @@ public class DefaultMQProducerImpl implements MQProducerInner { this.mqFaultStrategy.updateFaultItem(brokerName, currentLatency, isolation); } - private SendResult sendDefaultImpl(// - Message msg, // - final CommunicationMode communicationMode, // - final SendCallback sendCallback, // - final long timeout// + private SendResult sendDefaultImpl( + Message msg, + final CommunicationMode communicationMode, + final SendCallback sendCallback, + final long timeout ) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { this.makeSureStateOK(); Validators.checkMessage(msg, this.defaultMQProducer); @@ -579,11 +582,11 @@ public class DefaultMQProducerImpl implements MQProducerInner { } } - private SendResult sendKernelImpl(final Message msg, // - final MessageQueue mq, // - final CommunicationMode communicationMode, // - final SendCallback sendCallback, // - final TopicPublishInfo topicPublishInfo, // + private SendResult sendKernelImpl(final Message msg, + final MessageQueue mq, + final CommunicationMode communicationMode, + final SendCallback sendCallback, + final TopicPublishInfo topicPublishInfo, final long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { String brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(mq.getBrokerName()); if (null == brokerAddr) { @@ -674,18 +677,18 @@ public class DefaultMQProducerImpl implements MQProducerInner { SendResult sendResult = null; switch (communicationMode) { case ASYNC: - sendResult = this.mQClientFactory.getMQClientAPIImpl().sendMessage(// - brokerAddr, // 1 - mq.getBrokerName(), // 2 - msg, // 3 - requestHeader, // 4 - timeout, // 5 - communicationMode, // 6 - sendCallback, // 7 - topicPublishInfo, // 8 - this.mQClientFactory, // 9 - this.defaultMQProducer.getRetryTimesWhenSendAsyncFailed(), // 10 - context, // + sendResult = this.mQClientFactory.getMQClientAPIImpl().sendMessage( + brokerAddr, + mq.getBrokerName(), + msg, + requestHeader, + timeout, + communicationMode, + sendCallback, + topicPublishInfo, + this.mQClientFactory, + this.defaultMQProducer.getRetryTimesWhenSendAsyncFailed(), + context, this); break; case ONEWAY: @@ -863,7 +866,8 @@ public class DefaultMQProducerImpl implements MQProducerInner { /** * KERNEL ONEWAY ------------------------------------------------------- */ - public void sendOneway(Message msg, MessageQueue mq) throws MQClientException, RemotingException, InterruptedException { + public void sendOneway(Message msg, + MessageQueue mq) throws MQClientException, RemotingException, InterruptedException { this.makeSureStateOK(); Validators.checkMessage(msg, this.defaultMQProducer); @@ -887,12 +891,12 @@ public class DefaultMQProducerImpl implements MQProducerInner { return this.sendSelectImpl(msg, selector, arg, CommunicationMode.SYNC, null, timeout); } - private SendResult sendSelectImpl(// - Message msg, // - MessageQueueSelector selector, // - Object arg, // - final CommunicationMode communicationMode, // - final SendCallback sendCallback, final long timeout// + private SendResult sendSelectImpl( + Message msg, + MessageQueueSelector selector, + Object arg, + final CommunicationMode communicationMode, + final SendCallback sendCallback, final long timeout ) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { this.makeSureStateOK(); Validators.checkMessage(msg, this.defaultMQProducer); @@ -945,7 +949,8 @@ public class DefaultMQProducerImpl implements MQProducerInner { } } - public TransactionSendResult sendMessageInTransaction(final Message msg, final LocalTransactionExecuter tranExecuter, final Object arg) + public TransactionSendResult sendMessageInTransaction(final Message msg, + final LocalTransactionExecuter tranExecuter, final Object arg) throws MQClientException { if (null == tranExecuter) { throw new MQClientException("tranExecutor is null", null); @@ -1013,13 +1018,14 @@ public class DefaultMQProducerImpl implements MQProducerInner { /** * DEFAULT SYNC ------------------------------------------------------- */ - public SendResult send(Message msg) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + public SendResult send( + Message msg) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return send(msg, this.defaultMQProducer.getSendMsgTimeout()); } - public void endTransaction(// - final SendResult sendResult, // - final LocalTransactionState localTransactionState, // + public void endTransaction( + final SendResult sendResult, + final LocalTransactionState localTransactionState, final Throwable localException) throws RemotingException, MQBrokerException, InterruptedException, UnknownHostException { final MessageId id; if (sendResult.getOffsetMsgId() != null) { @@ -1054,7 +1060,8 @@ public class DefaultMQProducerImpl implements MQProducerInner { this.defaultMQProducer.getSendMsgTimeout()); } - public SendResult send(Message msg, long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + public SendResult send(Message msg, + long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.sendDefaultImpl(msg, CommunicationMode.SYNC, null, timeout); } diff --git a/client/src/main/java/org/apache/rocketmq/client/impl/producer/MQProducerInner.java b/client/src/main/java/org/apache/rocketmq/client/impl/producer/MQProducerInner.java index 5b2039ec47edcdffa75da96a2c833b4b5a237b80..dfd485dd90909573eac012ff1e94f08f82d8e529 100644 --- a/client/src/main/java/org/apache/rocketmq/client/impl/producer/MQProducerInner.java +++ b/client/src/main/java/org/apache/rocketmq/client/impl/producer/MQProducerInner.java @@ -28,9 +28,9 @@ public interface MQProducerInner { TransactionCheckListener checkListener(); - void checkTransactionState(// - final String addr, // - final MessageExt msg, // + void checkTransactionState( + final String addr, + final MessageExt msg, final CheckTransactionStateRequestHeader checkRequestHeader); void updateTopicPublishInfo(final String topic, final TopicPublishInfo info); diff --git a/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java b/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java index 05d72b40ce08e43bd33d2903cab8c89f8a656514..c3df9a63947ffc927f67e65291b2641fde600054 100644 --- a/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java +++ b/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java @@ -16,14 +16,14 @@ */ package org.apache.rocketmq.client.log; -import java.lang.reflect.Method; -import java.net.URL; - import org.apache.rocketmq.common.constant.LoggerName; import org.slf4j.ILoggerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.lang.reflect.Method; +import java.net.URL; + public class ClientLogger { public static final String CLIENT_LOG_ROOT = "rocketmq.client.logRoot"; public static final String CLIENT_LOG_MAXINDEX = "rocketmq.client.logFileMaxIndex"; @@ -31,25 +31,21 @@ public class ClientLogger { private static Logger log; - private static Class logClass = null; - private static Logger createLogger(final String loggerName) { - String logConfigFilePath = - System.getProperty("rocketmq.client.log.configFile", - System.getenv("ROCKETMQ_CLIENT_LOG_CONFIGFILE")); + String logConfigFilePath = System.getProperty("rocketmq.client.log.configFile", System.getenv("ROCKETMQ_CLIENT_LOG_CONFIGFILE")); Boolean isloadconfig = - Boolean.parseBoolean(System.getProperty("rocketmq.client.log.loadconfig", "true")); + Boolean.parseBoolean(System.getProperty("rocketmq.client.log.loadconfig", "true")); final String log4JResourceFile = - System.getProperty("rocketmq.client.log4j.resource.fileName", "log4j_rocketmq_client.xml"); + System.getProperty("rocketmq.client.log4j.resource.fileName", "log4j_rocketmq_client.xml"); final String logbackResourceFile = - System.getProperty("rocketmq.client.logback.resource.fileName", "logback_rocketmq_client.xml"); + System.getProperty("rocketmq.client.logback.resource.fileName", "logback_rocketmq_client.xml"); final String log4J2ResourceFile = - System.getProperty("rocketmq.client.log4j2.resource.fileName", "log4j2_rocketmq_client.xml"); + System.getProperty("rocketmq.client.log4j2.resource.fileName", "log4j2_rocketmq_client.xml"); - String clientLogRoot = System.getProperty(CLIENT_LOG_ROOT, "${user.home}/logs/rocketmqlogs"); + String clientLogRoot = System.getProperty(CLIENT_LOG_ROOT, System.getProperty("user.home") + "/logs/rocketmqlogs"); System.setProperty("client.logRoot", clientLogRoot); String clientLogLevel = System.getProperty(CLIENT_LOG_LEVEL, "INFO"); System.setProperty("client.logLevel", clientLogLevel); @@ -85,11 +81,11 @@ public class ClientLogger { if (null == logConfigFilePath) { URL url = ClientLogger.class.getClassLoader().getResource(logbackResourceFile); Method doConfigure = - joranConfiguratoroObj.getClass().getMethod("doConfigure", URL.class); + joranConfiguratoroObj.getClass().getMethod("doConfigure", URL.class); doConfigure.invoke(joranConfiguratoroObj, url); } else { Method doConfigure = - joranConfiguratoroObj.getClass().getMethod("doConfigure", String.class); + joranConfiguratoroObj.getClass().getMethod("doConfigure", String.class); doConfigure.invoke(joranConfiguratoroObj, logConfigFilePath); } @@ -102,7 +98,6 @@ public class ClientLogger { initialize.invoke(joranConfigurator, "log4j2", logConfigFilePath); } } - logClass = classType; } catch (Exception e) { System.err.println(e); } diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java b/client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java index 135a447eba4ba0b5e0925da92431bc8a5c147d7f..d48686e3379507cc78f3608c7e08d08d38bc426a 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/DefaultMQProducer.java @@ -48,8 +48,8 @@ import org.apache.rocketmq.remoting.exception.RemotingException; *

    * *

    - * Thread Safety: After configuring and starting process, this class can be regarded as thread-safe - * and used among multiple threads context. + * Thread Safety: After configuring and starting process, this class can be regarded as thread-safe + * and used among multiple threads context. *

    */ public class DefaultMQProducer extends ClientConfig implements MQProducer { @@ -137,6 +137,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { /** * Constructor specifying producer group. + * * @param producerGroup Producer group, see the name-sake field. */ public DefaultMQProducer(final String producerGroup) { @@ -145,6 +146,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { /** * Constructor specifying the RPC hook. + * * @param rpcHook RPC hook to execute per each remoting command execution. */ public DefaultMQProducer(RPCHook rpcHook) { @@ -178,6 +180,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { /** * Fetch message queues of topic topic, to which we may send/publish messages. + * * @param topic Topic to fetch. * @return List of message queues readily to send messages to * @throws MQClientException if there is any client error. @@ -204,12 +207,14 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { * @throws InterruptedException if the sending thread is interrupted. */ @Override - public SendResult send(Message msg) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + public SendResult send( + Message msg) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.defaultMQProducerImpl.send(msg); } /** * Same to {@link #send(Message)} with send timeout specified in addition. + * * @param msg Message to send. * @param timeout send timeout. * @return {@link SendResult} instance to inform senders details of the deliverable, say Message ID of the message, @@ -220,7 +225,8 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { * @throws InterruptedException if the sending thread is interrupted. */ @Override - public SendResult send(Message msg, long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + public SendResult send(Message msg, + long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.defaultMQProducerImpl.send(msg, timeout); } @@ -234,6 +240,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { * Similar to {@link #send(Message)}, internal implementation would potentially retry up to * {@link #retryTimesWhenSendAsyncFailed} times before claiming sending failure, which may yield message duplication * and application developers are the one to resolve this potential issue. + * * @param msg Message to send. * @param sendCallback Callback to execute on sending completed, either successful or unsuccessful. * @throws MQClientException if there is any client error. @@ -241,12 +248,14 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { * @throws InterruptedException if the sending thread is interrupted. */ @Override - public void send(Message msg, SendCallback sendCallback) throws MQClientException, RemotingException, InterruptedException { + public void send(Message msg, + SendCallback sendCallback) throws MQClientException, RemotingException, InterruptedException { this.defaultMQProducerImpl.send(msg, sendCallback); } /** * Same to {@link #send(Message, SendCallback)} with send timeout specified in addition. + * * @param msg message to send. * @param sendCallback Callback to execute. * @param timeout send timeout. @@ -263,6 +272,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { /** * Similar to UDP, this method won't wait for * acknowledgement from broker before return. Obviously, it has maximums throughput yet potentials of message loss. + * * @param msg Message to send. * @throws MQClientException if there is any client error. * @throws RemotingException if there is any network-tier error. @@ -275,6 +285,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { /** * Same to {@link #send(Message)} with target message queue specified in addition. + * * @param msg Message to send. * @param mq Target message queue. * @return {@link SendResult} instance to inform senders details of the deliverable, say Message ID of the message, @@ -327,6 +338,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { /** * Same to {@link #send(Message, SendCallback)} with target message queue and send timeout specified. + * * @param msg Message to send. * @param mq Target message queue. * @param sendCallback Callback to execute on sending completed, either successful or unsuccessful. @@ -343,6 +355,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { /** * Same to {@link #sendOneway(Message)} with target message queue specified. + * * @param msg Message to send. * @param mq Target message queue. * @throws MQClientException if there is any client error. @@ -350,12 +363,13 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { * @throws InterruptedException if the sending thread is interrupted. */ @Override - public void sendOneway(Message msg, MessageQueue mq) throws MQClientException, RemotingException, InterruptedException { + public void sendOneway(Message msg, + MessageQueue mq) throws MQClientException, RemotingException, InterruptedException { this.defaultMQProducerImpl.sendOneway(msg, mq); } /** - * Same to {@link #send(Message)} with message queue selector specified. + * Same to {@link #send(Message)} with message queue selector specified. * * @param msg Message to send. * @param selector Message queue selector, through which we get target message queue to deliver message to. @@ -430,6 +444,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { /** * Same to {@link #sendOneway(Message)} with message queue selector specified. + * * @param msg Message to send. * @param selector Message queue selector, through which to determine target message queue to deliver message * @param arg Argument used along with message queue selector. @@ -453,13 +468,15 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { * @throws MQClientException if there is any client error. */ @Override - public TransactionSendResult sendMessageInTransaction(Message msg, LocalTransactionExecuter tranExecuter, final Object arg) + public TransactionSendResult sendMessageInTransaction(Message msg, LocalTransactionExecuter tranExecuter, + final Object arg) throws MQClientException { throw new RuntimeException("sendMessageInTransaction not implement, please use TransactionMQProducer class"); } /** * Create a topic on broker. + * * @param key accesskey * @param newTopic topic name * @param queueNum topic's queue number @@ -472,6 +489,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { /** * Create a topic on broker. + * * @param key accesskey * @param newTopic topic name * @param queueNum topic's queue number @@ -485,6 +503,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { /** * Search consume queue offset of the given time stamp. + * * @param mq Instance of MessageQueue * @param timestamp from when in milliseconds. * @return Consume queue offset. @@ -509,6 +528,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { /** * Query minimum offset of the given message queue. + * * @param mq Instance of MessageQueue * @return minimum offset of the given message queue. * @throws MQClientException if there is any client error. @@ -520,6 +540,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { /** * Query earliest message store time. + * * @param mq Instance of MessageQueue * @return earliest message store time. * @throws MQClientException if there is any client error. @@ -531,6 +552,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { /** * Query message of the given offset message ID. + * * @param offsetMsgId message id * @return Message specified. * @throws MQBrokerException if there is any broker error. @@ -539,12 +561,14 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { * @throws InterruptedException if the sending thread is interrupted. */ @Override - public MessageExt viewMessage(String offsetMsgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + public MessageExt viewMessage( + String offsetMsgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { return this.defaultMQProducerImpl.viewMessage(offsetMsgId); } /** * Query message by key. + * * @param topic message topic * @param key message key index word * @param maxNum max message number @@ -572,7 +596,8 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { * @throws InterruptedException if the sending thread is interrupted. */ @Override - public MessageExt viewMessage(String topic, String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + public MessageExt viewMessage(String topic, + String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { try { MessageId oldMsgId = MessageDecoder.decodeMessageId(msgId); return this.viewMessage(msgId); @@ -582,22 +607,26 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { } @Override - public SendResult send(Collection msgs) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + public SendResult send( + Collection msgs) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.defaultMQProducerImpl.send(batch(msgs)); } @Override - public SendResult send(Collection msgs, long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + public SendResult send(Collection msgs, + long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.defaultMQProducerImpl.send(batch(msgs), timeout); } @Override - public SendResult send(Collection msgs, MessageQueue messageQueue) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + public SendResult send(Collection msgs, + MessageQueue messageQueue) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.defaultMQProducerImpl.send(batch(msgs), messageQueue); } @Override - public SendResult send(Collection msgs, MessageQueue messageQueue, long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { + public SendResult send(Collection msgs, MessageQueue messageQueue, + long timeout) throws MQClientException, RemotingException, MQBrokerException, InterruptedException { return this.defaultMQProducerImpl.send(batch(msgs), messageQueue, timeout); } @@ -615,6 +644,7 @@ public class DefaultMQProducer extends ClientConfig implements MQProducer { } return msgBatch; } + public String getProducerGroup() { return producerGroup; } diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/LocalTransactionExecuter.java b/client/src/main/java/org/apache/rocketmq/client/producer/LocalTransactionExecuter.java index 0c22c3ea6b4f394b28ed19fad8ad812fb1f34a3c..80b5546925fee85484151985aee052107f59e49e 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/LocalTransactionExecuter.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/LocalTransactionExecuter.java @@ -19,5 +19,5 @@ package org.apache.rocketmq.client.producer; import org.apache.rocketmq.common.message.Message; public interface LocalTransactionExecuter { - public LocalTransactionState executeLocalTransactionBranch(final Message msg, final Object arg); + LocalTransactionState executeLocalTransactionBranch(final Message msg, final Object arg); } diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/SendCallback.java b/client/src/main/java/org/apache/rocketmq/client/producer/SendCallback.java index 1adf1834d91a1f5b4780469903222623deb1b38c..a85fa699c8fa7f69a740f89988062a90591d42fb 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/SendCallback.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/SendCallback.java @@ -17,7 +17,7 @@ package org.apache.rocketmq.client.producer; public interface SendCallback { - public void onSuccess(final SendResult sendResult); + void onSuccess(final SendResult sendResult); - public void onException(final Throwable e); + void onException(final Throwable e); } diff --git a/client/src/main/java/org/apache/rocketmq/client/producer/SendResult.java b/client/src/main/java/org/apache/rocketmq/client/producer/SendResult.java index fa960757983141d5d0c1cfdacda2b55b2cf5d641..80948830fbafbcf09107859113db015ceb60a839 100644 --- a/client/src/main/java/org/apache/rocketmq/client/producer/SendResult.java +++ b/client/src/main/java/org/apache/rocketmq/client/producer/SendResult.java @@ -32,7 +32,8 @@ public class SendResult { public SendResult() { } - public SendResult(SendStatus sendStatus, String msgId, String offsetMsgId, MessageQueue messageQueue, long queueOffset) { + public SendResult(SendStatus sendStatus, String msgId, String offsetMsgId, MessageQueue messageQueue, + long queueOffset) { this.sendStatus = sendStatus; this.msgId = msgId; this.offsetMsgId = offsetMsgId; @@ -40,7 +41,8 @@ public class SendResult { this.queueOffset = queueOffset; } - public SendResult(final SendStatus sendStatus, final String msgId, final MessageQueue messageQueue, final long queueOffset, final String transactionId, + public SendResult(final SendStatus sendStatus, final String msgId, final MessageQueue messageQueue, + final long queueOffset, final String transactionId, final String offsetMsgId, final String regionId) { this.sendStatus = sendStatus; this.msgId = msgId; diff --git a/client/src/test/java/org/apache/rocketmq/client/consumer/DefaultMQPullConsumerTest.java b/client/src/test/java/org/apache/rocketmq/client/consumer/DefaultMQPullConsumerTest.java index 33142617d0d3d533a4f5b0e090a35e84f9bcf90b..9cdeda8e8dc15c79d1aa936d3a2a868a96826925 100644 --- a/client/src/test/java/org/apache/rocketmq/client/consumer/DefaultMQPullConsumerTest.java +++ b/client/src/test/java/org/apache/rocketmq/client/consumer/DefaultMQPullConsumerTest.java @@ -86,7 +86,8 @@ public class DefaultMQPullConsumerTest { @Test public void testPullMessage_Success() throws Exception { doAnswer(new Answer() { - @Override public Object answer(InvocationOnMock mock) throws Throwable { + @Override + public Object answer(InvocationOnMock mock) throws Throwable { PullMessageRequestHeader requestHeader = mock.getArgument(1); return createPullResult(requestHeader, PullStatus.FOUND, Collections.singletonList(new MessageExt())); } @@ -103,9 +104,10 @@ public class DefaultMQPullConsumerTest { } @Test - public void testPullMessage_NotFound() throws Exception{ + public void testPullMessage_NotFound() throws Exception { doAnswer(new Answer() { - @Override public Object answer(InvocationOnMock mock) throws Throwable { + @Override + public Object answer(InvocationOnMock mock) throws Throwable { PullMessageRequestHeader requestHeader = mock.getArgument(1); return createPullResult(requestHeader, PullStatus.NO_NEW_MSG, new ArrayList()); } @@ -119,7 +121,8 @@ public class DefaultMQPullConsumerTest { @Test public void testPullMessageAsync_Success() throws Exception { doAnswer(new Answer() { - @Override public Object answer(InvocationOnMock mock) throws Throwable { + @Override + public Object answer(InvocationOnMock mock) throws Throwable { PullMessageRequestHeader requestHeader = mock.getArgument(1); PullResult pullResult = createPullResult(requestHeader, PullStatus.FOUND, Collections.singletonList(new MessageExt())); @@ -131,7 +134,8 @@ public class DefaultMQPullConsumerTest { MessageQueue messageQueue = new MessageQueue(topic, brokerName, 0); pullConsumer.pull(messageQueue, "*", 1024, 3, new PullCallback() { - @Override public void onSuccess(PullResult pullResult) { + @Override + public void onSuccess(PullResult pullResult) { assertThat(pullResult).isNotNull(); assertThat(pullResult.getPullStatus()).isEqualTo(PullStatus.FOUND); assertThat(pullResult.getNextBeginOffset()).isEqualTo(1024 + 1); @@ -140,13 +144,15 @@ public class DefaultMQPullConsumerTest { assertThat(pullResult.getMsgFoundList()).isEqualTo(new ArrayList()); } - @Override public void onException(Throwable e) { + @Override + public void onException(Throwable e) { } }); } - private PullResultExt createPullResult(PullMessageRequestHeader requestHeader, PullStatus pullStatus, List messageExtList) throws Exception { + private PullResultExt createPullResult(PullMessageRequestHeader requestHeader, PullStatus pullStatus, + List messageExtList) throws Exception { return new PullResultExt(pullStatus, requestHeader.getQueueOffset() + messageExtList.size(), 123, 2048, messageExtList, 0, new byte[] {}); } } \ No newline at end of file diff --git a/client/src/test/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumerTest.java b/client/src/test/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumerTest.java index cdf1d7800363d434f71b9423b8c5aab34ea0c6d8..7e69cc147856def1fd5aee2f14f224f41be8d1e9 100644 --- a/client/src/test/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumerTest.java +++ b/client/src/test/java/org/apache/rocketmq/client/consumer/DefaultMQPushConsumerTest.java @@ -90,7 +90,8 @@ public class DefaultMQPushConsumerTest { pushConsumer.setPullInterval(60 * 1000); pushConsumer.registerMessageListener(new MessageListenerConcurrently() { - @Override public ConsumeConcurrentlyStatus consumeMessage(List msgs, + @Override + public ConsumeConcurrentlyStatus consumeMessage(List msgs, ConsumeConcurrentlyContext context) { return null; } @@ -109,7 +110,6 @@ public class DefaultMQPushConsumerTest { field.setAccessible(true); field.set(pushConsumerImpl, mQClientFactory); - field = MQClientInstance.class.getDeclaredField("mQClientAPIImpl"); field.setAccessible(true); field.set(mQClientFactory, mQClientAPIImpl); @@ -125,21 +125,22 @@ public class DefaultMQPushConsumerTest { when(mQClientFactory.getMQClientAPIImpl().pullMessage(anyString(), any(PullMessageRequestHeader.class), anyLong(), any(CommunicationMode.class), nullable(PullCallback.class))) .thenAnswer(new Answer() { - @Override public Object answer(InvocationOnMock mock) throws Throwable { - PullMessageRequestHeader requestHeader = mock.getArgument(1); - MessageClientExt messageClientExt = new MessageClientExt(); - messageClientExt.setTopic(topic); - messageClientExt.setQueueId(0); - messageClientExt.setMsgId("123"); - messageClientExt.setBody(new byte[] {'a'}); - messageClientExt.setOffsetMsgId("234"); - messageClientExt.setBornHost(new InetSocketAddress(8080)); - messageClientExt.setStoreHost(new InetSocketAddress(8080)); - PullResult pullResult = createPullResult(requestHeader, PullStatus.FOUND, Collections.singletonList(messageClientExt)); - ((PullCallback)mock.getArgument(4)).onSuccess(pullResult); - return pullResult; - } - }); + @Override + public Object answer(InvocationOnMock mock) throws Throwable { + PullMessageRequestHeader requestHeader = mock.getArgument(1); + MessageClientExt messageClientExt = new MessageClientExt(); + messageClientExt.setTopic(topic); + messageClientExt.setQueueId(0); + messageClientExt.setMsgId("123"); + messageClientExt.setBody(new byte[] {'a'}); + messageClientExt.setOffsetMsgId("234"); + messageClientExt.setBornHost(new InetSocketAddress(8080)); + messageClientExt.setStoreHost(new InetSocketAddress(8080)); + PullResult pullResult = createPullResult(requestHeader, PullStatus.FOUND, Collections.singletonList(messageClientExt)); + ((PullCallback) mock.getArgument(4)).onSuccess(pullResult); + return pullResult; + } + }); doReturn(new FindBrokerResult("127.0.0.1:10911", false)).when(mQClientFactory).findBrokerAddressInSubscribe(anyString(), anyLong(), anyBoolean()); doReturn(Collections.singletonList(mQClientFactory.getClientId())).when(mQClientFactory).findConsumerIdList(anyString(), anyString()); @@ -159,7 +160,8 @@ public class DefaultMQPushConsumerTest { final CountDownLatch countDownLatch = new CountDownLatch(1); final MessageExt[] messageExts = new MessageExt[1]; pushConsumer.getDefaultMQPushConsumerImpl().setConsumeMessageService(new ConsumeMessageConcurrentlyService(pushConsumer.getDefaultMQPushConsumerImpl(), new MessageListenerConcurrently() { - @Override public ConsumeConcurrentlyStatus consumeMessage(List msgs, + @Override + public ConsumeConcurrentlyStatus consumeMessage(List msgs, ConsumeConcurrentlyContext context) { messageExts[0] = msgs.get(0); countDownLatch.countDown(); @@ -217,7 +219,8 @@ public class DefaultMQPushConsumerTest { return pullRequest; } - private PullResultExt createPullResult(PullMessageRequestHeader requestHeader, PullStatus pullStatus, List messageExtList) throws Exception { + private PullResultExt createPullResult(PullMessageRequestHeader requestHeader, PullStatus pullStatus, + List messageExtList) throws Exception { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); for (MessageExt messageExt : messageExtList) { outputStream.write(MessageDecoder.encode(messageExt, false)); diff --git a/client/src/test/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueConsitentHashTest.java b/client/src/test/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueConsitentHashTest.java index e9e5db7efd82235d1d48583a16743bb2e791385c..3a581e131002d5b9f803712c7c1ff5d636d7b417 100644 --- a/client/src/test/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueConsitentHashTest.java +++ b/client/src/test/java/org/apache/rocketmq/client/consumer/rebalance/AllocateMessageQueueConsitentHashTest.java @@ -29,7 +29,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; - public class AllocateMessageQueueConsitentHashTest { private String topic; @@ -40,8 +39,6 @@ public class AllocateMessageQueueConsitentHashTest { topic = "topic_test"; } - - public void printMessageQueue(List messageQueueList, String name) { if (messageQueueList == null || messageQueueList.size() < 1) return; @@ -85,28 +82,27 @@ public class AllocateMessageQueueConsitentHashTest { @Test public void testAllocate1() { - testAllocate(20,10); + testAllocate(20, 10); } @Test public void testAllocate2() { - testAllocate(10,20); + testAllocate(10, 20); } - @Test - public void testRun100RandomCase(){ - for(int i=0;i<100;i++){ - int consumerSize = new Random().nextInt(200)+1;//1-200 - int queueSize = new Random().nextInt(100)+1;//1-100 - testAllocate(queueSize,consumerSize); + public void testRun100RandomCase() { + for (int i = 0; i < 10; i++) { + int consumerSize = new Random().nextInt(20) + 1;//1-20 + int queueSize = new Random().nextInt(20) + 1;//1-20 + testAllocate(queueSize, consumerSize); try { Thread.sleep(1); - } catch (InterruptedException e) {} + } catch (InterruptedException e) { + } } } - public void testAllocate(int queueSize, int consumerSize) { AllocateMessageQueueStrategy allocateMessageQueueConsistentHash = new AllocateMessageQueueConsistentHash(3); @@ -133,7 +129,7 @@ public class AllocateMessageQueueConsitentHashTest { } Assert.assertTrue( - verifyAllocateAll(cidBegin,mqAll, allocatedResAll)); + verifyAllocateAll(cidBegin, mqAll, allocatedResAll)); } Map allocateToAllAfterRemoveOne = new TreeMap(); @@ -162,7 +158,7 @@ public class AllocateMessageQueueConsitentHashTest { //System.out.println("rs[" + cid + "]:" + "[" + rs.size() + "]" + rs.toString()); } - Assert.assertTrue("queueSize"+queueSize+"consumerSize:"+consumerSize+"\nmqAll:"+mqAll+"\nallocatedResAllAfterRemove"+allocatedResAllAfterRemove, + Assert.assertTrue("queueSize" + queueSize + "consumerSize:" + consumerSize + "\nmqAll:" + mqAll + "\nallocatedResAllAfterRemove" + allocatedResAllAfterRemove, verifyAllocateAll(cidAfterRemoveOne, mqAll, allocatedResAllAfterRemove)); verifyAfterRemove(allocateToAllOrigin, allocateToAllAfterRemoveOne, removeCID); } @@ -170,7 +166,7 @@ public class AllocateMessageQueueConsitentHashTest { List cidAfterAdd = new ArrayList(cidAfterRemoveOne); //test allocate add one more cid { - String newCid = CID_PREFIX+"NEW"; + String newCid = CID_PREFIX + "NEW"; //System.out.println("add one more cid "+newCid); cidAfterAdd.add(newCid); List mqShouldOnlyChanged = new ArrayList(); @@ -182,7 +178,7 @@ public class AllocateMessageQueueConsitentHashTest { allocatedResAllAfterAdd.addAll(rs); for (MessageQueue mq : rs) { allocateToAll3.put(mq, cid); - if (cid.equals(newCid)){ + if (cid.equals(newCid)) { mqShouldOnlyChanged.add(mq); } } @@ -190,19 +186,21 @@ public class AllocateMessageQueueConsitentHashTest { } Assert.assertTrue( - verifyAllocateAll(cidAfterAdd,mqAll, allocatedResAllAfterAdd)); + verifyAllocateAll(cidAfterAdd, mqAll, allocatedResAllAfterAdd)); verifyAfterAdd(allocateToAllAfterRemoveOne, allocateToAll3, newCid); } } - private boolean verifyAllocateAll(List cidAll,List mqAll, List allocatedResAll) { - if (cidAll.isEmpty()){ + private boolean verifyAllocateAll(List cidAll, List mqAll, + List allocatedResAll) { + if (cidAll.isEmpty()) { return allocatedResAll.isEmpty(); } return mqAll.containsAll(allocatedResAll) && allocatedResAll.containsAll(mqAll); } - private void verifyAfterRemove(Map allocateToBefore, Map allocateAfter, String removeCID) { + private void verifyAfterRemove(Map allocateToBefore, Map allocateAfter, + String removeCID) { for (MessageQueue mq : allocateToBefore.keySet()) { String allocateToOrigin = allocateToBefore.get(mq); if (allocateToOrigin.equals(removeCID)) { @@ -213,14 +211,15 @@ public class AllocateMessageQueueConsitentHashTest { } } - private void verifyAfterAdd(Map allocateBefore, Map allocateAfter, String newCID) { + private void verifyAfterAdd(Map allocateBefore, Map allocateAfter, + String newCID) { for (MessageQueue mq : allocateAfter.keySet()) { String allocateToOrigin = allocateBefore.get(mq); String allocateToAfter = allocateAfter.get(mq); if (allocateToAfter.equals(newCID)) { } else {//the rest queue should be the same - Assert.assertTrue("it was allocated to "+allocateToOrigin+". Now, it is to "+allocateAfter.get(mq)+" mq:"+mq,allocateAfter.get(mq).equals(allocateToOrigin));//should be the same + Assert.assertTrue("it was allocated to " + allocateToOrigin + ". Now, it is to " + allocateAfter.get(mq) + " mq:" + mq, allocateAfter.get(mq).equals(allocateToOrigin));//should be the same } } } diff --git a/client/src/test/java/org/apache/rocketmq/client/consumer/store/RemoteBrokerOffsetStoreTest.java b/client/src/test/java/org/apache/rocketmq/client/consumer/store/RemoteBrokerOffsetStoreTest.java index 81c394c448f2b81a5b1836cdb319c0cfec98bbef..64d64f29a9489fbc77577c71170e552718be3263 100644 --- a/client/src/test/java/org/apache/rocketmq/client/consumer/store/RemoteBrokerOffsetStoreTest.java +++ b/client/src/test/java/org/apache/rocketmq/client/consumer/store/RemoteBrokerOffsetStoreTest.java @@ -99,7 +99,8 @@ public class RemoteBrokerOffsetStoreTest { final MessageQueue messageQueue = new MessageQueue(topic, brokerName, 3); doAnswer(new Answer() { - @Override public Object answer(InvocationOnMock mock) throws Throwable { + @Override + public Object answer(InvocationOnMock mock) throws Throwable { UpdateConsumerOffsetRequestHeader updateRequestHeader = mock.getArgument(1); when(mqClientAPI.queryConsumerOffset(anyString(), any(QueryConsumerOffsetRequestHeader.class), anyLong())).thenReturn(updateRequestHeader.getCommitOffset()); return null; @@ -123,8 +124,6 @@ public class RemoteBrokerOffsetStoreTest { assertThat(offsetStore.readOffset(messageQueue, ReadOffsetType.READ_FROM_STORE)).isEqualTo(1025); } - - @Test public void testRemoveOffset() throws Exception { OffsetStore offsetStore = new RemoteBrokerOffsetStore(mQClientFactory, group); diff --git a/client/src/test/java/org/apache/rocketmq/client/impl/MQClientAPIImplTest.java b/client/src/test/java/org/apache/rocketmq/client/impl/MQClientAPIImplTest.java index 3553738f387f3d9c2f9bca4b4cd2c2ef2801801e..bf019618d9c897e474ac10c1882f5c5fb37d2551 100644 --- a/client/src/test/java/org/apache/rocketmq/client/impl/MQClientAPIImplTest.java +++ b/client/src/test/java/org/apache/rocketmq/client/impl/MQClientAPIImplTest.java @@ -107,7 +107,8 @@ public class MQClientAPIImplTest { @Test public void testSendMessageSync_Success() throws InterruptedException, RemotingException, MQBrokerException { doAnswer(new Answer() { - @Override public Object answer(InvocationOnMock mock) throws Throwable { + @Override + public Object answer(InvocationOnMock mock) throws Throwable { RemotingCommand request = mock.getArgument(1); return createSuccessResponse(request); } @@ -127,7 +128,8 @@ public class MQClientAPIImplTest { @Test public void testSendMessageSync_WithException() throws InterruptedException, RemotingException, MQBrokerException { doAnswer(new Answer() { - @Override public Object answer(InvocationOnMock mock) throws Throwable { + @Override + public Object answer(InvocationOnMock mock) throws Throwable { RemotingCommand request = mock.getArgument(1); RemotingCommand response = RemotingCommand.createResponseCommand(SendMessageResponseHeader.class); response.setCode(ResponseCode.SYSTEM_ERROR); @@ -156,7 +158,8 @@ public class MQClientAPIImplTest { assertThat(sendResult).isNull(); doAnswer(new Answer() { - @Override public Object answer(InvocationOnMock mock) throws Throwable { + @Override + public Object answer(InvocationOnMock mock) throws Throwable { InvokeCallback callback = mock.getArgument(3); RemotingCommand request = mock.getArgument(1); ResponseFuture responseFuture = new ResponseFuture(request.getOpaque(), 3 * 1000, null, null); @@ -169,14 +172,16 @@ public class MQClientAPIImplTest { sendMessageContext.setProducer(new DefaultMQProducerImpl(new DefaultMQProducer())); mqClientAPI.sendMessage(brokerAddr, brokerName, msg, new SendMessageRequestHeader(), 3 * 1000, CommunicationMode.ASYNC, new SendCallback() { - @Override public void onSuccess(SendResult sendResult) { + @Override + public void onSuccess(SendResult sendResult) { assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK); assertThat(sendResult.getOffsetMsgId()).isEqualTo("123"); assertThat(sendResult.getQueueOffset()).isEqualTo(123L); assertThat(sendResult.getMessageQueue().getQueueId()).isEqualTo(1); } - @Override public void onException(Throwable e) { + @Override + public void onException(Throwable e) { } }, null, null, 0, sendMessageContext, defaultMQProducerImpl); diff --git a/client/src/test/java/org/apache/rocketmq/client/impl/factory/MQClientInstanceTest.java b/client/src/test/java/org/apache/rocketmq/client/impl/factory/MQClientInstanceTest.java index 7e0b4f934d532779338d1de47582d33e4b75f5bd..171a95a8b68f520c1c9e833ad85fc66880b2cd35 100644 --- a/client/src/test/java/org/apache/rocketmq/client/impl/factory/MQClientInstanceTest.java +++ b/client/src/test/java/org/apache/rocketmq/client/impl/factory/MQClientInstanceTest.java @@ -39,7 +39,7 @@ import static org.mockito.Mockito.mock; @RunWith(MockitoJUnitRunner.class) public class MQClientInstanceTest { - private MQClientInstance mqClientInstance = MQClientManager.getInstance().getAndCreateMQClientInstance(new ClientConfig()); + private MQClientInstance mqClientInstance = MQClientManager.getInstance().getAndCreateMQClientInstance(new ClientConfig()); private String topic = "FooBar"; private String group = "FooBarGroup"; diff --git a/client/src/test/java/org/apache/rocketmq/client/log/ClientLogTest.java b/client/src/test/java/org/apache/rocketmq/client/log/ClientLogTest.java deleted file mode 100644 index d7b619f51bf2c79a7474f871599c84eb777c3958..0000000000000000000000000000000000000000 --- a/client/src/test/java/org/apache/rocketmq/client/log/ClientLogTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.rocketmq.client.log; - -import org.junit.Assert; -import org.junit.Test; - -import java.io.*; -import java.lang.reflect.Field; -import java.util.Date; - -public class ClientLogTest { - - public static final String CLIENT_LOG_ROOT = "rocketmq.client.logRoot"; - public static final String LOG_DIR; - - static { - LOG_DIR = System.getProperty(CLIENT_LOG_ROOT, "${user.home}/logs/rocketmqlogs"); - } - - // FIXME: Workarond for concret implementation for slf4j, is there any better solution for all slf4j implementations in one class ? 2017/8/1 - @Test - public void testLog4j2() throws IOException, NoSuchFieldException, IllegalAccessException { - ClientLogger.getLog(); - long seek = 0; - boolean result = false; - File file = new File(LOG_DIR + File.separator + "rocketmq_client.log"); - if (file.exists()) { - seek = file.length(); - } - Field logClassField = ClientLogger.class.getDeclaredField("logClass"); - logClassField.setAccessible(true); - Class logClass = (Class) logClassField.get(ClientLogger.class); - Assert.assertEquals("org.apache.logging.slf4j.Log4jLoggerFactory", logClass.getName()); - for (int i = 0; i < 10; i++) { - ClientLogger.getLog().info("testcase testLog4j2 " + new Date()); - } - - RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r"); - randomAccessFile.seek(seek); - String line = randomAccessFile.readLine(); - int idx = 1; - while (line != null) { - if (line.contains("testLog4j2")) { - result = true; - break; - } - line = randomAccessFile.readLine(); - idx++; - if (idx > 20) { - break; - } - } - randomAccessFile.close(); - Assert.assertTrue(result); - } -} diff --git a/client/src/test/java/org/apache/rocketmq/client/log/ClientLoggerTest.java b/client/src/test/java/org/apache/rocketmq/client/log/ClientLoggerTest.java new file mode 100644 index 0000000000000000000000000000000000000000..d3f3be79b2a993f268d5ee8b3b57f452347a72dc --- /dev/null +++ b/client/src/test/java/org/apache/rocketmq/client/log/ClientLoggerTest.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.rocketmq.client.log; + +import org.apache.rocketmq.common.UtilAll; +import org.junit.After; +import org.junit.Test; +import org.slf4j.Logger; + +import java.io.File; + +import static org.junit.Assert.assertEquals; + +public class ClientLoggerTest { + + public static final String CLIENT_LOG_ROOT = "rocketmq.client.logRoot"; + public static final String LOG_DIR; + + static { + LOG_DIR = System.getProperty(CLIENT_LOG_ROOT, System.getProperty("user.home") + "/logs/rocketmqlogs"); + } + + + @After + public void cleanFiles() { + UtilAll.deleteFile(new File(LOG_DIR)); + } + + // FIXME: Workaround for concrete implementation for slf4j, is there any better solution for all slf4j implementations in one class ? 2017/8/1 + @Test + public void testLog4j2() throws Exception { + Logger logger = ClientLogger.getLog(); + + System.out.println(logger); + assertEquals("org.apache.logging.slf4j.Log4jLogger", logger.getClass().getName()); + } +} diff --git a/client/src/test/java/org/apache/rocketmq/client/producer/DefaultMQProducerTest.java b/client/src/test/java/org/apache/rocketmq/client/producer/DefaultMQProducerTest.java index 2f035e0fca21b3ff216621a9938dce6f106c500c..1ae6f2f2cc69c67d4856bd4889c068b2fc60d0e2 100644 --- a/client/src/test/java/org/apache/rocketmq/client/producer/DefaultMQProducerTest.java +++ b/client/src/test/java/org/apache/rocketmq/client/producer/DefaultMQProducerTest.java @@ -149,13 +149,16 @@ public class DefaultMQProducerTest { final Throwable[] assertionErrors = new Throwable[1]; final CountDownLatch countDownLatch = new CountDownLatch(2); producer.getDefaultMQProducerImpl().registerSendMessageHook(new SendMessageHook() { - @Override public String hookName() { + @Override + public String hookName() { return "TestHook"; } - @Override public void sendMessageBefore(final SendMessageContext context) { + @Override + public void sendMessageBefore(final SendMessageContext context) { assertionErrors[0] = assertInOtherThread(new Runnable() { - @Override public void run() { + @Override + public void run() { assertThat(context.getMessage()).isEqualTo(message); assertThat(context.getProducer()).isEqualTo(producer); assertThat(context.getCommunicationMode()).isEqualTo(CommunicationMode.SYNC); @@ -165,9 +168,11 @@ public class DefaultMQProducerTest { countDownLatch.countDown(); } - @Override public void sendMessageAfter(final SendMessageContext context) { + @Override + public void sendMessageAfter(final SendMessageContext context) { assertionErrors[0] = assertInOtherThread(new Runnable() { - @Override public void run() { + @Override + public void run() { assertThat(context.getMessage()).isEqualTo(message); assertThat(context.getProducer()).isEqualTo(producer.getDefaultMQProducerImpl()); assertThat(context.getCommunicationMode()).isEqualTo(CommunicationMode.SYNC); @@ -229,7 +234,8 @@ public class DefaultMQProducerTest { private Throwable assertInOtherThread(final Runnable runnable) { final Throwable[] assertionErrors = new Throwable[1]; Thread thread = new Thread(new Runnable() { - @Override public void run() { + @Override + public void run() { try { runnable.run(); } catch (AssertionError e) { diff --git a/common/src/main/java/org/apache/rocketmq/common/BrokerConfig.java b/common/src/main/java/org/apache/rocketmq/common/BrokerConfig.java index f22729c14c9a8f879e1de552a4a9f9e5f9a47745..9a208a3fad05b3f3a555204532c13e6679b78c7f 100644 --- a/common/src/main/java/org/apache/rocketmq/common/BrokerConfig.java +++ b/common/src/main/java/org/apache/rocketmq/common/BrokerConfig.java @@ -54,7 +54,8 @@ public class BrokerConfig { private String messageStorePlugIn = ""; /** - * thread numbers for send message thread pool, since spin lock will be used by default since 4.0.x, the default value is 1. + * thread numbers for send message thread pool, since spin lock will be used by default since 4.0.x, the default + * value is 1. */ private int sendMessageThreadPoolNums = 1; //16 + Runtime.getRuntime().availableProcessors() * 4; private int pullMessageThreadPoolNums = 16 + Runtime.getRuntime().availableProcessors() * 2; diff --git a/common/src/main/java/org/apache/rocketmq/common/Configuration.java b/common/src/main/java/org/apache/rocketmq/common/Configuration.java index d0c7aefe2f3e8a479995a244f0a4552cadcc7b0b..802f6eea2bd47ae87eb3a2f3ba46265a0af585ac 100644 --- a/common/src/main/java/org/apache/rocketmq/common/Configuration.java +++ b/common/src/main/java/org/apache/rocketmq/common/Configuration.java @@ -65,7 +65,6 @@ public class Configuration { /** * register config object * - * @param configObject * @return the current Configuration object */ public Configuration registerConfig(Object configObject) { @@ -91,7 +90,6 @@ public class Configuration { /** * register config properties * - * @param extProperties * @return the current Configuration object */ public Configuration registerConfig(Properties extProperties) { @@ -117,8 +115,6 @@ public class Configuration { /** * The store path will be gotten from the field of object. * - * @param object - * @param fieldName * @throws java.lang.RuntimeException if the field of object is not exist. */ public void setStorePathFromConfig(Object object, String fieldName) { diff --git a/common/src/main/java/org/apache/rocketmq/common/CountDownLatch2.java b/common/src/main/java/org/apache/rocketmq/common/CountDownLatch2.java index cb3903280ed3d56c0d12836e911c80705054a0d2..de1d548932caa1dfb73b223404ea3b68b2da4b81 100644 --- a/common/src/main/java/org/apache/rocketmq/common/CountDownLatch2.java +++ b/common/src/main/java/org/apache/rocketmq/common/CountDownLatch2.java @@ -29,7 +29,8 @@ public class CountDownLatch2 { /** * Constructs a {@code CountDownLatch2} initialized with the given count. * - * @param count the number of times {@link #countDown} must be invoked before threads can pass through {@link #await} + * @param count the number of times {@link #countDown} must be invoked before threads can pass through {@link + * #await} * @throws IllegalArgumentException if {@code count} is negative */ public CountDownLatch2(int count) { @@ -104,7 +105,8 @@ public class CountDownLatch2 { * * @param timeout the maximum time to wait * @param unit the time unit of the {@code timeout} argument - * @return {@code true} if the count reached zero and {@code false} if the waiting time elapsed before the count reached zero + * @return {@code true} if the count reached zero and {@code false} if the waiting time elapsed before the count + * reached zero * @throws InterruptedException if the current thread is interrupted while waiting */ public boolean await(long timeout, TimeUnit unit) @@ -176,7 +178,7 @@ public class CountDownLatch2 { protected boolean tryReleaseShared(int releases) { // Decrement count; signal when transition to zero - for (;;) { + for (; ; ) { int c = getState(); if (c == 0) return false; diff --git a/common/src/main/java/org/apache/rocketmq/common/DataVersion.java b/common/src/main/java/org/apache/rocketmq/common/DataVersion.java index e47a9b38195e7cc73b7d9dfa67b6e3c4a26c4e13..71b00fdd72d2ae6188948177f8963832a7d8b149 100644 --- a/common/src/main/java/org/apache/rocketmq/common/DataVersion.java +++ b/common/src/main/java/org/apache/rocketmq/common/DataVersion.java @@ -74,7 +74,7 @@ public class DataVersion extends RemotingSerializable { int result = (int) (timestamp ^ (timestamp >>> 32)); if (null != counter) { long l = counter.get(); - result = 31 * result + (int)(l ^ (l >>> 32)); + result = 31 * result + (int) (l ^ (l >>> 32)); } return result; } diff --git a/common/src/main/java/org/apache/rocketmq/common/MixAll.java b/common/src/main/java/org/apache/rocketmq/common/MixAll.java index f8e9b4e1f673c37b0b649712f37ce7fca3824cc4..3a005e6a545b60c3d68b497ead4b641a92573a8e 100644 --- a/common/src/main/java/org/apache/rocketmq/common/MixAll.java +++ b/common/src/main/java/org/apache/rocketmq/common/MixAll.java @@ -26,20 +26,17 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.net.Inet6Address; import java.net.InetAddress; -import java.net.InetSocketAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.net.URL; import java.net.URLConnection; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Enumeration; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; -import java.util.Set; import java.util.concurrent.atomic.AtomicLong; import org.apache.rocketmq.common.annotation.ImportantField; import org.apache.rocketmq.common.constant.LoggerName; @@ -58,8 +55,8 @@ public class MixAll { public static final String DEFAULT_NAMESRV_ADDR_LOOKUP = "jmenv.tbsite.net"; public static final String WS_DOMAIN_NAME = System.getProperty("rocketmq.namesrv.domain", DEFAULT_NAMESRV_ADDR_LOOKUP); public static final String WS_DOMAIN_SUBGROUP = System.getProperty("rocketmq.namesrv.domain.subgroup", "nsaddr"); -// // http://jmenv.tbsite.net:8080/rocketmq/nsaddr -// public static final String WS_ADDR = "http://" + WS_DOMAIN_NAME + ":8080/rocketmq/" + WS_DOMAIN_SUBGROUP; + //http://jmenv.tbsite.net:8080/rocketmq/nsaddr + //public static final String WS_ADDR = "http://" + WS_DOMAIN_NAME + ":8080/rocketmq/" + WS_DOMAIN_SUBGROUP; public static final String DEFAULT_TOPIC = "TBW102"; public static final String BENCHMARK_TOPIC = "BenchmarkTest"; public static final String DEFAULT_PRODUCER_GROUP = "DEFAULT_PRODUCER"; @@ -141,16 +138,6 @@ public class MixAll { return 0; } - public static long createBrokerId(final String ip, final int port) { - InetSocketAddress isa = new InetSocketAddress(ip, port); - byte[] ipArray = isa.getAddress().getAddress(); - ByteBuffer bb = ByteBuffer.allocate(8); - bb.put(ipArray); - bb.putInt(port); - long value = bb.getLong(0); - return Math.abs(value); - } - public static void string2File(final String str, final String fileName) throws IOException { String tmpFile = fileName + ".tmp"; @@ -169,7 +156,6 @@ public class MixAll { file.renameTo(new File(fileName)); } - public static void string2FileNotSafe(final String str, final String fileName) throws IOException { File file = new File(fileName); File fileParent = file.getParentFile(); @@ -241,16 +227,12 @@ public class MixAll { return null; } - public static String findClassPath(Class c) { - URL url = c.getProtectionDomain().getCodeSource().getLocation(); - return url.getPath(); - } - public static void printObjectProperties(final Logger logger, final Object object) { printObjectProperties(logger, object, false); } - public static void printObjectProperties(final Logger logger, final Object object, final boolean onlyImportantField) { + public static void printObjectProperties(final Logger logger, final Object object, + final boolean onlyImportantField) { Field[] fields = object.getClass().getDeclaredFields(); for (Field field : fields) { if (!Modifier.isStatic(field.getModifiers())) { @@ -394,25 +376,54 @@ public class MixAll { return inetAddressList; } - public static boolean isLocalAddr(String address) { - for (String addr : LOCAL_INET_ADDRESS) { - if (address.contains(addr)) - return true; - } - return false; - } - private static String localhost() { try { - InetAddress addr = InetAddress.getLocalHost(); - return addr.getHostAddress(); + return InetAddress.getLocalHost().getHostAddress(); } catch (Throwable e) { - throw new RuntimeException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException" - + FAQUrl.suggestTodo(FAQUrl.UNKNOWN_HOST_EXCEPTION), - e); + try { + String candidatesHost = getLocalhostByNetworkInterface(); + if (candidatesHost != null) + return candidatesHost; + + } catch (Exception ignored) { + } + + throw new RuntimeException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException" + FAQUrl.suggestTodo(FAQUrl.UNKNOWN_HOST_EXCEPTION), e); } } + //Reverse logic comparing to RemotingUtil method, consider refactor in RocketMQ 5.0 + public static String getLocalhostByNetworkInterface() throws SocketException { + List candidatesHost = new ArrayList(); + Enumeration enumeration = NetworkInterface.getNetworkInterfaces(); + + while (enumeration.hasMoreElements()) { + NetworkInterface networkInterface = enumeration.nextElement(); + // Workaround for docker0 bridge + if ("docker0".equals(networkInterface.getName()) || !networkInterface.isUp()) { + continue; + } + Enumeration addrs = networkInterface.getInetAddresses(); + while (addrs.hasMoreElements()) { + InetAddress address = addrs.nextElement(); + if (address.isLoopbackAddress()) { + continue; + } + //ip4 highter priority + if (address instanceof Inet6Address) { + candidatesHost.add(address.getHostAddress()); + continue; + } + return address.getHostAddress(); + } + } + + if (!candidatesHost.isEmpty()) { + return candidatesHost.get(0); + } + return null; + } + public static boolean compareAndIncreaseOnly(final AtomicLong target, final long value) { long prev = target.get(); while (value > prev) { @@ -426,16 +437,6 @@ public class MixAll { return false; } - public static String localhostName() { - try { - return InetAddress.getLocalHost().getHostName(); - } catch (Throwable e) { - throw new RuntimeException("InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException" - + FAQUrl.suggestTodo(FAQUrl.UNKNOWN_HOST_EXCEPTION), - e); - } - } - public static String humanReadableByteCount(long bytes, boolean si) { int unit = si ? 1000 : 1024; if (bytes < unit) @@ -445,19 +446,4 @@ public class MixAll { return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); } - public Set list2Set(List values) { - Set result = new HashSet(); - for (String v : values) { - result.add(v); - } - return result; - } - - public List set2List(Set values) { - List result = new ArrayList(); - for (String v : values) { - result.add(v); - } - return result; - } } diff --git a/common/src/main/java/org/apache/rocketmq/common/ServiceThread.java b/common/src/main/java/org/apache/rocketmq/common/ServiceThread.java index 7b968807ccad397e9ace2c25663574c6ac9d3931..bf7e724986aa69db93d829c8318afa6a4e5d6fb3 100644 --- a/common/src/main/java/org/apache/rocketmq/common/ServiceThread.java +++ b/common/src/main/java/org/apache/rocketmq/common/ServiceThread.java @@ -65,7 +65,7 @@ public abstract class ServiceThread implements Runnable { } long eclipseTime = System.currentTimeMillis() - beginTime; log.info("join thread " + this.getServiceName() + " eclipse time(ms) " + eclipseTime + " " - + this.getJointime()); + + this.getJointime()); } catch (InterruptedException e) { log.error("Interrupted", e); } diff --git a/common/src/main/java/org/apache/rocketmq/common/TopicConfig.java b/common/src/main/java/org/apache/rocketmq/common/TopicConfig.java index b85f6f5b2030c4360b891db6eee52c99b0c12f81..4795cced62dc1329c0cbefc13f4cc3d31ec08e42 100644 --- a/common/src/main/java/org/apache/rocketmq/common/TopicConfig.java +++ b/common/src/main/java/org/apache/rocketmq/common/TopicConfig.java @@ -46,24 +46,14 @@ public class TopicConfig { public String encode() { StringBuilder sb = new StringBuilder(); - - // 1 sb.append(this.topicName); sb.append(SEPARATOR); - - // 2 sb.append(this.readQueueNums); sb.append(SEPARATOR); - - // 3 sb.append(this.writeQueueNums); sb.append(SEPARATOR); - - // 4 sb.append(this.perm); sb.append(SEPARATOR); - - // 5 sb.append(this.topicFilterType); return sb.toString(); diff --git a/common/src/main/java/org/apache/rocketmq/common/UtilAll.java b/common/src/main/java/org/apache/rocketmq/common/UtilAll.java index 15d41087c0a691f8b713213cc5b3b669518c4123..9ed8ab881b7124350091d929e85daa8627157132 100644 --- a/common/src/main/java/org/apache/rocketmq/common/UtilAll.java +++ b/common/src/main/java/org/apache/rocketmq/common/UtilAll.java @@ -209,7 +209,6 @@ public class UtilAll { return -1; } - public static int crc32(byte[] array) { if (array != null) { return crc32(array, 0, array.length); @@ -218,7 +217,6 @@ public class UtilAll { return 0; } - public static int crc32(byte[] array, int offset, int length) { CRC32 crc32 = new CRC32(); crc32.update(array, offset, length); @@ -505,4 +503,19 @@ public class UtilAll { throw new RuntimeException("Can not get local ip", e); } } + + public static void deleteFile(File file) { + if (!file.exists()) { + return; + } + if (file.isFile()) { + file.delete(); + } else if (file.isDirectory()) { + File[] files = file.listFiles(); + for (File file1 : files) { + deleteFile(file1); + } + file.delete(); + } + } } diff --git a/common/src/main/java/org/apache/rocketmq/common/consistenthash/ConsistentHashRouter.java b/common/src/main/java/org/apache/rocketmq/common/consistenthash/ConsistentHashRouter.java index a6fce51e2265e28005aa184973cbb9a58aa62c82..fca1d877d459b3503f097bb6c6a2faffdcf766d7 100644 --- a/common/src/main/java/org/apache/rocketmq/common/consistenthash/ConsistentHashRouter.java +++ b/common/src/main/java/org/apache/rocketmq/common/consistenthash/ConsistentHashRouter.java @@ -25,20 +25,18 @@ import java.util.TreeMap; /** * To hash Node objects to a hash ring with a certain amount of virtual node. - * Method routeNode will return a Node instance which the object key should be allocated to according to consistent hash algorithm - * - * @param + * Method routeNode will return a Node instance which the object key should be allocated to according to consistent hash + * algorithm */ public class ConsistentHashRouter { private final SortedMap> ring = new TreeMap>(); private final HashFunction hashFunction; public ConsistentHashRouter(Collection pNodes, int vNodeCount) { - this(pNodes,vNodeCount, new MD5Hash()); + this(pNodes, vNodeCount, new MD5Hash()); } /** - * * @param pNodes collections of physical nodes * @param vNodeCount amounts of virtual nodes * @param hashFunction hash Function to hash Node instances @@ -57,11 +55,13 @@ public class ConsistentHashRouter { /** * add physic node to the hash ring with some virtual nodes + * * @param pNode physical node needs added to hash ring * @param vNodeCount the number of virtual node of the physical node. Value should be greater than or equals to 0 */ public void addNode(T pNode, int vNodeCount) { - if (vNodeCount < 0) throw new IllegalArgumentException("illegal virtual node counts :" + vNodeCount); + if (vNodeCount < 0) + throw new IllegalArgumentException("illegal virtual node counts :" + vNodeCount); int existingReplicas = getExistingReplicas(pNode); for (int i = 0; i < vNodeCount; i++) { VirtualNode vNode = new VirtualNode(pNode, i + existingReplicas); @@ -71,7 +71,6 @@ public class ConsistentHashRouter { /** * remove the physical node from the hash ring - * @param pNode */ public void removeNode(T pNode) { Iterator it = ring.keySet().iterator(); @@ -86,20 +85,19 @@ public class ConsistentHashRouter { /** * with a specified key, route the nearest Node instance in the current hash ring + * * @param objectKey the object key to find a nearest Node - * @return */ public T routeNode(String objectKey) { if (ring.isEmpty()) { return null; } Long hashVal = hashFunction.hash(objectKey); - SortedMap> tailMap = ring.tailMap(hashVal); + SortedMap> tailMap = ring.tailMap(hashVal); Long nodeHashVal = !tailMap.isEmpty() ? tailMap.firstKey() : ring.firstKey(); return ring.get(nodeHashVal).getPhysicalNode(); } - public int getExistingReplicas(T pNode) { int replicas = 0; for (VirtualNode vNode : ring.values()) { @@ -110,7 +108,6 @@ public class ConsistentHashRouter { return replicas; } - //default hash function private static class MD5Hash implements HashFunction { MessageDigest instance; diff --git a/common/src/main/java/org/apache/rocketmq/common/consistenthash/Node.java b/common/src/main/java/org/apache/rocketmq/common/consistenthash/Node.java index 0ece21098a36eae1e01435bbdc9c2e780346bf1e..192600b7829681f17bb25a0f00bc8e908a6684fa 100644 --- a/common/src/main/java/org/apache/rocketmq/common/consistenthash/Node.java +++ b/common/src/main/java/org/apache/rocketmq/common/consistenthash/Node.java @@ -21,7 +21,6 @@ package org.apache.rocketmq.common.consistenthash; */ public interface Node { /** - * * @return the key which will be used for hash mapping */ String getKey(); diff --git a/common/src/main/java/org/apache/rocketmq/common/consistenthash/VirtualNode.java b/common/src/main/java/org/apache/rocketmq/common/consistenthash/VirtualNode.java index c8b72d9018b5201c9cd792f1bdd0f6b8d074a540..c086c011f8cebaa70a00e4a526ae26492160724c 100644 --- a/common/src/main/java/org/apache/rocketmq/common/consistenthash/VirtualNode.java +++ b/common/src/main/java/org/apache/rocketmq/common/consistenthash/VirtualNode.java @@ -16,7 +16,6 @@ */ package org.apache.rocketmq.common.consistenthash; - public class VirtualNode implements Node { final T physicalNode; final int replicaIndex; diff --git a/common/src/main/java/org/apache/rocketmq/common/filter/FilterAPI.java b/common/src/main/java/org/apache/rocketmq/common/filter/FilterAPI.java index fc8525c18ea23b5162ec5c4dc112b1ba3252019b..9268a6ef45d0663b1c5a08b81efc93e6ef988741 100644 --- a/common/src/main/java/org/apache/rocketmq/common/filter/FilterAPI.java +++ b/common/src/main/java/org/apache/rocketmq/common/filter/FilterAPI.java @@ -65,7 +65,7 @@ public class FilterAPI { } public static SubscriptionData build(final String topic, final String subString, - final String type) throws Exception { + final String type) throws Exception { if (ExpressionType.TAG.equals(type) || type == null) { return buildSubscriptionData(null, topic, subString); } diff --git a/common/src/main/java/org/apache/rocketmq/common/filter/impl/PolishExpr.java b/common/src/main/java/org/apache/rocketmq/common/filter/impl/PolishExpr.java index 56e94e4cc6fcabfda6579554a4f4a3a5680930aa..cdc6187a148b08ed89165d8e06b044cd38cbf692 100644 --- a/common/src/main/java/org/apache/rocketmq/common/filter/impl/PolishExpr.java +++ b/common/src/main/java/org/apache/rocketmq/common/filter/impl/PolishExpr.java @@ -35,7 +35,6 @@ public class PolishExpr { * Shunting-yard algorithm
    * http://en.wikipedia.org/wiki/Shunting_yard_algorithm * - * @param tokens * @return the compute result of Shunting-yard algorithm */ public static List reversePolish(List tokens) { diff --git a/common/src/main/java/org/apache/rocketmq/common/help/FAQUrl.java b/common/src/main/java/org/apache/rocketmq/common/help/FAQUrl.java index eea0da1f9e95602594a12a0742f71f46bf7ca2aa..5d950bebfb1305e36a4be4449b9ab894c0bccc35 100644 --- a/common/src/main/java/org/apache/rocketmq/common/help/FAQUrl.java +++ b/common/src/main/java/org/apache/rocketmq/common/help/FAQUrl.java @@ -18,44 +18,44 @@ package org.apache.rocketmq.common.help; public class FAQUrl { - public static final String APPLY_TOPIC_URL = // + public static final String APPLY_TOPIC_URL = "http://rocketmq.apache.org/docs/faq/"; - public static final String NAME_SERVER_ADDR_NOT_EXIST_URL = // + public static final String NAME_SERVER_ADDR_NOT_EXIST_URL = "http://rocketmq.apache.org/docs/faq/"; - public static final String GROUP_NAME_DUPLICATE_URL = // + public static final String GROUP_NAME_DUPLICATE_URL = "http://rocketmq.apache.org/docs/faq/"; - public static final String CLIENT_PARAMETER_CHECK_URL = // + public static final String CLIENT_PARAMETER_CHECK_URL = "http://rocketmq.apache.org/docs/faq/"; - public static final String SUBSCRIPTION_GROUP_NOT_EXIST = // + public static final String SUBSCRIPTION_GROUP_NOT_EXIST = "http://rocketmq.apache.org/docs/faq/"; - public static final String CLIENT_SERVICE_NOT_OK = // + public static final String CLIENT_SERVICE_NOT_OK = "http://rocketmq.apache.org/docs/faq/"; // FAQ: No route info of this topic, TopicABC - public static final String NO_TOPIC_ROUTE_INFO = // + public static final String NO_TOPIC_ROUTE_INFO = "http://rocketmq.apache.org/docs/faq/"; - public static final String LOAD_JSON_EXCEPTION = // + public static final String LOAD_JSON_EXCEPTION = "http://rocketmq.apache.org/docs/faq/"; - public static final String SAME_GROUP_DIFFERENT_TOPIC = // + public static final String SAME_GROUP_DIFFERENT_TOPIC = "http://rocketmq.apache.org/docs/faq/"; - public static final String MQLIST_NOT_EXIST = // + public static final String MQLIST_NOT_EXIST = "http://rocketmq.apache.org/docs/faq/"; - public static final String UNEXPECTED_EXCEPTION_URL = // + public static final String UNEXPECTED_EXCEPTION_URL = "http://rocketmq.apache.org/docs/faq/"; - public static final String SEND_MSG_FAILED = // + public static final String SEND_MSG_FAILED = "http://rocketmq.apache.org/docs/faq/"; - public static final String UNKNOWN_HOST_EXCEPTION = // + public static final String UNKNOWN_HOST_EXCEPTION = "http://rocketmq.apache.org/docs/faq/"; private static final String TIP_STRING_BEGIN = "\nSee "; diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageClientIDSetter.java b/common/src/main/java/org/apache/rocketmq/common/message/MessageClientIDSetter.java index a1d3ede2113d8de9301a24b2c9d2fd7feebb5b29..d0b202ec64b120a07ecb555a594d8cd9b2d0efc8 100644 --- a/common/src/main/java/org/apache/rocketmq/common/message/MessageClientIDSetter.java +++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageClientIDSetter.java @@ -42,7 +42,7 @@ public class MessageClientIDSetter { tempBuffer.put(createFakeIP()); } tempBuffer.position(6); - tempBuffer.putInt(MessageClientIDSetter.class.getClassLoader().hashCode()); //4 + tempBuffer.putInt(MessageClientIDSetter.class.getClassLoader().hashCode()); FIX_STRING = UtilAll.bytes2string(tempBuffer.array()); setStartTime(System.currentTimeMillis()); COUNTER = new AtomicInteger(0); diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java b/common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java index e41ec9d206a00f373321d566b75b5bfcfaad2ba0..2d7bcbbfd45e38566d6a15f8c3179294d3665804 100644 --- a/common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java +++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java @@ -98,7 +98,6 @@ public class MessageDecoder { * Just decode properties from msg buffer. * * @param byteBuffer msg commit log buffer. - * @return */ public static Map decodeProperties(java.nio.ByteBuffer byteBuffer) { int topicLengthPosition = BODY_SIZE_POSITION + 4 + byteBuffer.getInt(BODY_SIZE_POSITION); @@ -239,8 +238,6 @@ public class MessageDecoder { return byteBuffer.array(); } - - public static MessageExt decode( java.nio.ByteBuffer byteBuffer, final boolean readBody, final boolean deCompressBody) { return decode(byteBuffer, readBody, deCompressBody, false); @@ -414,7 +411,6 @@ public class MessageDecoder { return map; } - public static byte[] encodeMessage(Message message) { //only need flag, body, properties byte[] body = message.getBody(); @@ -488,9 +484,9 @@ public class MessageDecoder { public static byte[] encodeMessages(List messages) { //TO DO refactor, accumulate in one buffer, avoid copies - List encodedMessages = new ArrayList(messages.size()); + List encodedMessages = new ArrayList(messages.size()); int allSize = 0; - for (Message message: messages) { + for (Message message : messages) { byte[] tmp = encodeMessage(message); encodedMessages.add(tmp); allSize += tmp.length; @@ -504,7 +500,6 @@ public class MessageDecoder { return allBytes; } - public static List decodeMessages(ByteBuffer byteBuffer) throws Exception { //TO DO add a callback for processing, avoid creating lists List msgs = new ArrayList(); diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageExtBatch.java b/common/src/main/java/org/apache/rocketmq/common/message/MessageExtBatch.java index 352ab376e15863c37e9ca310b8479b3fcee45cce..a2713cb4c3d903fa25e1a28257be9100ef21d64d 100644 --- a/common/src/main/java/org/apache/rocketmq/common/message/MessageExtBatch.java +++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageExtBatch.java @@ -6,13 +6,13 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.common.message; @@ -23,13 +23,11 @@ public class MessageExtBatch extends MessageExt { private static final long serialVersionUID = -2353110995348498537L; - public ByteBuffer wrap() { assert getBody() != null; - return ByteBuffer.wrap(getBody(), 0, getBody().length); + return ByteBuffer.wrap(getBody(), 0, getBody().length); } - private ByteBuffer encodedBuff; public ByteBuffer getEncodedBuff() { diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/RequestCode.java b/common/src/main/java/org/apache/rocketmq/common/protocol/RequestCode.java index 6f132f7cdf47254980422935580dd39f38fcde45..5900c0b9d0c314d808aa3bb9dbeaa2192753c05c 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/RequestCode.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/RequestCode.java @@ -162,7 +162,6 @@ public class RequestCode { */ public static final int GET_NAMESRV_CONFIG = 319; - public static final int SEND_BATCH_MESSAGE = 320; public static final int QUERY_CONSUME_QUEUE = 321; diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumerRunningInfo.java b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumerRunningInfo.java index 41e76fcb3c3264dbe70b4ce30912bce98279746b..d7942eb4a0a26c697abb96d1228b6a8e13655cfb 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumerRunningInfo.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/body/ConsumerRunningInfo.java @@ -130,15 +130,15 @@ public class ConsumerRunningInfo extends RemotingSerializable { if (orderMsg) { if (!pq.isLocked()) { - sb.append(String.format("%s %s can't lock for a while, %dms%n", // - clientId, // - mq, // + sb.append(String.format("%s %s can't lock for a while, %dms%n", + clientId, + mq, System.currentTimeMillis() - pq.getLastLockTimestamp())); } else { if (pq.isDroped() && (pq.getTryUnlockTimes() > 0)) { - sb.append(String.format("%s %s unlock %d times, still failed%n", // - clientId, // - mq, // + sb.append(String.format("%s %s unlock %d times, still failed%n", + clientId, + mq, pq.getTryUnlockTimes())); } } @@ -147,9 +147,9 @@ public class ConsumerRunningInfo extends RemotingSerializable { long diff = System.currentTimeMillis() - pq.getLastConsumeTimestamp(); if (diff > (1000 * 60) && pq.getCachedMsgCount() > 0) { - sb.append(String.format("%s %s can't consume for a while, maybe blocked, %dms%n", // - clientId, // - mq, // + sb.append(String.format("%s %s can't consume for a while, maybe blocked, %dms%n", + clientId, + mq, diff)); } } @@ -211,10 +211,10 @@ public class ConsumerRunningInfo extends RemotingSerializable { int i = 0; while (it.hasNext()) { SubscriptionData next = it.next(); - String item = String.format("%03d Topic: %-40s ClassFilter: %-8s SubExpression: %s%n", // - ++i, // - next.getTopic(), // - next.isClassFilterMode(), // + String item = String.format("%03d Topic: %-40s ClassFilter: %-8s SubExpression: %s%n", + ++i, + next.getTopic(), + next.isClassFilterMode(), next.getSubString()); sb.append(item); @@ -223,20 +223,20 @@ public class ConsumerRunningInfo extends RemotingSerializable { { sb.append("\n\n#Consumer Offset#\n"); - sb.append(String.format("%-32s %-32s %-4s %-20s%n", // - "#Topic", // - "#Broker Name", // - "#QID", // - "#Consumer Offset"// + sb.append(String.format("%-32s %-32s %-4s %-20s%n", + "#Topic", + "#Broker Name", + "#QID", + "#Consumer Offset" )); Iterator> it = this.mqTable.entrySet().iterator(); while (it.hasNext()) { Entry next = it.next(); - String item = String.format("%-32s %-32s %-4d %-20d%n", // - next.getKey().getTopic(), // - next.getKey().getBrokerName(), // - next.getKey().getQueueId(), // + String item = String.format("%-32s %-32s %-4d %-20d%n", + next.getKey().getTopic(), + next.getKey().getBrokerName(), + next.getKey().getQueueId(), next.getValue().getCommitOffset()); sb.append(item); @@ -245,20 +245,20 @@ public class ConsumerRunningInfo extends RemotingSerializable { { sb.append("\n\n#Consumer MQ Detail#\n"); - sb.append(String.format("%-32s %-32s %-4s %-20s%n", // - "#Topic", // - "#Broker Name", // - "#QID", // - "#ProcessQueueInfo"// + sb.append(String.format("%-32s %-32s %-4s %-20s%n", + "#Topic", + "#Broker Name", + "#QID", + "#ProcessQueueInfo" )); Iterator> it = this.mqTable.entrySet().iterator(); while (it.hasNext()) { Entry next = it.next(); - String item = String.format("%-32s %-32s %-4d %s%n", // - next.getKey().getTopic(), // - next.getKey().getBrokerName(), // - next.getKey().getQueueId(), // + String item = String.format("%-32s %-32s %-4d %s%n", + next.getKey().getTopic(), + next.getKey().getBrokerName(), + next.getKey().getQueueId(), next.getValue().toString()); sb.append(item); @@ -267,27 +267,27 @@ public class ConsumerRunningInfo extends RemotingSerializable { { sb.append("\n\n#Consumer RT&TPS#\n"); - sb.append(String.format("%-32s %14s %14s %14s %14s %18s %25s%n", // - "#Topic", // - "#Pull RT", // - "#Pull TPS", // - "#Consume RT", // - "#ConsumeOK TPS", // - "#ConsumeFailed TPS", // - "#ConsumeFailedMsgsInHour"// + sb.append(String.format("%-32s %14s %14s %14s %14s %18s %25s%n", + "#Topic", + "#Pull RT", + "#Pull TPS", + "#Consume RT", + "#ConsumeOK TPS", + "#ConsumeFailed TPS", + "#ConsumeFailedMsgsInHour" )); Iterator> it = this.statusTable.entrySet().iterator(); while (it.hasNext()) { Entry next = it.next(); - String item = String.format("%-32s %14.2f %14.2f %14.2f %14.2f %18.2f %25d%n", // - next.getKey(), // - next.getValue().getPullRT(), // - next.getValue().getPullTPS(), // - next.getValue().getConsumeRT(), // - next.getValue().getConsumeOKTPS(), // - next.getValue().getConsumeFailedTPS(), // - next.getValue().getConsumeFailedMsgs()// + String item = String.format("%-32s %14.2f %14.2f %14.2f %14.2f %18.2f %25d%n", + next.getKey(), + next.getValue().getPullRT(), + next.getValue().getPullTPS(), + next.getValue().getConsumeRT(), + next.getValue().getConsumeOKTPS(), + next.getValue().getConsumeFailedTPS(), + next.getValue().getConsumeFailedMsgs() ); sb.append(item); diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumeStatsRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumeStatsRequestHeader.java index ba6b1293443a7ea0b0a94adfe39460b18e340236..6ba069e1ffd0cdd2092b3b7f9419b8b8b96ad478 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumeStatsRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumeStatsRequestHeader.java @@ -27,8 +27,6 @@ public class GetConsumeStatsRequestHeader implements CommandCustomHeader { @Override public void checkFields() throws RemotingCommandException { - // TODO Auto-generated method stub - } public String getConsumerGroup() { diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerStatusRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerStatusRequestHeader.java index 20990a6901deeb90ebd17ffdabe19d8dc3640a37..ca26a869c60fe2fdcee729159dbab1eab35651f8 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerStatusRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetConsumerStatusRequestHeader.java @@ -32,7 +32,6 @@ public class GetConsumerStatusRequestHeader implements CommandCustomHeader { @Override public void checkFields() throws RemotingCommandException { - // TODO Auto-generated method stub } public String getTopic() { diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetEarliestMsgStoretimeRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetEarliestMsgStoretimeRequestHeader.java index 222382e947fca5d6191a5236b8f6b387eae9f0a0..c64381fb7870cdb450af2cb1c7f7b6f170c6eba7 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetEarliestMsgStoretimeRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/GetEarliestMsgStoretimeRequestHeader.java @@ -32,7 +32,6 @@ public class GetEarliestMsgStoretimeRequestHeader implements CommandCustomHeader @Override public void checkFields() throws RemotingCommandException { - // TODO Auto-generated method stub } public String getTopic() { diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryCorrectionOffsetHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryCorrectionOffsetHeader.java index 6a998d9f5bc74a07d614c32db1215aa2f2219e65..93fa722742007fa451b53aeae93ae47ff4e35f6d 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryCorrectionOffsetHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/QueryCorrectionOffsetHeader.java @@ -33,7 +33,7 @@ public class QueryCorrectionOffsetHeader implements CommandCustomHeader { @Override public void checkFields() throws RemotingCommandException { - // TODO Auto-generated method stub + } public String getFilterGroups() { diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/SearchOffsetRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/SearchOffsetRequestHeader.java index 113e46f671c9f80a4bc8dc1252408ec0a834d30c..5ea2e24bfc87a56721950b8b77d485717ec21c1e 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/SearchOffsetRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/SearchOffsetRequestHeader.java @@ -34,7 +34,6 @@ public class SearchOffsetRequestHeader implements CommandCustomHeader { @Override public void checkFields() throws RemotingCommandException { - // TODO Auto-generated method stub } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/SendMessageRequestHeaderV2.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/SendMessageRequestHeaderV2.java index 757ef0c1526d27a11d49f5be915a4e5a524519db..4e0098b5f0e435f65ad94e71e0beee8ac12966fb 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/SendMessageRequestHeaderV2.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/SendMessageRequestHeaderV2.java @@ -54,7 +54,6 @@ public class SendMessageRequestHeaderV2 implements CommandCustomHeader { @CFNullable private boolean m; //batch - public static SendMessageRequestHeader createSendMessageRequestHeaderV1(final SendMessageRequestHeaderV2 v2) { SendMessageRequestHeader v1 = new SendMessageRequestHeader(); v1.setProducerGroup(v2.a); diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/UnregisterClientRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/UnregisterClientRequestHeader.java index 082329c04bf2937dbea5fe6c0393efdf1fc16fc2..bb0a462917083d625ab36a4e34f48cca26631aaf 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/UnregisterClientRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/UnregisterClientRequestHeader.java @@ -57,7 +57,6 @@ public class UnregisterClientRequestHeader implements CommandCustomHeader { @Override public void checkFields() throws RemotingCommandException { - // TODO Auto-generated method stub } } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/UnregisterClientResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/UnregisterClientResponseHeader.java index 6ae69294ce545ecfdcd0d30815c738b6b3d3cfd6..38fb87a6e231da7da610e4f6c43ed11bb3529922 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/UnregisterClientResponseHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/UnregisterClientResponseHeader.java @@ -24,7 +24,6 @@ public class UnregisterClientResponseHeader implements CommandCustomHeader { @Override public void checkFields() throws RemotingCommandException { - // TODO Auto-generated method stub } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetRouteInfoResponseHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetRouteInfoResponseHeader.java deleted file mode 100644 index 64081eadb228df25ae19527bf650b1494e6fd36a..0000000000000000000000000000000000000000 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/GetRouteInfoResponseHeader.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * $Id: GetRouteInfoResponseHeader.java 1835 2013-05-16 02:00:50Z vintagewang@apache.org $ - */ -package org.apache.rocketmq.common.protocol.header.namesrv; - -import org.apache.rocketmq.remoting.CommandCustomHeader; -import org.apache.rocketmq.remoting.exception.RemotingCommandException; - -public class GetRouteInfoResponseHeader implements CommandCustomHeader { - - @Override - public void checkFields() throws RemotingCommandException { - // TODO Auto-generated method stub - - } -} diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/RegisterOrderTopicRequestHeader.java b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/RegisterOrderTopicRequestHeader.java index 93069feda3b4f197c1b70c046e199db7053dc5dc..8307e20b712b8ce1791fa6d71b79c9990c62a3dd 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/RegisterOrderTopicRequestHeader.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/header/namesrv/RegisterOrderTopicRequestHeader.java @@ -32,7 +32,7 @@ public class RegisterOrderTopicRequestHeader implements CommandCustomHeader { @Override public void checkFields() throws RemotingCommandException { - // TODO Auto-generated method stub + } public String getTopic() { diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/MessageModel.java b/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/MessageModel.java index ff94bb4496da333b21711bad7ac29d0c308e501e..defe676f6ea42ff11ef3f5b5f946617c0ab6b080 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/MessageModel.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/heartbeat/MessageModel.java @@ -22,7 +22,6 @@ package org.apache.rocketmq.common.protocol.heartbeat; /** * Message model - * */ public enum MessageModel { /** diff --git a/common/src/main/java/org/apache/rocketmq/common/sysflag/TopicSysFlag.java b/common/src/main/java/org/apache/rocketmq/common/sysflag/TopicSysFlag.java index 9966a90f7720358a5b70b78d7423183dcf0438fe..cc23ff1a3f359e080ce65e2a5c7d5096ca62fb55 100644 --- a/common/src/main/java/org/apache/rocketmq/common/sysflag/TopicSysFlag.java +++ b/common/src/main/java/org/apache/rocketmq/common/sysflag/TopicSysFlag.java @@ -16,11 +16,6 @@ */ package org.apache.rocketmq.common.sysflag; -/** - - * - * - */ public class TopicSysFlag { private final static int FLAG_UNIT = 0x1 << 0; diff --git a/common/src/main/java/org/apache/rocketmq/common/utils/HttpTinyClient.java b/common/src/main/java/org/apache/rocketmq/common/utils/HttpTinyClient.java index 37bf999f9bc837fecb20c53b7e428ae50c5ca781..85afc0ac678ee7e2451349e7d3f3990457152aac 100755 --- a/common/src/main/java/org/apache/rocketmq/common/utils/HttpTinyClient.java +++ b/common/src/main/java/org/apache/rocketmq/common/utils/HttpTinyClient.java @@ -90,13 +90,7 @@ public class HttpTinyClient { } /** - * @param url - * @param headers - * @param paramValues - * @param encoding - * @param readTimeoutMs * @return the http response of given http post request - * @throws java.io.IOException */ static public HttpResult httpPost(String url, List headers, List paramValues, String encoding, long readTimeoutMs) throws IOException { diff --git a/common/src/main/java/org/apache/rocketmq/common/utils/IOTinyUtils.java b/common/src/main/java/org/apache/rocketmq/common/utils/IOTinyUtils.java index 28ead5cd107d4db6816e2c9d0ff9e11551660da6..5ed82ae6e67cb2e9a590aafbcb431f4e85acdfbf 100644 --- a/common/src/main/java/org/apache/rocketmq/common/utils/IOTinyUtils.java +++ b/common/src/main/java/org/apache/rocketmq/common/utils/IOTinyUtils.java @@ -60,7 +60,7 @@ public class IOTinyUtils { BufferedReader reader = toBufferedReader(input); List list = new ArrayList(); String line; - for (;;) { + for (; ; ) { line = reader.readLine(); if (null != line) { list.add(line); @@ -114,9 +114,6 @@ public class IOTinyUtils { fileOrDir.delete(); } - /** - - */ public static void cleanDirectory(File directory) throws IOException { if (!directory.exists()) { String message = directory + " does not exist"; diff --git a/common/src/test/java/org/apache/rocketmq/common/MQVersionTest.java b/common/src/test/java/org/apache/rocketmq/common/MQVersionTest.java index ac6269f3b8871730df53fcd0beb1661248497e0d..51856b849e36f17e2927eb81471910f8da8e0942 100644 --- a/common/src/test/java/org/apache/rocketmq/common/MQVersionTest.java +++ b/common/src/test/java/org/apache/rocketmq/common/MQVersionTest.java @@ -18,6 +18,7 @@ package org.apache.rocketmq.common; import org.junit.Test; + import static org.assertj.core.api.Assertions.assertThat; public class MQVersionTest { @@ -39,7 +40,6 @@ public class MQVersionTest { assertThat(MQVersion.value2Version(0)).isEqualTo(MQVersion.Version.V3_0_0_SNAPSHOT); } - @Test public void testValue2Version_HigherVersion() throws Exception { assertThat(MQVersion.value2Version(Integer.MAX_VALUE)).isEqualTo(MQVersion.Version.HIGHER_VERSION); diff --git a/common/src/test/java/org/apache/rocketmq/common/MessageBatchTest.java b/common/src/test/java/org/apache/rocketmq/common/MessageBatchTest.java index 1e406d2f64ce704bcdcc9526f554361194c8005e..f264420760b45c8a504c19cc033c0cd8184a572f 100644 --- a/common/src/test/java/org/apache/rocketmq/common/MessageBatchTest.java +++ b/common/src/test/java/org/apache/rocketmq/common/MessageBatchTest.java @@ -25,7 +25,6 @@ import org.junit.Test; public class MessageBatchTest { - public List generateMessages() { List messages = new ArrayList(); Message message1 = new Message("topic1", "body".getBytes()); @@ -37,32 +36,34 @@ public class MessageBatchTest { } @Test - public void testGenerate_OK() throws Exception{ + public void testGenerate_OK() throws Exception { List messages = generateMessages(); MessageBatch.generateFromList(messages); } @Test(expected = UnsupportedOperationException.class) - public void testGenerate_DiffTopic() throws Exception{ + public void testGenerate_DiffTopic() throws Exception { List messages = generateMessages(); messages.get(1).setTopic("topic2"); MessageBatch.generateFromList(messages); } @Test(expected = UnsupportedOperationException.class) - public void testGenerate_DiffWaitOK() throws Exception{ + public void testGenerate_DiffWaitOK() throws Exception { List messages = generateMessages(); messages.get(1).setWaitStoreMsgOK(false); MessageBatch.generateFromList(messages); } + @Test(expected = UnsupportedOperationException.class) - public void testGenerate_Delay() throws Exception{ + public void testGenerate_Delay() throws Exception { List messages = generateMessages(); messages.get(1).setDelayTimeLevel(1); MessageBatch.generateFromList(messages); } + @Test(expected = UnsupportedOperationException.class) - public void testGenerate_Retry() throws Exception{ + public void testGenerate_Retry() throws Exception { List messages = generateMessages(); messages.get(1).setTopic(MixAll.RETRY_GROUP_TOPIC_PREFIX + "topic"); MessageBatch.generateFromList(messages); diff --git a/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java b/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java index 218b36d2d8be12880458bebba521eb42d8ce18af..3f0487202f04c13485ea165280c3f71583e52efa 100644 --- a/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java +++ b/common/src/test/java/org/apache/rocketmq/common/MixAllTest.java @@ -17,17 +17,14 @@ package org.apache.rocketmq.common; +import org.junit.Test; + import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.net.InetAddress; -import java.nio.ByteOrder; -import java.nio.CharBuffer; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.util.List; import java.util.concurrent.atomic.AtomicLong; -import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -93,4 +90,10 @@ public class MixAllTest { MixAll.string2File("MixAll_testString2File", fileName); assertThat(MixAll.file2String(fileName)).isEqualTo("MixAll_testString2File"); } + + @Test + public void testGetLocalhostByNetworkInterface() throws Exception { + assertThat(MixAll.LOCALHOST).isNotNull(); + assertThat(MixAll.getLocalhostByNetworkInterface()).isNotNull(); + } } diff --git a/common/src/test/java/org/apache/rocketmq/common/filter/FilterAPITest.java b/common/src/test/java/org/apache/rocketmq/common/filter/FilterAPITest.java index c5f8460eeb3467c166423d9bb3465780f441ba04..73ab09e61c4cd8ac5b4524815506af316c340b80 100644 --- a/common/src/test/java/org/apache/rocketmq/common/filter/FilterAPITest.java +++ b/common/src/test/java/org/apache/rocketmq/common/filter/FilterAPITest.java @@ -17,11 +17,12 @@ package org.apache.rocketmq.common.filter; -import java.util.HashSet; -import java.util.Set; import org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData; import org.junit.Test; +import java.util.HashSet; +import java.util.Set; + import static org.assertj.core.api.Assertions.assertThat; public class FilterAPITest { @@ -32,10 +33,10 @@ public class FilterAPITest { @Test public void testBuildSubscriptionData() throws Exception { SubscriptionData subscriptionData = - FilterAPI.buildSubscriptionData(group, topic, subString); + FilterAPI.buildSubscriptionData(group, topic, subString); assertThat(subscriptionData.getTopic()).isEqualTo(topic); assertThat(subscriptionData.getSubString()).isEqualTo(subString); - String [] tags = subString.split("\\|\\|"); + String[] tags = subString.split("\\|\\|"); Set tagSet = new HashSet(); for (String tag : tags) { tagSet.add(tag.trim()); @@ -47,7 +48,7 @@ public class FilterAPITest { public void testBuildTagSome() { try { SubscriptionData subscriptionData = FilterAPI.build( - "TOPIC", "A || B", ExpressionType.TAG + "TOPIC", "A || B", ExpressionType.TAG ); assertThat(subscriptionData).isNotNull(); @@ -67,7 +68,7 @@ public class FilterAPITest { public void testBuildSQL() { try { SubscriptionData subscriptionData = FilterAPI.build( - "TOPIC", "a is not null", ExpressionType.SQL92 + "TOPIC", "a is not null", ExpressionType.SQL92 ); assertThat(subscriptionData).isNotNull(); @@ -79,16 +80,8 @@ public class FilterAPITest { } } - @Test - public void testBuildSQLWithNullSubString() { - try { - FilterAPI.build( - "TOPIC", null, ExpressionType.SQL92 - ); - - assertThat(Boolean.FALSE).isTrue(); - } catch (Exception e) { - e.printStackTrace(); - } + @Test(expected = IllegalArgumentException.class) + public void testBuildSQLWithNullSubString() throws Exception { + FilterAPI.build("TOPIC", null, ExpressionType.SQL92); } } diff --git a/common/src/test/java/org/apache/rocketmq/common/protocol/route/BrokerDataTest.java b/common/src/test/java/org/apache/rocketmq/common/protocol/route/BrokerDataTest.java deleted file mode 100644 index 97da458da77f41371cd749ca728631f9e909e165..0000000000000000000000000000000000000000 --- a/common/src/test/java/org/apache/rocketmq/common/protocol/route/BrokerDataTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.rocketmq.common.protocol.route; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * BrokerData tests. - */ -public class BrokerDataTest { - private static BrokerData brokerData; - - @BeforeClass - public static void prepare() { - brokerData = new BrokerData("testCluster", "testBroker", - new HashMap() {{ - put(1L, "addr1"); - put(2L, "addr2"); - put(3L, "addr3"); - }}); - } - - @Test - public void selectBrokerAddr() throws Exception { - List selectedAddr = new ArrayList(); - - for (int i = 0; i < 5; i++) - selectedAddr.add(brokerData.selectBrokerAddr()); - - List firstElemList = new ArrayList(); - - for (int i = 0; i < 5; i++) - firstElemList.add(selectedAddr.get(0)); - - Assert.assertFalse("Contains same addresses", selectedAddr.equals(firstElemList)); - } -} diff --git a/benchmark/consumer.sh b/distribution/benchmark/consumer.sh similarity index 100% rename from benchmark/consumer.sh rename to distribution/benchmark/consumer.sh diff --git a/benchmark/producer.sh b/distribution/benchmark/producer.sh similarity index 100% rename from benchmark/producer.sh rename to distribution/benchmark/producer.sh diff --git a/benchmark/runclass.sh b/distribution/benchmark/runclass.sh similarity index 100% rename from benchmark/runclass.sh rename to distribution/benchmark/runclass.sh diff --git a/benchmark/tproducer.sh b/distribution/benchmark/tproducer.sh similarity index 100% rename from benchmark/tproducer.sh rename to distribution/benchmark/tproducer.sh diff --git a/distribution/bin/mqadmin.xml b/distribution/bin/mqadmin.xml index d014743179ecc81de2237f76dba26a7de5ba4007..0f07da414e20742984a2f0d56af8cc72b50c2053 100644 --- a/distribution/bin/mqadmin.xml +++ b/distribution/bin/mqadmin.xml @@ -16,28 +16,28 @@ --> - false + false - ${JAVA_HOME} + ${JAVA_HOME} - server + server - org.apache.rocketmq.tools.command.MQAdminStartup + org.apache.rocketmq.tools.command.MQAdminStartup - - ${cpd}/../lib - ${cpd}/.. - + + ${cpd}/../lib + ${cpd}/.. + - - + + - - <-Xms512m> - <-Xmx1g> - <-XX:NewSize>256M - <-XX:MaxNewSize>512M - <-XX:PermSize>128M - <-XX:MaxPermSize>128M - + + <-Xms512m> + <-Xmx1g> + <-XX:NewSize>256M + <-XX:MaxNewSize>512M + <-XX:PermSize>128M + <-XX:MaxPermSize>128M + diff --git a/distribution/bin/mqbroker.xml b/distribution/bin/mqbroker.xml index d1bc16fe4c427d1287f6d940be2f2ed81c8c15b8..3043cc0f8d07c065b204da0cbcbe0ba8f6a281ca 100644 --- a/distribution/bin/mqbroker.xml +++ b/distribution/bin/mqbroker.xml @@ -16,28 +16,30 @@ --> - false + false - ${JAVA_HOME} + ${JAVA_HOME} - server + server - org.apache.rocketmq.broker.BrokerStartup + org.apache.rocketmq.broker.BrokerStartup - - ${cpd}/../lib - ${cpd}/.. - + + ${cpd}/../lib + ${cpd}/.. + - - + + - - <-Xms512m> - <-Xmx1g> - <-XX:NewSize>256M - <-XX:MaxNewSize>512M - <-XX:PermSize>128M - <-XX:MaxPermSize>128M - - + + <-Xms512m> + + <-Xmx1g> + +<-XX:NewSize>256M +<-XX:MaxNewSize>512M +<-XX:PermSize>128M +<-XX:MaxPermSize>128M + + diff --git a/distribution/bin/mqfiltersrv.xml b/distribution/bin/mqfiltersrv.xml index 8fdea394c95bcad1d1816126f0c81b97602989d8..dc36a8d8c1e21899e0d5f84ac10d6dfb2fa56287 100644 --- a/distribution/bin/mqfiltersrv.xml +++ b/distribution/bin/mqfiltersrv.xml @@ -16,28 +16,30 @@ --> - false + false - ${JAVA_HOME} + ${JAVA_HOME} - server + server - org.apache.rocketmq.filtersrv.FiltersrvStartup + org.apache.rocketmq.filtersrv.FiltersrvStartup - - ${cpd}/../lib - ${cpd}/.. - + + ${cpd}/../lib + ${cpd}/.. + - - + + - - <-Xms512m> - <-Xmx1g> - <-XX:NewSize>256M - <-XX:MaxNewSize>512M - <-XX:PermSize>128M - <-XX:MaxPermSize>128M - - + + <-Xms512m> + + <-Xmx1g> + +<-XX:NewSize>256M +<-XX:MaxNewSize>512M +<-XX:PermSize>128M +<-XX:MaxPermSize>128M + + diff --git a/distribution/bin/mqnamesrv.xml b/distribution/bin/mqnamesrv.xml index dc5736adc26f68dd4d8f4c629a18a777efd62dd3..1f050d145d71982d902865ae5492c0ba933b7496 100644 --- a/distribution/bin/mqnamesrv.xml +++ b/distribution/bin/mqnamesrv.xml @@ -16,28 +16,30 @@ --> - false + false - ${JAVA_HOME} + ${JAVA_HOME} - server + server - org.apache.rocketmq.namesrv.NamesrvStartup + org.apache.rocketmq.namesrv.NamesrvStartup - - ${cpd}/../lib - ${cpd}/.. - + + ${cpd}/../lib + ${cpd}/.. + - - + + - - <-Xms512m> - <-Xmx1g> - <-XX:NewSize>256M - <-XX:MaxNewSize>512M - <-XX:PermSize>128M - <-XX:MaxPermSize>128M - - + + <-Xms512m> + + <-Xmx1g> + +<-XX:NewSize>256M +<-XX:MaxNewSize>512M +<-XX:PermSize>128M +<-XX:MaxPermSize>128M + + diff --git a/distribution/conf/2m-2s-async/broker-a-s.properties b/distribution/conf/2m-2s-async/broker-a-s.properties index 10d1555b54a3837616273cace503eb352dfff046..0e3388b8f8c4f05ee58a530d9b3a825025512056 100644 --- a/distribution/conf/2m-2s-async/broker-a-s.properties +++ b/distribution/conf/2m-2s-async/broker-a-s.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-a brokerId=1 diff --git a/distribution/conf/2m-2s-async/broker-a.properties b/distribution/conf/2m-2s-async/broker-a.properties index da6fc5f6e4388b421c60d61d18cbfe9ff2473959..b704b54c54c72349238ec0f00bea1f5b4c9b7d20 100644 --- a/distribution/conf/2m-2s-async/broker-a.properties +++ b/distribution/conf/2m-2s-async/broker-a.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-a brokerId=0 diff --git a/distribution/conf/2m-2s-async/broker-b-s.properties b/distribution/conf/2m-2s-async/broker-b-s.properties index 9fbe0880da3ea1986d39002bfd65c1dfb68f5722..6c6beab2448a0140681ade0dd6fb8d7e50edd88b 100644 --- a/distribution/conf/2m-2s-async/broker-b-s.properties +++ b/distribution/conf/2m-2s-async/broker-b-s.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-b brokerId=1 diff --git a/distribution/conf/2m-2s-async/broker-b.properties b/distribution/conf/2m-2s-async/broker-b.properties index cb09f9de8e82a01c44a7db1edd0de68316b0fdf1..130671a7c319eaf8d3b98e62845bedbb3296a291 100644 --- a/distribution/conf/2m-2s-async/broker-b.properties +++ b/distribution/conf/2m-2s-async/broker-b.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-b brokerId=0 diff --git a/distribution/conf/2m-2s-sync/broker-a-s.properties b/distribution/conf/2m-2s-sync/broker-a-s.properties index 10d1555b54a3837616273cace503eb352dfff046..0e3388b8f8c4f05ee58a530d9b3a825025512056 100644 --- a/distribution/conf/2m-2s-sync/broker-a-s.properties +++ b/distribution/conf/2m-2s-sync/broker-a-s.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-a brokerId=1 diff --git a/distribution/conf/2m-2s-sync/broker-a.properties b/distribution/conf/2m-2s-sync/broker-a.properties index 82c4631185420a9f2f730ac0ac362cf3356c054e..fba30fa1ab611918d01336a1991a82e4ca8e4d0a 100644 --- a/distribution/conf/2m-2s-sync/broker-a.properties +++ b/distribution/conf/2m-2s-sync/broker-a.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-a brokerId=0 diff --git a/distribution/conf/2m-2s-sync/broker-b-s.properties b/distribution/conf/2m-2s-sync/broker-b-s.properties index 9fbe0880da3ea1986d39002bfd65c1dfb68f5722..6c6beab2448a0140681ade0dd6fb8d7e50edd88b 100644 --- a/distribution/conf/2m-2s-sync/broker-b-s.properties +++ b/distribution/conf/2m-2s-sync/broker-b-s.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-b brokerId=1 diff --git a/distribution/conf/2m-2s-sync/broker-b.properties b/distribution/conf/2m-2s-sync/broker-b.properties index 29a42646153e0c715c344fad5ba2ed1475249a7e..ab925a816964b1035ddb64245b6ac2d73db6051b 100644 --- a/distribution/conf/2m-2s-sync/broker-b.properties +++ b/distribution/conf/2m-2s-sync/broker-b.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-b brokerId=0 diff --git a/distribution/conf/2m-noslave/broker-a.properties b/distribution/conf/2m-noslave/broker-a.properties index da6fc5f6e4388b421c60d61d18cbfe9ff2473959..b704b54c54c72349238ec0f00bea1f5b4c9b7d20 100644 --- a/distribution/conf/2m-noslave/broker-a.properties +++ b/distribution/conf/2m-noslave/broker-a.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-a brokerId=0 diff --git a/distribution/conf/2m-noslave/broker-b.properties b/distribution/conf/2m-noslave/broker-b.properties index cb09f9de8e82a01c44a7db1edd0de68316b0fdf1..130671a7c319eaf8d3b98e62845bedbb3296a291 100644 --- a/distribution/conf/2m-noslave/broker-b.properties +++ b/distribution/conf/2m-noslave/broker-b.properties @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - brokerClusterName=DefaultCluster brokerName=broker-b brokerId=0 diff --git a/distribution/conf/logback_broker.xml b/distribution/conf/logback_broker.xml index 3945fac388ecf0937dd2b401fc24b31b7a363357..56c9ac64ee813226519a66fbdb2c3a943bc2dcc6 100644 --- a/distribution/conf/logback_broker.xml +++ b/distribution/conf/logback_broker.xml @@ -233,7 +233,7 @@ 10 + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> 100MB @@ -350,8 +350,8 @@ - - + + diff --git a/example/src/main/java/org/apache/rocketmq/example/batch/SimpleBatchProducer.java b/example/src/main/java/org/apache/rocketmq/example/batch/SimpleBatchProducer.java index a8609e793fadc0c3813cf573048fc87ccd06af6b..cf566aa15bd0d58f629ff879a96921acd71c9ad0 100644 --- a/example/src/main/java/org/apache/rocketmq/example/batch/SimpleBatchProducer.java +++ b/example/src/main/java/org/apache/rocketmq/example/batch/SimpleBatchProducer.java @@ -24,8 +24,7 @@ import org.apache.rocketmq.common.message.Message; public class SimpleBatchProducer { - - public static void main(String[] args) throws Exception { + public static void main(String[] args) throws Exception { DefaultMQProducer producer = new DefaultMQProducer("BatchProducerGroupName"); producer.start(); diff --git a/example/src/main/java/org/apache/rocketmq/example/batch/SplitBatchProducer.java b/example/src/main/java/org/apache/rocketmq/example/batch/SplitBatchProducer.java index 8809a11512c5366e0bb76948e1375a65464d20e2..f9495c4171481bc324f10bd36f00cb9b756de4c4 100644 --- a/example/src/main/java/org/apache/rocketmq/example/batch/SplitBatchProducer.java +++ b/example/src/main/java/org/apache/rocketmq/example/batch/SplitBatchProducer.java @@ -26,7 +26,7 @@ import org.apache.rocketmq.common.message.Message; public class SplitBatchProducer { - public static void main(String[] args) throws Exception { + public static void main(String[] args) throws Exception { DefaultMQProducer producer = new DefaultMQProducer("BatchProducerGroupName"); producer.start(); @@ -41,25 +41,29 @@ public class SplitBatchProducer { //split the large batch into small ones: ListSplitter splitter = new ListSplitter(messages); while (splitter.hasNext()) { - List listItem = splitter.next(); + List listItem = splitter.next(); producer.send(listItem); } } } - class ListSplitter implements Iterator> { private int sizeLimit = 1000 * 1000; private final List messages; private int currIndex; + public ListSplitter(List messages) { this.messages = messages; } - @Override public boolean hasNext() { + + @Override + public boolean hasNext() { return currIndex < messages.size(); } - @Override public List next() { + + @Override + public List next() { int nextIndex = currIndex; int totalSize = 0; for (; nextIndex < messages.size(); nextIndex++) { @@ -91,7 +95,8 @@ class ListSplitter implements Iterator> { return subList; } - @Override public void remove() { + @Override + public void remove() { throw new UnsupportedOperationException("Not allowed to remove"); } } diff --git a/example/src/main/java/org/apache/rocketmq/example/benchmark/Producer.java b/example/src/main/java/org/apache/rocketmq/example/benchmark/Producer.java index 2d8d0f6fa185915d1a5128070ba2a6ec3af44934..9bd526628300fcf84ac7bfe4d110ffe93386b71f 100644 --- a/example/src/main/java/org/apache/rocketmq/example/benchmark/Producer.java +++ b/example/src/main/java/org/apache/rocketmq/example/benchmark/Producer.java @@ -242,7 +242,7 @@ class StatsBenchmarkProducer { private final AtomicLong sendMessageMaxRT = new AtomicLong(0L); public Long[] createSnapshot() { - Long[] snap = new Long[]{ + Long[] snap = new Long[] { System.currentTimeMillis(), this.sendRequestSuccessCount.get(), this.sendRequestFailedCount.get(), diff --git a/example/src/main/java/org/apache/rocketmq/example/filter/SqlConsumer.java b/example/src/main/java/org/apache/rocketmq/example/filter/SqlConsumer.java index 52c2474103eefd2abe0974d4cb7de9e62cdf722e..8421675ced27d31f6b1109aa1e2c5ad1607026d6 100644 --- a/example/src/main/java/org/apache/rocketmq/example/filter/SqlConsumer.java +++ b/example/src/main/java/org/apache/rocketmq/example/filter/SqlConsumer.java @@ -44,7 +44,7 @@ public class SqlConsumer { @Override public ConsumeConcurrentlyStatus consumeMessage(List msgs, - ConsumeConcurrentlyContext context) { + ConsumeConcurrentlyContext context) { System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n"); return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } diff --git a/example/src/main/java/org/apache/rocketmq/example/simple/AsyncProducer.java b/example/src/main/java/org/apache/rocketmq/example/simple/AsyncProducer.java index 038ea65ad09931340f3336007f6e415d69332371..aa15cafff2d307a7a7c69fa546cdff401a3f1ed2 100644 --- a/example/src/main/java/org/apache/rocketmq/example/simple/AsyncProducer.java +++ b/example/src/main/java/org/apache/rocketmq/example/simple/AsyncProducer.java @@ -25,7 +25,8 @@ import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.remoting.common.RemotingHelper; public class AsyncProducer { - public static void main(String[] args) throws MQClientException, InterruptedException, UnsupportedEncodingException { + public static void main( + String[] args) throws MQClientException, InterruptedException, UnsupportedEncodingException { DefaultMQProducer producer = new DefaultMQProducer("Jodie_Daily_test"); producer.start(); diff --git a/example/src/main/java/org/apache/rocketmq/example/simple/PushConsumer.java b/example/src/main/java/org/apache/rocketmq/example/simple/PushConsumer.java index c8252d03caa0de902c26afc5ad293a38de8cab90..43bbf6c36b59618e327fa86a67b48ac92bb2b81b 100644 --- a/example/src/main/java/org/apache/rocketmq/example/simple/PushConsumer.java +++ b/example/src/main/java/org/apache/rocketmq/example/simple/PushConsumer.java @@ -35,9 +35,6 @@ public class PushConsumer { consumer.setConsumeTimestamp("20170422221800"); consumer.registerMessageListener(new MessageListenerConcurrently() { - /** - - */ @Override public ConsumeConcurrentlyStatus consumeMessage(List msgs, ConsumeConcurrentlyContext context) { System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n"); diff --git a/example/src/main/resources/MessageFilterImpl.java b/example/src/main/resources/MessageFilterImpl.java index 23e4a79b942aefeae014e3222f291c69ccb93e50..6cb5d158a385f409cc1ae9862400a9524ff10678 100644 --- a/example/src/main/resources/MessageFilterImpl.java +++ b/example/src/main/resources/MessageFilterImpl.java @@ -28,7 +28,7 @@ public class MessageFilterImpl implements MessageFilter { String property = msg.getProperty("SequenceId"); if (property != null) { int id = Integer.parseInt(property); - if (((id % 10) == 0) && // + if (((id % 10) == 0) && (id > 100)) { return true; } diff --git a/filter/src/main/java/org/apache/rocketmq/filter/FilterFactory.java b/filter/src/main/java/org/apache/rocketmq/filter/FilterFactory.java index a31854840c7ccab060825c2e9b9756f5d51ccb7c..f1e1c7d73faa8f2c5002a798257f5f3b509a4cbc 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/FilterFactory.java +++ b/filter/src/main/java/org/apache/rocketmq/filter/FilterFactory.java @@ -38,8 +38,6 @@ public class FilterFactory { *
    * Note: *
  • 1. Filter registered will be used in broker server, so take care of it's reliability and performance.
  • - * - * @param filterSpi */ public void register(FilterSpi filterSpi) { if (FILTER_SPI_HOLDER.containsKey(filterSpi.ofType())) { @@ -51,9 +49,6 @@ public class FilterFactory { /** * Un register a filter. - * - * @param type - * @return */ public FilterSpi unRegister(String type) { return FILTER_SPI_HOLDER.remove(type); @@ -61,9 +56,6 @@ public class FilterFactory { /** * Get a filter registered, null if none exist. - * - * @param type - * @return */ public FilterSpi get(String type) { return FILTER_SPI_HOLDER.get(type); diff --git a/filter/src/main/java/org/apache/rocketmq/filter/FilterSpi.java b/filter/src/main/java/org/apache/rocketmq/filter/FilterSpi.java index fcc39fac6077096cd0a4e67c4680af1cd1819730..f2d9f1c223b1dc69bf3b4587e89f17a81ff31c2b 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/FilterSpi.java +++ b/filter/src/main/java/org/apache/rocketmq/filter/FilterSpi.java @@ -27,17 +27,11 @@ public interface FilterSpi { /** * Compile. - * - * @param expr - * @return - * @throws org.apache.rocketmq.filter.expression.MQFilterException */ Expression compile(final String expr) throws MQFilterException; /** * Which type. - * - * @return */ String ofType(); } diff --git a/filter/src/main/java/org/apache/rocketmq/filter/expression/BinaryExpression.java b/filter/src/main/java/org/apache/rocketmq/filter/expression/BinaryExpression.java index 0f172e305f9f67a0d3f49fd7bfdd2a825657c034..a3bf66b48ec82a158b064a9e621508f41f3b6bb2 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/expression/BinaryExpression.java +++ b/filter/src/main/java/org/apache/rocketmq/filter/expression/BinaryExpression.java @@ -69,8 +69,6 @@ public abstract class BinaryExpression implements Expression { /** * Returns the symbol that represents this binary expression. For example, addition is * represented by "+" - * - * @return */ public abstract String getExpressionSymbol(); diff --git a/filter/src/main/java/org/apache/rocketmq/filter/expression/BooleanExpression.java b/filter/src/main/java/org/apache/rocketmq/filter/expression/BooleanExpression.java index bb54632e640df17527f211d7c72eb872aa04ccbf..068b362e2bc324d0b2dbdc4608c68a75a92ddcd7 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/expression/BooleanExpression.java +++ b/filter/src/main/java/org/apache/rocketmq/filter/expression/BooleanExpression.java @@ -30,9 +30,7 @@ package org.apache.rocketmq.filter.expression; public interface BooleanExpression extends Expression { /** - * @param context * @return true if the expression evaluates to Boolean.TRUE. - * @throws Exception */ boolean matches(EvaluationContext context) throws Exception; diff --git a/filter/src/main/java/org/apache/rocketmq/filter/expression/ComparisonExpression.java b/filter/src/main/java/org/apache/rocketmq/filter/expression/ComparisonExpression.java index 8b82e5739775fdd15ac241194f77c0e70e29e474..fe898e7884862b30677db773a5d724335e3980e1 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/expression/ComparisonExpression.java +++ b/filter/src/main/java/org/apache/rocketmq/filter/expression/ComparisonExpression.java @@ -203,8 +203,6 @@ public abstract class ComparisonExpression extends BinaryExpression implements B /** * Only Numeric expressions can be used in >, >=, < or <= expressions.s - * - * @param expr */ public static void checkLessThanOperand(Expression expr) { if (expr instanceof ConstantExpression) { @@ -224,8 +222,6 @@ public abstract class ComparisonExpression extends BinaryExpression implements B /** * Validates that the expression can be used in == or <> expression. Cannot * not be NULL TRUE or FALSE litterals. - * - * @param expr */ public static void checkEqualOperand(Expression expr) { if (expr instanceof ConstantExpression) { diff --git a/filter/src/main/java/org/apache/rocketmq/filter/expression/ConstantExpression.java b/filter/src/main/java/org/apache/rocketmq/filter/expression/ConstantExpression.java index ca70f51a8e13b4a62a42da9fdad5ffb7e0777d94..e649f5a2328119756d6235bf7d1e67feb0ccf998 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/expression/ConstantExpression.java +++ b/filter/src/main/java/org/apache/rocketmq/filter/expression/ConstantExpression.java @@ -136,8 +136,6 @@ public class ConstantExpression implements Expression { /** * Encodes the value of string so that it looks like it would look like when * it was provided in a selector. - * - * @return */ public static String encodeString(String s) { StringBuffer b = new StringBuffer(); diff --git a/filter/src/main/java/org/apache/rocketmq/filter/expression/EvaluationContext.java b/filter/src/main/java/org/apache/rocketmq/filter/expression/EvaluationContext.java index 094ef53ce36e583737cc9bcab2e570ef73b22b40..1bea15b8788ca66a804f3973907ef554b8795533 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/expression/EvaluationContext.java +++ b/filter/src/main/java/org/apache/rocketmq/filter/expression/EvaluationContext.java @@ -28,16 +28,11 @@ public interface EvaluationContext { /** * Get value by name from context - * - * @param name - * @return */ Object get(String name); /** * Context variables. - * - * @return */ Map keyValues(); } diff --git a/filter/src/main/java/org/apache/rocketmq/filter/expression/UnaryExpression.java b/filter/src/main/java/org/apache/rocketmq/filter/expression/UnaryExpression.java index 0519f4d56d630e2a0ed0b88ad95c5da57589914c..24845fc058952bf5556372be7e0af8207016da13 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/expression/UnaryExpression.java +++ b/filter/src/main/java/org/apache/rocketmq/filter/expression/UnaryExpression.java @@ -71,7 +71,7 @@ public abstract class UnaryExpression implements Expression { } public static BooleanExpression createInExpression(PropertyExpression right, List elements, - final boolean not) { + final boolean not) { // Use a HashSet if there are many elements. Collection t; @@ -259,8 +259,6 @@ public abstract class UnaryExpression implements Expression { /** * Returns the symbol that represents this binary expression. For example, * addition is represented by "+" - * - * @return */ public abstract String getExpressionSymbol(); diff --git a/filter/src/main/java/org/apache/rocketmq/filter/expression/UnaryInExpression.java b/filter/src/main/java/org/apache/rocketmq/filter/expression/UnaryInExpression.java index a6cf1730084c5fea2fc341b41f5933be60e1f622..653cd92170acb3dd6e048ae783fd1afc047746ea 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/expression/UnaryInExpression.java +++ b/filter/src/main/java/org/apache/rocketmq/filter/expression/UnaryInExpression.java @@ -31,7 +31,7 @@ abstract public class UnaryInExpression extends UnaryExpression implements Boole private Collection inList; public UnaryInExpression(Expression left, UnaryType unaryType, - Collection inList, boolean not) { + Collection inList, boolean not) { super(left, unaryType); this.setInList(inList); this.setNot(not); diff --git a/filter/src/main/java/org/apache/rocketmq/filter/parser/ParseException.java b/filter/src/main/java/org/apache/rocketmq/filter/parser/ParseException.java index 2ccccaf5547f3bfde72ea3fd4416f92f481fc700..06014cbcbed6e0a8d2e521c5ae05c575dcb991f5 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/parser/ParseException.java +++ b/filter/src/main/java/org/apache/rocketmq/filter/parser/ParseException.java @@ -44,8 +44,8 @@ public class ParseException extends Exception { * "expectedTokenSequences", and "TOKEN_IMAGE" set. */ public ParseException(Token currentTokenVal, - int[][] expectedTokenSequencesVal, - String[] tokenImageVal + int[][] expectedTokenSequencesVal, + String[] tokenImageVal ) { super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); currentToken = currentTokenVal; @@ -103,8 +103,8 @@ public class ParseException extends Exception { * gets displayed. */ private static String initialise(Token currentToken, - int[][] expectedTokenSequences, - String[] tokenImage) { + int[][] expectedTokenSequences, + String[] tokenImage) { String eol = System.getProperty("line.separator", "\n"); StringBuffer expected = new StringBuffer(); int maxSize = 0; diff --git a/filter/src/main/java/org/apache/rocketmq/filter/parser/SelectorParser.java b/filter/src/main/java/org/apache/rocketmq/filter/parser/SelectorParser.java index 74e5501beeb0de06cecf7e7103b15b5eaa8e82c5..198aacf83e20c81ea470451214d96925a8a32b29 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/parser/SelectorParser.java +++ b/filter/src/main/java/org/apache/rocketmq/filter/parser/SelectorParser.java @@ -56,7 +56,6 @@ public class SelectorParser implements SelectorParserConstants { // convertStringExpressions = true; // sql = sql.substring(CONVERT_STRING_EXPRESSIONS_PREFIX.length()); // } - // // if( convertStringExpressions ) { // ComparisonExpression.CONVERT_STRING_EXPRESSIONS.set(true); // } @@ -997,12 +996,13 @@ public class SelectorParser implements SelectorParserConstants { } private static void jj_la1_init_0() { - jjLa10 = new int[]{0x400, 0x200, 0xc10000, 0xc00000, 0x10000, 0xf001900, 0x20000000, 0x20000000, 0xf000800, + jjLa10 = new int[] { + 0x400, 0x200, 0xc10000, 0xc00000, 0x10000, 0xf001900, 0x20000000, 0x20000000, 0xf000800, 0x1000, 0x1036e100, 0x1036e000, 0x16e000}; } private static void jj_la1_init_1() { - jjLa11 = new int[]{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0}; + jjLa11 = new int[] {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0}; } final private JJCalls[] jj2Rtns = new JJCalls[4]; @@ -1323,7 +1323,8 @@ public class SelectorParser implements SelectorParserConstants { } } p = p.next; - } while (p != null); + } + while (p != null); } catch (LookaheadSuccess ls) { } } diff --git a/filter/src/main/java/org/apache/rocketmq/filter/parser/SelectorParser.jj b/filter/src/main/java/org/apache/rocketmq/filter/parser/SelectorParser.jj index 5d1a4a7d8fba094d4fc1053e4adef741376b34d5..b533ac1778da1fea299e2eb9efa3b563edd6b4bd 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/parser/SelectorParser.jj +++ b/filter/src/main/java/org/apache/rocketmq/filter/parser/SelectorParser.jj @@ -82,7 +82,6 @@ public class SelectorParser { // convertStringExpressions = true; // sql = sql.substring(CONVERT_STRING_EXPRESSIONS_PREFIX.length()); // } -// // if( convertStringExpressions ) { // ComparisonExpression.CONVERT_STRING_EXPRESSIONS.set(true); // } diff --git a/filter/src/main/java/org/apache/rocketmq/filter/parser/SelectorParserTokenManager.java b/filter/src/main/java/org/apache/rocketmq/filter/parser/SelectorParserTokenManager.java index 354f5ba21b59d40c678934167fa4c5549f3dc029..b5bac9824052c3e7dbe1dbcebfb7c359e8886f4b 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/parser/SelectorParserTokenManager.java +++ b/filter/src/main/java/org/apache/rocketmq/filter/parser/SelectorParserTokenManager.java @@ -385,7 +385,7 @@ public class SelectorParserTokenManager implements SelectorParserConstants { int i = 1; jjstateSet[0] = startState; int kind = 0x7fffffff; - for (;;) { + for (; ; ) { if (++jjround == 0x7fffffff) ReInitRounds(); if (curChar < 64) { @@ -586,7 +586,8 @@ public class SelectorParserTokenManager implements SelectorParserConstants { default: break; } - } while (i != startsAt); + } + while (i != startsAt); } else if (curChar < 128) { long l = 1L << (curChar & 077); do { @@ -631,7 +632,8 @@ public class SelectorParserTokenManager implements SelectorParserConstants { default: break; } - } while (i != startsAt); + } + while (i != startsAt); } else { int hiByte = (int) (curChar >> 8); int i1 = hiByte >> 6; @@ -660,7 +662,8 @@ public class SelectorParserTokenManager implements SelectorParserConstants { default: break; } - } while (i != startsAt); + } + while (i != startsAt); } if (kind != 0x7fffffff) { jjmatchedKind = kind; @@ -834,7 +837,7 @@ public class SelectorParserTokenManager implements SelectorParserConstants { int curPos = 0; EOFLoop: - for (;;) { + for (; ; ) { try { curChar = inputStream.BeginToken(); } catch (java.io.IOException e) { @@ -902,7 +905,8 @@ public class SelectorParserTokenManager implements SelectorParserConstants { private void jjAddStates(int start, int end) { do { jjstateSet[jjnewStateCnt++] = JJ_NEXT_STATES[start]; - } while (start++ != end); + } + while (start++ != end); } private void jjCheckNAddTwoStates(int state1, int state2) { @@ -913,7 +917,8 @@ public class SelectorParserTokenManager implements SelectorParserConstants { private void jjCheckNAddStates(int start, int end) { do { jjCheckNAdd(JJ_NEXT_STATES[start]); - } while (start++ != end); + } + while (start++ != end); } } diff --git a/filter/src/main/java/org/apache/rocketmq/filter/parser/SimpleCharStream.java b/filter/src/main/java/org/apache/rocketmq/filter/parser/SimpleCharStream.java index 94a54b41c24f9ef5c2e3f561558fdf6a8916e250..53f7e1c297e3acea100512b068c1a852e4e09c26 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/parser/SimpleCharStream.java +++ b/filter/src/main/java/org/apache/rocketmq/filter/parser/SimpleCharStream.java @@ -264,7 +264,7 @@ public class SimpleCharStream { * Constructor. */ public SimpleCharStream(java.io.Reader dstream, int startline, - int startcolumn, int buffersize) { + int startcolumn, int buffersize) { inputStream = dstream; line = startline; column = startcolumn - 1; @@ -279,7 +279,7 @@ public class SimpleCharStream { * Constructor. */ public SimpleCharStream(java.io.Reader dstream, int startline, - int startcolumn) { + int startcolumn) { this(dstream, startline, startcolumn, 4096); } @@ -294,7 +294,7 @@ public class SimpleCharStream { * Reinitialise. */ public void ReInit(java.io.Reader dstream, int startline, - int startcolumn, int buffersize) { + int startcolumn, int buffersize) { inputStream = dstream; line = startline; column = startcolumn - 1; @@ -314,7 +314,7 @@ public class SimpleCharStream { * Reinitialise. */ public void ReInit(java.io.Reader dstream, int startline, - int startcolumn) { + int startcolumn) { ReInit(dstream, startline, startcolumn, 4096); } @@ -329,7 +329,7 @@ public class SimpleCharStream { * Constructor. */ public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, - int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException { + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException { this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); @@ -339,7 +339,7 @@ public class SimpleCharStream { * Constructor. */ public SimpleCharStream(java.io.InputStream dstream, int startline, - int startcolumn, int buffersize) { + int startcolumn, int buffersize) { this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); } @@ -347,7 +347,7 @@ public class SimpleCharStream { * Constructor. */ public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, - int startcolumn) throws java.io.UnsupportedEncodingException { + int startcolumn) throws java.io.UnsupportedEncodingException { this(dstream, encoding, startline, startcolumn, 4096); } @@ -355,7 +355,7 @@ public class SimpleCharStream { * Constructor. */ public SimpleCharStream(java.io.InputStream dstream, int startline, - int startcolumn) { + int startcolumn) { this(dstream, startline, startcolumn, 4096); } @@ -377,7 +377,7 @@ public class SimpleCharStream { * Reinitialise. */ public void ReInit(java.io.InputStream dstream, String encoding, int startline, - int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException { + int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException { ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); @@ -387,7 +387,7 @@ public class SimpleCharStream { * Reinitialise. */ public void ReInit(java.io.InputStream dstream, int startline, - int startcolumn, int buffersize) { + int startcolumn, int buffersize) { ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); } @@ -409,7 +409,7 @@ public class SimpleCharStream { * Reinitialise. */ public void ReInit(java.io.InputStream dstream, String encoding, int startline, - int startcolumn) throws java.io.UnsupportedEncodingException { + int startcolumn) throws java.io.UnsupportedEncodingException { ReInit(dstream, encoding, startline, startcolumn, 4096); } @@ -417,7 +417,7 @@ public class SimpleCharStream { * Reinitialise. */ public void ReInit(java.io.InputStream dstream, int startline, - int startcolumn) { + int startcolumn) { ReInit(dstream, startline, startcolumn, 4096); } diff --git a/filter/src/main/java/org/apache/rocketmq/filter/parser/TokenMgrError.java b/filter/src/main/java/org/apache/rocketmq/filter/parser/TokenMgrError.java index 75d83e5f17782014ca45dea586eee9475cc2fe3b..e8132df5aac561730e62e9fe199f68e1ee7c0d53 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/parser/TokenMgrError.java +++ b/filter/src/main/java/org/apache/rocketmq/filter/parser/TokenMgrError.java @@ -122,7 +122,7 @@ public class TokenMgrError extends Error { * Note: You can customize the lexical error message by modifying this method. */ protected static String LexicalError(boolean eofSeen, int lexState, int errorLine, int errorColumn, - String errorAfter, char curChar) { + String errorAfter, char curChar) { return "Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: " + @@ -167,7 +167,7 @@ public class TokenMgrError extends Error { * Full Constructor. */ public TokenMgrError(boolean eofSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, - int reason) { + int reason) { this(LexicalError(eofSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); } } diff --git a/filter/src/main/java/org/apache/rocketmq/filter/util/BloomFilter.java b/filter/src/main/java/org/apache/rocketmq/filter/util/BloomFilter.java index f61090622ea949300a07f3f7571740d632d0c6ea..9a3de6016b691261132536b9c94377bb73968cc2 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/util/BloomFilter.java +++ b/filter/src/main/java/org/apache/rocketmq/filter/util/BloomFilter.java @@ -42,7 +42,6 @@ public class BloomFilter { * * @param f error rate * @param n num will mapping to bit - * @return */ public static BloomFilter createByFn(int f, int n) { return new BloomFilter(f, n); @@ -87,9 +86,6 @@ public class BloomFilter { * See "Less Hashing, Same Performance: Building a Better Bloom Filter" by Adam Kirsch and Michael * Mitzenmacher. *

    - * - * @param str - * @return */ public int[] calcBitPositions(String str) { int[] bitPositions = new int[this.k]; @@ -113,9 +109,6 @@ public class BloomFilter { /** * Calculate bit positions of {@code str} to construct {@code BloomFilterData} - * - * @param str - * @return */ public BloomFilterData generate(String str) { int[] bitPositions = calcBitPositions(str); @@ -125,9 +118,6 @@ public class BloomFilter { /** * Calculate bit positions of {@code str}, then set the related {@code bits} positions to 1. - * - * @param str - * @param bits */ public void hashTo(String str, BitsArray bits) { hashTo(calcBitPositions(str), bits); @@ -135,9 +125,6 @@ public class BloomFilter { /** * Set the related {@code bits} positions to 1. - * - * @param bitPositions - * @param bits */ public void hashTo(int[] bitPositions, BitsArray bits) { check(bits); @@ -153,9 +140,6 @@ public class BloomFilter { *

    * Then set the related {@code bits} positions to 1. *

    - * - * @param filterData - * @param bits */ public void hashTo(BloomFilterData filterData, BitsArray bits) { if (!isValid(filterData)) { @@ -170,8 +154,6 @@ public class BloomFilter { /** * Calculate bit positions of {@code str}, then check all the related {@code bits} positions is 1. * - * @param str - * @param bits * @return true: all the related {@code bits} positions is 1 */ public boolean isHit(String str, BitsArray bits) { @@ -181,8 +163,6 @@ public class BloomFilter { /** * Check all the related {@code bits} positions is 1. * - * @param bitPositions - * @param bits * @return true: all the related {@code bits} positions is 1 */ public boolean isHit(int[] bitPositions, BitsArray bits) { @@ -197,8 +177,6 @@ public class BloomFilter { /** * Check all the related {@code bits} positions is 1. * - * @param filterData - * @param bits * @return true: all the related {@code bits} positions is 1 */ public boolean isHit(BloomFilterData filterData, BitsArray bits) { @@ -214,8 +192,6 @@ public class BloomFilter { /** * Check whether one of {@code bitPositions} has been occupied. * - * @param bitPositions - * @param bits * @return true: if all positions have been occupied. */ public boolean checkFalseHit(int[] bitPositions, BitsArray bits) { @@ -246,9 +222,6 @@ public class BloomFilter { *
  • 2. {@link org.apache.rocketmq.filter.util.BloomFilterData#getBitNum} must be equal to {@code m}
  • *
  • 3. {@link org.apache.rocketmq.filter.util.BloomFilterData#getBitPos} is not null
  • *
  • 4. {@link org.apache.rocketmq.filter.util.BloomFilterData#getBitPos}'s length is equal to {@code k}
  • - * - * @param filterData - * @return */ public boolean isValid(BloomFilterData filterData) { if (filterData == null @@ -263,8 +236,6 @@ public class BloomFilter { /** * error rate. - * - * @return */ public int getF() { return f; @@ -272,8 +243,6 @@ public class BloomFilter { /** * expect mapping num. - * - * @return */ public int getN() { return n; @@ -281,8 +250,6 @@ public class BloomFilter { /** * hash function num. - * - * @return */ public int getK() { return k; @@ -290,8 +257,6 @@ public class BloomFilter { /** * total bit num. - * - * @return */ public int getM() { return m; diff --git a/filter/src/main/java/org/apache/rocketmq/filter/util/BloomFilterData.java b/filter/src/main/java/org/apache/rocketmq/filter/util/BloomFilterData.java index de02d927de550a3d3b8e1d158b64082032801931..c0213231b0c91c6a82016eaab61670f424574582 100644 --- a/filter/src/main/java/org/apache/rocketmq/filter/util/BloomFilterData.java +++ b/filter/src/main/java/org/apache/rocketmq/filter/util/BloomFilterData.java @@ -55,13 +55,17 @@ public class BloomFilterData { @Override public boolean equals(final Object o) { - if (this == o) return true; - if (!(o instanceof BloomFilterData)) return false; + if (this == o) + return true; + if (!(o instanceof BloomFilterData)) + return false; final BloomFilterData that = (BloomFilterData) o; - if (bitNum != that.bitNum) return false; - if (!Arrays.equals(bitPos, that.bitPos)) return false; + if (bitNum != that.bitNum) + return false; + if (!Arrays.equals(bitPos, that.bitPos)) + return false; return true; } diff --git a/filter/src/test/java/org/apache/rocketmq/filter/BitsArrayTest.java b/filter/src/test/java/org/apache/rocketmq/filter/BitsArrayTest.java index ef81b29b88ab20a3dee77209073ce1d476c9dc66..1ba736019d2fe9d9fd2e35a49744367816ebffcd 100644 --- a/filter/src/test/java/org/apache/rocketmq/filter/BitsArrayTest.java +++ b/filter/src/test/java/org/apache/rocketmq/filter/BitsArrayTest.java @@ -111,8 +111,8 @@ public class BitsArrayTest { @Test public void testOr() { - BitsArray b1 = BitsArray.create(new byte[]{(byte) 0xff, 0x00}); - BitsArray b2 = BitsArray.create(new byte[]{0x00, (byte) 0xff}); + BitsArray b1 = BitsArray.create(new byte[] {(byte) 0xff, 0x00}); + BitsArray b2 = BitsArray.create(new byte[] {0x00, (byte) 0xff}); b1.or(b2); diff --git a/filter/src/test/java/org/apache/rocketmq/filter/BloomFilterTest.java b/filter/src/test/java/org/apache/rocketmq/filter/BloomFilterTest.java index c6097ee85cf686a6b1758aeedb9b1b4aa2af7794..d2425b4d7124b90fcb4a107034ad25b99971a742 100644 --- a/filter/src/test/java/org/apache/rocketmq/filter/BloomFilterTest.java +++ b/filter/src/test/java/org/apache/rocketmq/filter/BloomFilterTest.java @@ -107,9 +107,9 @@ public class BloomFilterTest { @Test public void testBloomFilterData() { - BloomFilterData bloomFilterData = new BloomFilterData(new int[]{1, 2, 3}, 128); - BloomFilterData bloomFilterData1 = new BloomFilterData(new int[]{1, 2, 3}, 128); - BloomFilterData bloomFilterData2 = new BloomFilterData(new int[]{1, 2, 3}, 129); + BloomFilterData bloomFilterData = new BloomFilterData(new int[] {1, 2, 3}, 128); + BloomFilterData bloomFilterData1 = new BloomFilterData(new int[] {1, 2, 3}, 128); + BloomFilterData bloomFilterData2 = new BloomFilterData(new int[] {1, 2, 3}, 129); assertThat(bloomFilterData).isEqualTo(bloomFilterData1); assertThat(bloomFilterData2).isNotEqualTo(bloomFilterData); @@ -127,7 +127,7 @@ public class BloomFilterTest { assertThat(bloomFilterData).isEqualTo(bloomFilterData2); - bloomFilterData2.setBitPos(new int[]{1, 2, 3, 4}); + bloomFilterData2.setBitPos(new int[] {1, 2, 3, 4}); assertThat(bloomFilterData).isNotEqualTo(bloomFilterData2); diff --git a/filter/src/test/java/org/apache/rocketmq/filter/ExpressionTest.java b/filter/src/test/java/org/apache/rocketmq/filter/ExpressionTest.java index 0ee81c98a2d973cdc84b6bfdec9c8cd1f8e619f7..7fb606ac13bd57fcbe06b4b4db9a2ff4cff658cc 100644 --- a/filter/src/test/java/org/apache/rocketmq/filter/ExpressionTest.java +++ b/filter/src/test/java/org/apache/rocketmq/filter/ExpressionTest.java @@ -47,7 +47,7 @@ public class ExpressionTest { private static String stringHasString = "TAGS is not null and TAGS='''''tag'''''"; @Test - public void testEvaluate_stringHasString() { + public void testEvaluate_stringHasString() throws Exception { Expression expr = genExp(stringHasString); EvaluationContext context = genContext( @@ -58,7 +58,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_now() { + public void testEvaluate_now() throws Exception { EvaluationContext context = genContext( KeyValue.c("a", System.currentTimeMillis()) ); @@ -72,8 +72,8 @@ public class ExpressionTest { eval(expression, context, Boolean.TRUE); } - @Test - public void testEvaluate_stringCompare() { + @Test(expected = RuntimeException.class) + public void testEvaluate_stringCompare() throws Exception { Expression expression = genExp("a between up and low"); EvaluationContext context = genContext( @@ -147,7 +147,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_exponent() { + public void testEvaluate_exponent() throws Exception { Expression expression = genExp("a > 3.1E10"); EvaluationContext context = genContext( @@ -158,7 +158,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_floatNumber() { + public void testEvaluate_floatNumber() throws Exception { Expression expression = genExp("a > 3.14"); EvaluationContext context = genContext( @@ -169,7 +169,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_twoVariable() { + public void testEvaluate_twoVariable() throws Exception { Expression expression = genExp("a > b"); EvaluationContext context = genContext( @@ -178,8 +178,12 @@ public class ExpressionTest { ); eval(expression, context, Boolean.FALSE); + } - context = genContext( + @Test + public void testEvaluate_twoVariableGt() throws Exception { + Expression expression = genExp("a > b"); + EvaluationContext context = genContext( KeyValue.c("b", String.valueOf(10)), KeyValue.c("a", String.valueOf(20)) ); @@ -188,7 +192,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_nullOr() { + public void testEvaluate_nullOr() throws Exception { Expression expression = genExp(nullOrExpression); EvaluationContext context = genContext( @@ -210,7 +214,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_boolean() { + public void testEvaluate_boolean() throws Exception { Expression expression = genExp(booleanExpression); EvaluationContext context = genContext( @@ -229,7 +233,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_equal() { + public void testEvaluate_equal() throws Exception { Expression expression = genExp(equalExpression); EvaluationContext context = genContext( @@ -245,7 +249,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_andTrue() { + public void testEvaluate_andTrue() throws Exception { Expression expression = genExp(andExpression); EvaluationContext context = genContext( @@ -278,7 +282,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_andFalse() { + public void testEvaluate_andFalse() throws Exception { Expression expression = genExp(andExpression); EvaluationContext context = genContext( @@ -302,7 +306,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_orTrue() { + public void testEvaluate_orTrue() throws Exception { Expression expression = genExp(orExpression); // first @@ -337,7 +341,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_orFalse() { + public void testEvaluate_orFalse() throws Exception { Expression expression = genExp(orExpression); // forth EvaluationContext context = genContext( @@ -350,7 +354,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_inTrue() { + public void testEvaluate_inTrue() throws Exception { Expression expression = genExp(inExpression); EvaluationContext context = genContext( @@ -370,7 +374,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_inFalse() { + public void testEvaluate_inFalse() throws Exception { Expression expression = genExp(inExpression); EvaluationContext context = genContext( @@ -380,7 +384,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_notInTrue() { + public void testEvaluate_notInTrue() throws Exception { Expression expression = genExp(notInExpression); EvaluationContext context = genContext( @@ -390,7 +394,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_notInFalse() { + public void testEvaluate_notInFalse() throws Exception { Expression expression = genExp(notInExpression); EvaluationContext context = genContext( @@ -410,7 +414,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_betweenTrue() { + public void testEvaluate_betweenTrue() throws Exception { Expression expression = genExp(betweenExpression); EvaluationContext context = genContext( @@ -430,7 +434,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_betweenFalse() { + public void testEvaluate_betweenFalse() throws Exception { Expression expression = genExp(betweenExpression); EvaluationContext context = genContext( @@ -445,7 +449,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_notBetweenTrue() { + public void testEvaluate_notBetweenTrue() throws Exception { Expression expression = genExp(notBetweenExpression); EvaluationContext context = genContext( @@ -460,7 +464,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_notBetweenFalse() { + public void testEvaluate_notBetweenFalse() throws Exception { Expression expression = genExp(notBetweenExpression); EvaluationContext context = genContext( @@ -480,7 +484,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_isNullTrue() { + public void testEvaluate_isNullTrue() throws Exception { Expression expression = genExp(isNullExpression); EvaluationContext context = genContext( @@ -490,7 +494,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_isNullFalse() { + public void testEvaluate_isNullFalse() throws Exception { Expression expression = genExp(isNullExpression); EvaluationContext context = genContext( @@ -500,7 +504,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_isNotNullTrue() { + public void testEvaluate_isNotNullTrue() throws Exception { Expression expression = genExp(isNotNullExpression); EvaluationContext context = genContext( @@ -510,7 +514,7 @@ public class ExpressionTest { } @Test - public void testEvaluate_isNotNullFalse() { + public void testEvaluate_isNotNullFalse() throws Exception { Expression expression = genExp(isNotNullExpression); EvaluationContext context = genContext( @@ -519,14 +523,8 @@ public class ExpressionTest { eval(expression, context, Boolean.FALSE); } - protected void eval(Expression expression, EvaluationContext context, Boolean result) { - Object ret = null; - try { - ret = expression.evaluate(context); - } catch (Throwable e) { - e.printStackTrace(); - } - + protected void eval(Expression expression, EvaluationContext context, Boolean result) throws Exception { + Object ret = expression.evaluate(context); if (ret == null || !(ret instanceof Boolean)) { assertThat(result).isFalse(); } else { diff --git a/filter/src/test/java/org/apache/rocketmq/filter/FilterSpiTest.java b/filter/src/test/java/org/apache/rocketmq/filter/FilterSpiTest.java index 22eeb8603e7f4a8d545de4a1bdef12c92224efdc..bfbddf491359c62b137d0f70934f3912c74dbd8b 100644 --- a/filter/src/test/java/org/apache/rocketmq/filter/FilterSpiTest.java +++ b/filter/src/test/java/org/apache/rocketmq/filter/FilterSpiTest.java @@ -48,7 +48,6 @@ public class FilterSpiTest { } } - @Test public void testRegister() { FilterFactory.INSTANCE.register(new NothingFilter()); diff --git a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/processor/DefaultRequestProcessor.java b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/processor/DefaultRequestProcessor.java index ff8450e5c5a6c43afeaa5ca2f06ba3a6cbe8edb6..e459b1aeb6dc279a26245b452b627a0914d16397 100644 --- a/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/processor/DefaultRequestProcessor.java +++ b/filtersrv/src/main/java/org/apache/rocketmq/filtersrv/processor/DefaultRequestProcessor.java @@ -83,7 +83,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return false; } - private RemotingCommand registerMessageFilterClass(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand registerMessageFilterClass(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final RegisterMessageFilterClassRequestHeader requestHeader = (RegisterMessageFilterClassRequestHeader) request.decodeCommandCustomHeader(RegisterMessageFilterClassRequestHeader.class); @@ -108,7 +109,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand pullMessageForward(final ChannelHandlerContext ctx, final RemotingCommand request) throws Exception { + private RemotingCommand pullMessageForward(final ChannelHandlerContext ctx, + final RemotingCommand request) throws Exception { final RemotingCommand response = RemotingCommand.createResponseCommand(PullMessageResponseHeader.class); final PullMessageResponseHeader responseHeader = (PullMessageResponseHeader) response.readCustomHeader(); final PullMessageRequestHeader requestHeader = @@ -215,7 +217,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return null; } - private void returnResponse(final String group, final String topic, ChannelHandlerContext ctx, final RemotingCommand response, + private void returnResponse(final String group, final String topic, ChannelHandlerContext ctx, + final RemotingCommand response, final List msgList) { if (null != msgList) { ByteBuffer[] msgBufferList = new ByteBuffer[msgList.size()]; diff --git a/logappender/src/main/java/org/apache/rocketmq/logappender/common/ProducerInstance.java b/logappender/src/main/java/org/apache/rocketmq/logappender/common/ProducerInstance.java index 669e30c01e63b197af7ca5c6457ef60dddcb2ec5..d2adac53dbc6d5db1c1951883f42c710fd755fd5 100644 --- a/logappender/src/main/java/org/apache/rocketmq/logappender/common/ProducerInstance.java +++ b/logappender/src/main/java/org/apache/rocketmq/logappender/common/ProducerInstance.java @@ -16,6 +16,7 @@ */ package org.apache.rocketmq.logappender.common; +import org.apache.commons.lang3.StringUtils; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.producer.DefaultMQProducer; import org.apache.rocketmq.client.producer.MQProducer; @@ -39,20 +40,25 @@ public class ProducerInstance { public static final String DEFAULT_GROUP = "rocketmq_appender"; - private static ConcurrentHashMap producerMap = new ConcurrentHashMap(); + private ConcurrentHashMap producerMap = new ConcurrentHashMap(); - private static String genKey(String nameServerAddress, String group) { - return nameServerAddress + "_" + group; + private static ProducerInstance instance = new ProducerInstance(); + + public static ProducerInstance getProducerInstance() { + return instance; } + private String genKey(String nameServerAddress, String group) { + return nameServerAddress + "_" + group; + } - public static MQProducer getInstance(String nameServerAddress, String group) throws MQClientException { - if (group == null) { + public MQProducer getInstance(String nameServerAddress, String group) throws MQClientException { + if (StringUtils.isBlank(group)) { group = DEFAULT_GROUP; } String genKey = genKey(nameServerAddress, group); - MQProducer p = producerMap.get(genKey); + MQProducer p = getProducerInstance().producerMap.get(genKey); if (p != null) { return p; } @@ -60,8 +66,7 @@ public class ProducerInstance { DefaultMQProducer defaultMQProducer = new DefaultMQProducer(group); defaultMQProducer.setNamesrvAddr(nameServerAddress); MQProducer beforeProducer = null; - //cas put producer - beforeProducer = producerMap.putIfAbsent(genKey, defaultMQProducer); + beforeProducer = getProducerInstance().producerMap.putIfAbsent(genKey, defaultMQProducer); if (beforeProducer != null) { return beforeProducer; } @@ -69,23 +74,22 @@ public class ProducerInstance { return defaultMQProducer; } - - public static void removeAndClose(String nameServerAddress, String group) { + public void removeAndClose(String nameServerAddress, String group) { if (group == null) { group = DEFAULT_GROUP; } String genKey = genKey(nameServerAddress, group); - MQProducer producer = producerMap.remove(genKey); + MQProducer producer = getProducerInstance().producerMap.remove(genKey); if (producer != null) { producer.shutdown(); } } - public static void closeAll() { - Set> entries = producerMap.entrySet(); + public void closeAll() { + Set> entries = getProducerInstance().producerMap.entrySet(); for (Map.Entry entry : entries) { - producerMap.remove(entry.getKey()); + getProducerInstance().producerMap.remove(entry.getKey()); entry.getValue().shutdown(); } } diff --git a/logappender/src/main/java/org/apache/rocketmq/logappender/log4j/RocketmqLog4jAppender.java b/logappender/src/main/java/org/apache/rocketmq/logappender/log4j/RocketmqLog4jAppender.java index b2983b6c1c5c847603dbc078f52440f738216edf..646e924828abb666f62f8ec44523712862f3b76e 100644 --- a/logappender/src/main/java/org/apache/rocketmq/logappender/log4j/RocketmqLog4jAppender.java +++ b/logappender/src/main/java/org/apache/rocketmq/logappender/log4j/RocketmqLog4jAppender.java @@ -59,24 +59,20 @@ public class RocketmqLog4jAppender extends AppenderSkeleton { public RocketmqLog4jAppender() { } - public void activateOptions() { LogLog.debug("Getting initial context."); if (!checkEntryConditions()) { return; } try { - producer = ProducerInstance.getInstance(nameServerAddress, producerGroup); + producer = ProducerInstance.getProducerInstance().getInstance(nameServerAddress, producerGroup); } catch (Exception e) { LogLog.error("activateOptions nameserver:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage()); } } - /** * Info,error,warn,callback method implementation - * - * @param event */ public void append(LoggingEvent event) { if (null == producer) { @@ -95,7 +91,7 @@ public class RocketmqLog4jAppender extends AppenderSkeleton { } catch (Exception e) { String msg = new String(data); errorHandler.error("Could not send message in RocketmqLog4jAppender [" + name + "].Message is :" + msg, e, - ErrorCode.GENERIC_FAILURE); + ErrorCode.GENERIC_FAILURE); } } @@ -129,7 +125,7 @@ public class RocketmqLog4jAppender extends AppenderSkeleton { this.closed = true; try { - ProducerInstance.removeAndClose(this.nameServerAddress, this.producerGroup); + ProducerInstance.getProducerInstance().removeAndClose(this.nameServerAddress, this.producerGroup); } catch (Exception e) { LogLog.error("Closing RocketmqLog4jAppender [" + name + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage()); } @@ -145,7 +141,6 @@ public class RocketmqLog4jAppender extends AppenderSkeleton { return topic; } - public void setTopic(String topic) { this.topic = topic; } diff --git a/logappender/src/main/java/org/apache/rocketmq/logappender/log4j2/RocketmqLog4j2Appender.java b/logappender/src/main/java/org/apache/rocketmq/logappender/log4j2/RocketmqLog4j2Appender.java index fb8341f167e848da6f7e8c97556d9ceb1397e757..9543f1c2917cb7dc648282d3286d9ee372a93d59 100644 --- a/logappender/src/main/java/org/apache/rocketmq/logappender/log4j2/RocketmqLog4j2Appender.java +++ b/logappender/src/main/java/org/apache/rocketmq/logappender/log4j2/RocketmqLog4j2Appender.java @@ -70,10 +70,9 @@ public class RocketmqLog4j2Appender extends AbstractAppender { */ private String topic; - protected RocketmqLog4j2Appender(String name, Filter filter, Layout layout, - boolean ignoreExceptions, String nameServerAddress, String producerGroup, - String topic, String tag) { + boolean ignoreExceptions, String nameServerAddress, String producerGroup, + String topic, String tag) { super(name, filter, layout, ignoreExceptions); this.producer = producer; this.topic = topic; @@ -81,20 +80,18 @@ public class RocketmqLog4j2Appender extends AbstractAppender { this.nameServerAddress = nameServerAddress; this.producerGroup = producerGroup; try { - this.producer = ProducerInstance.getInstance(this.nameServerAddress, this.producerGroup); + this.producer = ProducerInstance.getProducerInstance().getInstance(this.nameServerAddress, this.producerGroup); } catch (Exception e) { ErrorHandler handler = this.getHandler(); if (handler != null) { handler.error("Starting RocketmqLog4j2Appender [" + this.getName() - + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage()); + + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage()); } } } /** * Info,error,warn,callback method implementation - * - * @param event */ public void append(LogEvent event) { if (null == producer) { @@ -119,20 +116,16 @@ public class RocketmqLog4j2Appender extends AbstractAppender { /** * When system exit,this method will be called to close resources - * - * @param timeout - * @param timeUnit - * @return */ public boolean stop(long timeout, TimeUnit timeUnit) { this.setStopping(); try { - ProducerInstance.removeAndClose(this.nameServerAddress, this.producerGroup); + ProducerInstance.getProducerInstance().removeAndClose(this.nameServerAddress, this.producerGroup); } catch (Exception e) { ErrorHandler handler = this.getHandler(); if (handler != null) { handler.error("Closeing RocketmqLog4j2Appender [" + this.getName() - + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage()); + + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage()); } } @@ -227,7 +220,7 @@ public class RocketmqLog4j2Appender extends AbstractAppender { public RocketmqLog4j2Appender build() { return new RocketmqLog4j2Appender(name, filter, layout, ignoreExceptions, - nameServerAddress, producerGroup, topic, tag); + nameServerAddress, producerGroup, topic, tag); } } } diff --git a/logappender/src/main/java/org/apache/rocketmq/logappender/logback/RocketmqLogbackAppender.java b/logappender/src/main/java/org/apache/rocketmq/logappender/logback/RocketmqLogbackAppender.java index cb4552285383e35f401c31fc9b15bc05804c0324..4018cd44a17bf14600a86884febabfccf2b76032 100644 --- a/logappender/src/main/java/org/apache/rocketmq/logappender/logback/RocketmqLogbackAppender.java +++ b/logappender/src/main/java/org/apache/rocketmq/logappender/logback/RocketmqLogbackAppender.java @@ -62,8 +62,6 @@ public class RocketmqLogbackAppender extends AppenderBase { /** * Info,error,warn,callback method implementation - * - * @param event */ @Override protected void append(ILoggingEvent event) { @@ -97,10 +95,10 @@ public class RocketmqLogbackAppender extends AppenderBase { return; } try { - producer = ProducerInstance.getInstance(nameServerAddress, producerGroup); + producer = ProducerInstance.getProducerInstance().getInstance(nameServerAddress, producerGroup); } catch (Exception e) { addError("Starting RocketmqLogbackAppender [" + this.getName() - + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage()); + + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage()); } if (producer != null) { super.start(); @@ -119,10 +117,10 @@ public class RocketmqLogbackAppender extends AppenderBase { this.started = false; try { - ProducerInstance.removeAndClose(this.nameServerAddress, this.producerGroup); + ProducerInstance.getProducerInstance().removeAndClose(this.nameServerAddress, this.producerGroup); } catch (Exception e) { addError("Closeing RocketmqLogbackAppender [" + this.getName() - + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage()); + + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage()); } // Help garbage collection @@ -144,7 +142,6 @@ public class RocketmqLogbackAppender extends AppenderBase { } } - public Layout getLayout() { return this.layout; } @@ -160,7 +157,6 @@ public class RocketmqLogbackAppender extends AppenderBase { return tag; } - public void setTag(String tag) { this.tag = tag; } diff --git a/logappender/src/test/java/org/apache/rocketmq/logappender/AbstractTestCase.java b/logappender/src/test/java/org/apache/rocketmq/logappender/AbstractTestCase.java index d3e2f8aedcfbbfc822c0db5c515cb1101c7a1fa4..38904c0bfc7733d50b8e100b54fe10c597af2b55 100644 --- a/logappender/src/test/java/org/apache/rocketmq/logappender/AbstractTestCase.java +++ b/logappender/src/test/java/org/apache/rocketmq/logappender/AbstractTestCase.java @@ -16,31 +16,18 @@ */ package org.apache.rocketmq.logappender; -import org.apache.rocketmq.broker.BrokerController; -import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; -import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; -import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; -import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; -import org.apache.rocketmq.client.exception.MQClientException; -import org.apache.rocketmq.common.BrokerConfig; -import org.apache.rocketmq.common.MQVersion; -import org.apache.rocketmq.common.MixAll; -import org.apache.rocketmq.common.consumer.ConsumeFromWhere; -import org.apache.rocketmq.common.message.MessageExt; -import org.apache.rocketmq.common.namesrv.NamesrvConfig; +import org.apache.rocketmq.client.producer.DefaultMQProducer; + +import org.apache.rocketmq.common.message.*; import org.apache.rocketmq.logappender.common.ProducerInstance; -import org.apache.rocketmq.namesrv.NamesrvController; -import org.apache.rocketmq.remoting.netty.NettyClientConfig; -import org.apache.rocketmq.remoting.netty.NettyServerConfig; -import org.apache.rocketmq.remoting.protocol.RemotingCommand; -import org.apache.rocketmq.store.config.MessageStoreConfig; -import org.junit.AfterClass; -import org.junit.BeforeClass; +import org.junit.Before; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +import static org.mockito.Mockito.*; -import java.util.List; -import java.util.Random; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; +import java.lang.reflect.Field; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicInteger; /** @@ -48,107 +35,38 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class AbstractTestCase { - private static String nameServer = "localhost:9876"; - - private static NamesrvController namesrvController; - - private static BrokerController brokerController; - - private static String topic = "TopicTest"; - - @BeforeClass - public static void startRocketmqService() throws Exception { - - startNamesrv(); - - startBroker(); - } - - /** - * Start rocketmq name server - * @throws Exception - */ - private static void startNamesrv() throws Exception { - - NamesrvConfig namesrvConfig = new NamesrvConfig(); - NettyServerConfig nettyServerConfig = new NettyServerConfig(); - nettyServerConfig.setListenPort(9876); - - namesrvController = new NamesrvController(namesrvConfig, nettyServerConfig); - boolean initResult = namesrvController.initialize(); - if (!initResult) { - namesrvController.shutdown(); - throw new Exception(); - } - namesrvController.start(); - } - - /** - * Start rocketmq broker service - * @throws Exception - */ - private static void startBroker() throws Exception { - - System.setProperty(RemotingCommand.REMOTING_VERSION_KEY, Integer.toString(MQVersion.CURRENT_VERSION)); + private static CopyOnWriteArrayList messages = new CopyOnWriteArrayList<>(); - BrokerConfig brokerConfig = new BrokerConfig(); - brokerConfig.setNamesrvAddr(nameServer); - brokerConfig.setBrokerId(MixAll.MASTER_ID); - NettyServerConfig nettyServerConfig = new NettyServerConfig(); - nettyServerConfig.setListenPort(10911); - NettyClientConfig nettyClientConfig = new NettyClientConfig(); - MessageStoreConfig messageStoreConfig = new MessageStoreConfig(); - - brokerController = new BrokerController(brokerConfig, nettyServerConfig, nettyClientConfig, messageStoreConfig); - boolean initResult = brokerController.initialize(); - if (!initResult) { - brokerController.shutdown(); - throw new Exception(); - } - brokerController.start(); + @Before + public void mockLoggerAppender() throws Exception { + DefaultMQProducer defaultMQProducer = spy(new DefaultMQProducer("loggerAppender")); + doAnswer(new Answer() { + @Override + public Void answer(InvocationOnMock invocationOnMock) throws Throwable { + Message message = (Message) invocationOnMock.getArgument(0); + messages.add(message); + return null; + } + }).when(defaultMQProducer).sendOneway(any(Message.class)); + ProducerInstance spy = mock(ProducerInstance.class); + Field instance = ProducerInstance.class.getDeclaredField("instance"); + instance.setAccessible(true); + instance.set(ProducerInstance.class, spy); + doReturn(defaultMQProducer).when(spy).getInstance(anyString(), anyString()); } - @AfterClass - public static void stop() { - ProducerInstance.closeAll(); - if (brokerController != null) { - brokerController.shutdown(); - } + public void clear() { - if (namesrvController != null) { - namesrvController.shutdown(); - } } - protected int consumeMessages(int count,final String key,int timeout) throws MQClientException, InterruptedException { - + protected int consumeMessages(int count, final String key, int timeout) { final AtomicInteger cc = new AtomicInteger(0); - final CountDownLatch countDownLatch = new CountDownLatch(count); - - DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("hello"); - consumer.setNamesrvAddr(nameServer); - consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET); - consumer.subscribe(topic, "*"); - - consumer.registerMessageListener(new MessageListenerConcurrently() { - - @Override - public ConsumeConcurrentlyStatus consumeMessage(List msgs, - ConsumeConcurrentlyContext context) { - for (MessageExt msg : msgs) { - String body = new String(msg.getBody()); - if(key==null||body.contains(key)){ - countDownLatch.countDown(); - cc.incrementAndGet(); - continue; - } - } - return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; + for (Message message : messages) { + String body = new String(message.getBody()); + if (body.contains(key)) { + cc.incrementAndGet(); } - }); - consumer.start(); - countDownLatch.await(timeout, TimeUnit.SECONDS); - consumer.shutdown(); + } return cc.get(); } } diff --git a/logappender/src/test/java/org/apache/rocketmq/logappender/Log4jTest.java b/logappender/src/test/java/org/apache/rocketmq/logappender/Log4jTest.java index 75f9bf2b602272df3cd57ec18c1e9af2f141232a..c139283a0c95d5af574b778d2d20fa786efd76b8 100644 --- a/logappender/src/test/java/org/apache/rocketmq/logappender/Log4jTest.java +++ b/logappender/src/test/java/org/apache/rocketmq/logappender/Log4jTest.java @@ -22,8 +22,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; - -public abstract class Log4jTest extends AbstractTestCase{ +public abstract class Log4jTest extends AbstractTestCase { @Before public abstract void init(); @@ -32,12 +31,13 @@ public abstract class Log4jTest extends AbstractTestCase{ @Test public void testLog4j() throws InterruptedException, MQClientException { + clear(); Logger logger = Logger.getLogger("testLogger"); - for (int i = 0; i < 50; i++) { + for (int i = 0; i < 10; i++) { logger.info("log4j " + this.getType() + " simple test message " + i); } - int received = consumeMessages(30, "log4j",30); - Assert.assertTrue(received>20); + int received = consumeMessages(10, "log4j", 10); + Assert.assertTrue(received > 5); } } diff --git a/logappender/src/test/java/org/apache/rocketmq/logappender/LogbackTest.java b/logappender/src/test/java/org/apache/rocketmq/logappender/LogbackTest.java index 15a21a3909e804fb64d46a7dd4ef62cfb699a596..d7ec184a4b79fb450974570293207734d7423116 100644 --- a/logappender/src/test/java/org/apache/rocketmq/logappender/LogbackTest.java +++ b/logappender/src/test/java/org/apache/rocketmq/logappender/LogbackTest.java @@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory; import java.io.File; -public class LogbackTest extends AbstractTestCase{ +public class LogbackTest extends AbstractTestCase { @Before public void init() throws JoranException { @@ -41,14 +41,14 @@ public class LogbackTest extends AbstractTestCase{ StatusPrinter.printInCaseOfErrorsOrWarnings(lc); } - @Test public void testLogback() throws InterruptedException, MQClientException { + clear(); Logger logger = LoggerFactory.getLogger("testLogger"); - for (int i = 0; i < 50; i++) { + for (int i = 0; i < 10; i++) { logger.info("logback test message " + i); } - int received = consumeMessages(30, "logback",30); - Assert.assertTrue(received>20); + int received = consumeMessages(10, "logback", 10); + Assert.assertTrue(received >= 5); } } diff --git a/logappender/src/test/java/org/apache/rocketmq/logappender/log4j2Test.java b/logappender/src/test/java/org/apache/rocketmq/logappender/log4j2Test.java index 75ba523f031048e828cc00e7757a3e9cac931a4a..6f6af60876e0146da49f23aecb7a763d8120da7d 100644 --- a/logappender/src/test/java/org/apache/rocketmq/logappender/log4j2Test.java +++ b/logappender/src/test/java/org/apache/rocketmq/logappender/log4j2Test.java @@ -24,21 +24,21 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -public class log4j2Test extends AbstractTestCase{ +public class log4j2Test extends AbstractTestCase { @Before public void init() { Configurator.initialize("log4j2", "src/test/resources/log4j2-example.xml"); } - @Test public void testLog4j2() throws InterruptedException, MQClientException { + clear(); Logger logger = LogManager.getLogger("test"); - for (int i = 0; i < 50; i++) { + for (int i = 0; i < 10; i++) { logger.info("log4j2 log message " + i); } - int received = consumeMessages(30, "log4j2",30); - Assert.assertTrue(received>20); + int received = consumeMessages(10, "log4j2", 10); + Assert.assertTrue(received > 5); } } diff --git a/logappender/src/test/resources/log4j-example.properties b/logappender/src/test/resources/log4j-example.properties index b4e8114a8bad0db109d62236d9fbd1c07c5d7254..63b2a988c49a9710d35ad6a0c23c131a46270906 100644 --- a/logappender/src/test/resources/log4j-example.properties +++ b/logappender/src/test/resources/log4j-example.properties @@ -12,27 +12,22 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - log4j.rootLogger=INFO,stdout - log4j.logger.testLogger=INFO,mq - log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d %-4r [%t] (%F:%L) %-5p - %m%n - log4j.appender.store=org.apache.log4j.DailyRollingFileAppender log4j.appender.store.File=${user.home}/logs/rocketmqlogs/appender.log log4j.appender.store.Append=true -log4j.appender.store.DatePattern ='_'yyyy-MM-dd'.log' +log4j.appender.store.DatePattern='_'yyyy-MM-dd'.log' log4j.appender.store.layout=org.apache.log4j.PatternLayout log4j.appender.store.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-4r [%t] (%F:%L) %-5p - %m%n - log4j.appender.mq=org.apache.rocketmq.logappender.log4j.RocketmqLog4jAppender log4j.appender.mq.Tag=log log4j.appender.mq.Topic=TopicTest -log4j.appender.mq.ProducerGroup=log4jp +log4j.appender.mq.ProducerGroup=loggerAppender log4j.appender.mq.NameServerAddress=127.0.0.1:9876 log4j.appender.mq.layout=org.apache.log4j.PatternLayout log4j.appender.mq.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-4r [%t] (%F:%L) %-5p - %m%n \ No newline at end of file diff --git a/logappender/src/test/resources/log4j-example.xml b/logappender/src/test/resources/log4j-example.xml index e58bcb09ce3a0b2205a8fa606717716cda15f4d1..6bddde9825c248c644eb7e8cb63c927713848bf7 100644 --- a/logappender/src/test/resources/log4j-example.xml +++ b/logappender/src/test/resources/log4j-example.xml @@ -19,43 +19,37 @@ limitations under the License. - - + + - + - - - + + + - + - - - - - - - - - + + + - - + + - + diff --git a/logappender/src/test/resources/log4j2-example.xml b/logappender/src/test/resources/log4j2-example.xml index 358d40ea54f39820a8ab58e3b366b1a4e4be940e..c310855498b720ffc525b5fcad53069e1ac47ccc 100644 --- a/logappender/src/test/resources/log4j2-example.xml +++ b/logappender/src/test/resources/log4j2-example.xml @@ -17,25 +17,25 @@ --> - - - - + + + + - - - - - + + + + + - - - + + + - - - - - + + + + + \ No newline at end of file diff --git a/logappender/src/test/resources/logback-example.xml b/logappender/src/test/resources/logback-example.xml index 21b543495024ace19dad53909c244a8565442a0f..3786137baf4b1bff231ef5cda471c6226a50a976 100644 --- a/logappender/src/test/resources/logback-example.xml +++ b/logappender/src/test/resources/logback-example.xml @@ -58,21 +58,13 @@ log1 TopicTest - logback + loggerAppender 127.0.0.1:9876 %date %p %t - %m%n - - 1024 - 80 - 2000 - true - - - @@ -83,7 +75,7 @@ - + diff --git a/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManager.java b/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManager.java index be13bd6bed5177a2e5a49e2ebdcb9547d3ee4b71..376a8143094678405b07034164d9c9ae1982cca8 100644 --- a/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManager.java +++ b/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManager.java @@ -72,10 +72,10 @@ public class KVConfigManager { final String prev = kvTable.put(key, value); if (null != prev) { - log.info("putKVConfig update config item, Namespace: {} Key: {} Value: {}", // + log.info("putKVConfig update config item, Namespace: {} Key: {} Value: {}", namespace, key, value); } else { - log.info("putKVConfig create new config item, Namespace: {} Key: {} Value: {}", // + log.info("putKVConfig create new config item, Namespace: {} Key: {} Value: {}", namespace, key, value); } } finally { @@ -119,7 +119,7 @@ public class KVConfigManager { HashMap kvTable = this.configTable.get(namespace); if (null != kvTable) { String value = kvTable.remove(key); - log.info("deleteKVConfig delete a config item, Namespace: {} Key: {} Value: {}", // + log.info("deleteKVConfig delete a config item, Namespace: {} Key: {} Value: {}", namespace, key, value); } } finally { diff --git a/namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/ClusterTestRequestProcessor.java b/namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/ClusterTestRequestProcessor.java index 04cf870278978d09d34566a7f4fb1c4f18a52068..f6611b6837a2b19955d2213dcdbd4e2c0c1d8276 100644 --- a/namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/ClusterTestRequestProcessor.java +++ b/namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/ClusterTestRequestProcessor.java @@ -50,7 +50,8 @@ public class ClusterTestRequestProcessor extends DefaultRequestProcessor { } @Override - public RemotingCommand getRouteInfoByTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand getRouteInfoByTopic(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetRouteInfoRequestHeader requestHeader = (GetRouteInfoRequestHeader) request.decodeCommandCustomHeader(GetRouteInfoRequestHeader.class); diff --git a/namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessor.java b/namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessor.java index 9647684224b2dbec9072a8e96dcf191c87786fb7..ed5b20b166727e22a50ee0c0549d5dcead0a9aa7 100644 --- a/namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessor.java +++ b/namesrv/src/main/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessor.java @@ -63,7 +63,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { } @Override - public RemotingCommand processRequest(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand processRequest(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { if (log.isDebugEnabled()) { log.debug("receive request, {} {} {}", request.getCode(), @@ -124,7 +125,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return false; } - public RemotingCommand putKVConfig(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand putKVConfig(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final PutKVConfigRequestHeader requestHeader = (PutKVConfigRequestHeader) request.decodeCommandCustomHeader(PutKVConfigRequestHeader.class); @@ -140,7 +142,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - public RemotingCommand getKVConfig(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand getKVConfig(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(GetKVConfigResponseHeader.class); final GetKVConfigResponseHeader responseHeader = (GetKVConfigResponseHeader) response.readCustomHeader(); final GetKVConfigRequestHeader requestHeader = @@ -163,7 +166,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - public RemotingCommand deleteKVConfig(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand deleteKVConfig(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final DeleteKVConfigRequestHeader requestHeader = (DeleteKVConfigRequestHeader) request.decodeCommandCustomHeader(DeleteKVConfigRequestHeader.class); @@ -215,7 +219,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - public RemotingCommand registerBroker(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand registerBroker(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(RegisterBrokerResponseHeader.class); final RegisterBrokerResponseHeader responseHeader = (RegisterBrokerResponseHeader) response.readCustomHeader(); final RegisterBrokerRequestHeader requestHeader = @@ -251,7 +256,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - public RemotingCommand unregisterBroker(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand unregisterBroker(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final UnRegisterBrokerRequestHeader requestHeader = (UnRegisterBrokerRequestHeader) request.decodeCommandCustomHeader(UnRegisterBrokerRequestHeader.class); @@ -267,7 +273,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - public RemotingCommand getRouteInfoByTopic(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + public RemotingCommand getRouteInfoByTopic(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetRouteInfoRequestHeader requestHeader = (GetRouteInfoRequestHeader) request.decodeCommandCustomHeader(GetRouteInfoRequestHeader.class); @@ -306,7 +313,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand wipeWritePermOfBroker(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand wipeWritePermOfBroker(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(WipeWritePermOfBrokerResponseHeader.class); final WipeWritePermOfBrokerResponseHeader responseHeader = (WipeWritePermOfBrokerResponseHeader) response.readCustomHeader(); final WipeWritePermOfBrokerRequestHeader requestHeader = @@ -336,7 +344,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand deleteTopicInNamesrv(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand deleteTopicInNamesrv(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final DeleteTopicInNamesrvRequestHeader requestHeader = (DeleteTopicInNamesrvRequestHeader) request.decodeCommandCustomHeader(DeleteTopicInNamesrvRequestHeader.class); @@ -348,7 +357,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getKVListByNamespace(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand getKVListByNamespace(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetKVListByNamespaceRequestHeader requestHeader = (GetKVListByNamespaceRequestHeader) request.decodeCommandCustomHeader(GetKVListByNamespaceRequestHeader.class); @@ -367,7 +377,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getTopicsByCluster(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand getTopicsByCluster(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); final GetTopicsByClusterRequestHeader requestHeader = (GetTopicsByClusterRequestHeader) request.decodeCommandCustomHeader(GetTopicsByClusterRequestHeader.class); @@ -380,7 +391,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getSystemTopicListFromNs(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand getSystemTopicListFromNs(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); byte[] body = this.namesrvController.getRouteInfoManager().getSystemTopicList(); @@ -391,7 +403,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getUnitTopicList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand getUnitTopicList(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); byte[] body = this.namesrvController.getRouteInfoManager().getUnitTopics(); @@ -402,7 +415,8 @@ public class DefaultRequestProcessor implements NettyRequestProcessor { return response; } - private RemotingCommand getHasUnitSubTopicList(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException { + private RemotingCommand getHasUnitSubTopicList(ChannelHandlerContext ctx, + RemotingCommand request) throws RemotingCommandException { final RemotingCommand response = RemotingCommand.createResponseCommand(null); byte[] body = this.namesrvController.getRouteInfoManager().getHasUnitSubTopicList(); diff --git a/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java b/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java index 7479fcc5f793abefa805956a46e30661dbc9aa2c..d78ec95f909dc2843628c8042a5b6c0d5066655a 100644 --- a/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java +++ b/namesrv/src/main/java/org/apache/rocketmq/namesrv/routeinfo/RouteInfoManager.java @@ -131,9 +131,9 @@ public class RouteInfoManager { String oldAddr = brokerData.getBrokerAddrs().put(brokerId, brokerAddr); registerFirst = registerFirst || (null == oldAddr); - if (null != topicConfigWrapper // + if (null != topicConfigWrapper && MixAll.MASTER_ID == brokerId) { - if (this.isBrokerTopicConfigChanged(brokerAddr, topicConfigWrapper.getDataVersion())// + if (this.isBrokerTopicConfigChanged(brokerAddr, topicConfigWrapper.getDataVersion()) || registerFirst) { ConcurrentMap tcTable = topicConfigWrapper.getTopicConfigTable(); @@ -276,8 +276,8 @@ public class RouteInfoManager { this.lock.writeLock().lockInterruptibly(); BrokerLiveInfo brokerLiveInfo = this.brokerLiveTable.remove(brokerAddr); log.info("unregisterBroker, remove from brokerLiveTable {}, {}", - brokerLiveInfo != null ? "OK" : "Failed", - brokerAddr + brokerLiveInfo != null ? "OK" : "Failed", + brokerAddr ); this.filterServerTable.remove(brokerAddr); diff --git a/namesrv/src/test/java/org/apache/rocketmq/namesrv/NamesrvControllerTest.java b/namesrv/src/test/java/org/apache/rocketmq/namesrv/NamesrvControllerTest.java deleted file mode 100644 index 3db042291075a9c8671891b0d1a70c157c8a6e65..0000000000000000000000000000000000000000 --- a/namesrv/src/test/java/org/apache/rocketmq/namesrv/NamesrvControllerTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.rocketmq.namesrv; - -import org.apache.rocketmq.common.namesrv.NamesrvConfig; -import org.apache.rocketmq.remoting.netty.NettyServerConfig; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class NamesrvControllerTest { - private final static int RESTARTNUM = 2; - - /** - * Tests if the controller can be properly stopped and started. - * - * @throws Exception If fails. - */ - @Test - public void testRestart() throws Exception { - for (int i = 0; i < RESTARTNUM; i++) { - NamesrvController namesrvController = new NamesrvController( - new NamesrvConfig(), - new NettyServerConfig() - ); - boolean initResult = namesrvController.initialize(); - assertThat(initResult).isEqualTo(true); - namesrvController.start(); - namesrvController.shutdown(); - } - } -} \ No newline at end of file diff --git a/namesrv/src/test/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManagerTest.java b/namesrv/src/test/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManagerTest.java index 8efa536fb57d821123055f847b51b8c10e881fb6..b74d66b2b42bee5ebd93cf529f79131c99a2b787 100644 --- a/namesrv/src/test/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManagerTest.java +++ b/namesrv/src/test/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManagerTest.java @@ -34,7 +34,6 @@ public class KVConfigManagerTest extends NameServerInstanceTest { @Test public void testPutKVConfig() { - kvConfigManager.load(); kvConfigManager.putKVConfig(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG, "UnitTest", "test"); byte[] kvConfig = kvConfigManager.getKVListByNamespace(NamesrvUtil.NAMESPACE_ORDER_TOPIC_CONFIG); assertThat(kvConfig).isNotNull(); diff --git a/namesrv/src/test/java/org/apache/rocketmq/namesrv/processor/ClusterTestRequestProcessorTest.java b/namesrv/src/test/java/org/apache/rocketmq/namesrv/processor/ClusterTestRequestProcessorTest.java index 5a98cd7de4a275f979853a4016b4637373bba6c9..a0e8137524afe2488663fa33b8ac36f667ce4db6 100644 --- a/namesrv/src/test/java/org/apache/rocketmq/namesrv/processor/ClusterTestRequestProcessorTest.java +++ b/namesrv/src/test/java/org/apache/rocketmq/namesrv/processor/ClusterTestRequestProcessorTest.java @@ -99,7 +99,8 @@ public class ClusterTestRequestProcessorTest { @Test public void testGetRouteInfoByTopic() throws RemotingCommandException { RemotingCommand request = RemotingCommand.createRequestCommand(12, new CommandCustomHeader() { - @Override public void checkFields() throws RemotingCommandException { + @Override + public void checkFields() throws RemotingCommandException { } }); diff --git a/openmessaging/src/main/java/io/openmessaging/rocketmq/promise/DefaultPromise.java b/openmessaging/src/main/java/io/openmessaging/rocketmq/promise/DefaultPromise.java index c863ccf6ade2848eb61cc2cca789cc9bb2d50366..3e4bd266ce117fb52dd78b3cf0caa9f624e29972 100644 --- a/openmessaging/src/main/java/io/openmessaging/rocketmq/promise/DefaultPromise.java +++ b/openmessaging/src/main/java/io/openmessaging/rocketmq/promise/DefaultPromise.java @@ -77,7 +77,7 @@ public class DefaultPromise implements Promise { } else { long waitTime = timeout - (System.currentTimeMillis() - createTime); if (waitTime > 0) { - for (;; ) { + for (; ; ) { try { lock.wait(waitTime); } catch (InterruptedException e) { diff --git a/openmessaging/src/test/java/io/openmessaging/rocketmq/consumer/LocalMessageCacheTest.java b/openmessaging/src/test/java/io/openmessaging/rocketmq/consumer/LocalMessageCacheTest.java index ae4d3ed537bde5c0bd02660046647a88ecf93498..851c283dd7b8238e523bfd747525833d79c9558c 100644 --- a/openmessaging/src/test/java/io/openmessaging/rocketmq/consumer/LocalMessageCacheTest.java +++ b/openmessaging/src/test/java/io/openmessaging/rocketmq/consumer/LocalMessageCacheTest.java @@ -75,7 +75,7 @@ public class LocalMessageCacheTest { @Test public void testSubmitConsumeRequest() throws Exception { - byte [] body = new byte[]{'1', '2', '3'}; + byte[] body = new byte[] {'1', '2', '3'}; MessageExt consumedMsg = new MessageExt(); consumedMsg.setMsgId("NewMsgId"); consumedMsg.setBody(body); diff --git a/openmessaging/src/test/java/io/openmessaging/rocketmq/consumer/PullConsumerImplTest.java b/openmessaging/src/test/java/io/openmessaging/rocketmq/consumer/PullConsumerImplTest.java index 277a5c65f27072162787c1096e4356eff08558d5..843ddb788053397a9811286d3bacf8c10a9ab354 100644 --- a/openmessaging/src/test/java/io/openmessaging/rocketmq/consumer/PullConsumerImplTest.java +++ b/openmessaging/src/test/java/io/openmessaging/rocketmq/consumer/PullConsumerImplTest.java @@ -46,13 +46,13 @@ public class PullConsumerImplTest { @Mock private DefaultMQPullConsumer rocketmqPullConsumer; - private LocalMessageCache localMessageCache = - spy(new LocalMessageCache(rocketmqPullConsumer, new ClientConfig())); + private LocalMessageCache localMessageCache = null; @Before public void init() throws NoSuchFieldException, IllegalAccessException { final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory .getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace"); + consumer = messagingAccessPoint.createPullConsumer(queueName, OMS.newKeyValue().put(NonStandardKeys.CONSUMER_GROUP, "TestGroup")); @@ -60,6 +60,10 @@ public class PullConsumerImplTest { field.setAccessible(true); field.set(consumer, rocketmqPullConsumer); //Replace + ClientConfig clientConfig = new ClientConfig(); + clientConfig.setOmsOperationTimeout(200); + localMessageCache = spy(new LocalMessageCache(rocketmqPullConsumer, clientConfig)); + field = PullConsumerImpl.class.getDeclaredField("localMessageCache"); field.setAccessible(true); field.set(consumer, localMessageCache); diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingHelper.java b/remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingHelper.java index 40c594313a89571e797b3aebde6d987c35d497c8..79957305c0fcac5142a09a3e4f78de07c6214200 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingHelper.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/common/RemotingHelper.java @@ -17,11 +17,6 @@ package org.apache.rocketmq.remoting.common; import io.netty.channel.Channel; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.nio.ByteBuffer; -import java.nio.channels.SocketChannel; import org.apache.rocketmq.remoting.exception.RemotingConnectException; import org.apache.rocketmq.remoting.exception.RemotingSendRequestException; import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; @@ -29,6 +24,12 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; + public class RemotingHelper { public static final String ROCKETMQ_REMOTING = "RocketmqRemoting"; public static final String DEFAULT_CHARSET = "UTF-8"; @@ -168,17 +169,6 @@ public class RemotingHelper { return ""; } - public static String parseChannelRemoteName(final Channel channel) { - if (null == channel) { - return ""; - } - final InetSocketAddress remote = (InetSocketAddress) channel.remoteAddress(); - if (remote != null) { - return remote.getAddress().getHostName(); - } - return ""; - } - public static String parseSocketAddressAddr(SocketAddress socketAddress) { if (socketAddress != null) { final String addr = socketAddress.toString(); @@ -190,13 +180,4 @@ public class RemotingHelper { return ""; } - public static String parseSocketAddressName(SocketAddress socketAddress) { - - final InetSocketAddress addrs = (InetSocketAddress) socketAddress; - if (addrs != null) { - return addrs.getAddress().getHostName(); - } - return ""; - } - } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/common/ServiceThread.java b/remoting/src/main/java/org/apache/rocketmq/remoting/common/ServiceThread.java index 843618900dd4e452d6809909b2f485de867f716c..346e72c5a2a087fa4b184b900f831f1b0218dfee 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/common/ServiceThread.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/common/ServiceThread.java @@ -63,7 +63,7 @@ public abstract class ServiceThread implements Runnable { this.thread.join(this.getJointime()); long eclipseTime = System.currentTimeMillis() - beginTime; log.info("join thread " + this.getServiceName() + " eclipse time(ms) " + eclipseTime + " " - + this.getJointime()); + + this.getJointime()); } catch (InterruptedException e) { log.error("Interrupted", e); } @@ -73,61 +73,6 @@ public abstract class ServiceThread implements Runnable { return JOIN_TIME; } - public void stop() { - this.stop(false); - } - - public void stop(final boolean interrupt) { - this.stopped = true; - log.info("stop thread " + this.getServiceName() + " interrupt " + interrupt); - synchronized (this) { - if (!this.hasNotified) { - this.hasNotified = true; - this.notify(); - } - } - - if (interrupt) { - this.thread.interrupt(); - } - } - - public void makeStop() { - this.stopped = true; - log.info("makestop thread " + this.getServiceName()); - } - - public void wakeup() { - synchronized (this) { - if (!this.hasNotified) { - this.hasNotified = true; - this.notify(); - } - } - } - - protected void waitForRunning(long interval) { - synchronized (this) { - if (this.hasNotified) { - this.hasNotified = false; - this.onWaitEnd(); - return; - } - - try { - this.wait(interval); - } catch (InterruptedException e) { - log.error("Interrupted", e); - } finally { - this.hasNotified = false; - this.onWaitEnd(); - } - } - } - - protected void onWaitEnd() { - } - public boolean isStopped() { return stopped; } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyDecoder.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyDecoder.java index 4ed156d5450054676e034a969fc03ebbeee20836..6e99b32f4cbf6f743b3fdcb7c893ca7b5aa81012 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyDecoder.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyDecoder.java @@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory; public class NettyDecoder extends LengthFieldBasedFrameDecoder { private static final Logger log = LoggerFactory.getLogger(RemotingHelper.ROCKETMQ_REMOTING); - private static final int FRAME_MAX_LENGTH = // + private static final int FRAME_MAX_LENGTH = Integer.parseInt(System.getProperty("com.rocketmq.remoting.frameMaxLength", "16777216")); public NettyDecoder() { diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingAbstract.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingAbstract.java index ba74b53260642af9b8b0633ae87369048ba3b687..614346285a91263bf0fccc47f547edf8f7cb1640 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingAbstract.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingAbstract.java @@ -90,6 +90,7 @@ public abstract class NettyRemotingAbstract { /** * Constructor, specifying capacity of one-way and asynchronous semaphores. + * * @param permitsOneway Number of permits for one-way requests. * @param permitsAsync Number of permits for asynchronous requests. */ @@ -100,12 +101,14 @@ public abstract class NettyRemotingAbstract { /** * Custom channel event listener. + * * @return custom channel event listener if defined; null otherwise. */ public abstract ChannelEventListener getChannelEventListener(); /** * Put a netty event to the executor. + * * @param event Netty event instance. */ public void putNettyEvent(final NettyEvent event) { @@ -116,13 +119,14 @@ public abstract class NettyRemotingAbstract { * Entry of incoming command processing. * *

    - * Note: - * The incoming remoting command may be - *

      - *
    • An inquiry request from a remote peer component;
    • - *
    • A response to a previous request issued by this very participant.
    • - *
    + * Note: + * The incoming remoting command may be + *
      + *
    • An inquiry request from a remote peer component;
    • + *
    • A response to a previous request issued by this very participant.
    • + *
    *

    + * * @param ctx Channel handler context. * @param msg incoming remoting command. * @throws Exception if there were any error while processing the incoming command. @@ -145,6 +149,7 @@ public abstract class NettyRemotingAbstract { /** * Process incoming request command issued by remote peer. + * * @param ctx channel handler context. * @param cmd request command. */ @@ -188,7 +193,7 @@ public abstract class NettyRemotingAbstract { log.error(cmd.toString()); if (!cmd.isOnewayRPC()) { - final RemotingCommand response = RemotingCommand.createResponseCommand(RemotingSysResponseCode.SYSTEM_ERROR, // + final RemotingCommand response = RemotingCommand.createResponseCommand(RemotingSysResponseCode.SYSTEM_ERROR, RemotingHelper.exceptionSimpleDesc(e)); response.setOpaque(opaque); ctx.writeAndFlush(response); @@ -210,9 +215,9 @@ public abstract class NettyRemotingAbstract { pair.getObject2().submit(requestTask); } catch (RejectedExecutionException e) { if ((System.currentTimeMillis() % 10000) == 0) { - log.warn(RemotingHelper.parseChannelRemoteAddr(ctx.channel()) // - + ", too many requests and system thread pool busy, RejectedExecutionException " // - + pair.getObject2().toString() // + log.warn(RemotingHelper.parseChannelRemoteAddr(ctx.channel()) + + ", too many requests and system thread pool busy, RejectedExecutionException " + + pair.getObject2().toString() + " request code: " + cmd.getCode()); } @@ -235,6 +240,7 @@ public abstract class NettyRemotingAbstract { /** * Process response from remote peer to the previous issued requests. + * * @param ctx channel handler context. * @param cmd response command instance. */ @@ -261,7 +267,6 @@ public abstract class NettyRemotingAbstract { /** * Execute callback in callback executor. If callback executor is null, run directly in current thread - * @param responseFuture */ private void executeInvokeCallback(final ResponseFuture responseFuture) { boolean runInThisThread = false; @@ -297,12 +302,14 @@ public abstract class NettyRemotingAbstract { /** * Custom RPC hook. + * * @return RPC hook if specified; null otherwise. */ public abstract RPCHook getRPCHook(); /** * This method specifies thread pool to use while invoking callback methods. + * * @return Dedicated thread pool instance if specified; or null if the callback is supposed to be executed in the * netty event-loop thread. */ @@ -310,7 +317,7 @@ public abstract class NettyRemotingAbstract { /** *

    - * This method is periodically invoked to scan and expire deprecated request. + * This method is periodically invoked to scan and expire deprecated request. *

    */ public void scanResponseTable() { @@ -337,7 +344,8 @@ public abstract class NettyRemotingAbstract { } } - public RemotingCommand invokeSyncImpl(final Channel channel, final RemotingCommand request, final long timeoutMillis) + public RemotingCommand invokeSyncImpl(final Channel channel, final RemotingCommand request, + final long timeoutMillis) throws InterruptedException, RemotingSendRequestException, RemotingTimeoutException { final int opaque = request.getOpaque(); @@ -422,10 +430,10 @@ public abstract class NettyRemotingAbstract { throw new RemotingTooMuchRequestException("invokeAsyncImpl invoke too fast"); } else { String info = - String.format("invokeAsyncImpl tryAcquire semaphore timeout, %dms, waiting thread nums: %d semaphoreAsyncValue: %d", // - timeoutMillis, // - this.semaphoreAsync.getQueueLength(), // - this.semaphoreAsync.availablePermits()// + String.format("invokeAsyncImpl tryAcquire semaphore timeout, %dms, waiting thread nums: %d semaphoreAsyncValue: %d", + timeoutMillis, + this.semaphoreAsync.getQueueLength(), + this.semaphoreAsync.availablePermits() ); log.warn(info); throw new RemotingTimeoutException(info); @@ -459,10 +467,10 @@ public abstract class NettyRemotingAbstract { throw new RemotingTooMuchRequestException("invokeOnewayImpl invoke too fast"); } else { String info = String.format( - "invokeOnewayImpl tryAcquire semaphore timeout, %dms, waiting thread nums: %d semaphoreAsyncValue: %d", // - timeoutMillis, // - this.semaphoreOneway.getQueueLength(), // - this.semaphoreOneway.availablePermits()// + "invokeOnewayImpl tryAcquire semaphore timeout, %dms, waiting thread nums: %d semaphoreAsyncValue: %d", + timeoutMillis, + this.semaphoreOneway.getQueueLength(), + this.semaphoreOneway.availablePermits() ); log.warn(info); throw new RemotingTimeoutException(info); diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingClient.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingClient.java index db6a7e4bab4e78882b37c6590d074996a29b0b05..34f560fdab1f202665488962df18680fc12b0176 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingClient.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingClient.java @@ -92,7 +92,7 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti this(nettyClientConfig, null); } - public NettyRemotingClient(final NettyClientConfig nettyClientConfig, // + public NettyRemotingClient(final NettyClientConfig nettyClientConfig, final ChannelEventListener channelEventListener) { super(nettyClientConfig.getClientOnewaySemaphoreValue(), nettyClientConfig.getClientAsyncSemaphoreValue()); this.nettyClientConfig = nettyClientConfig; @@ -130,8 +130,8 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti @Override public void start() { - this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(// - nettyClientConfig.getClientWorkerThreads(), // + this.defaultEventExecutorGroup = new DefaultEventExecutorGroup( + nettyClientConfig.getClientWorkerThreads(), new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); @@ -142,7 +142,7 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti } }); - Bootstrap handler = this.bootstrap.group(this.eventLoopGroupWorker).channel(NioSocketChannel.class)// + Bootstrap handler = this.bootstrap.group(this.eventLoopGroupWorker).channel(NioSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.SO_KEEPALIVE, false) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, nettyClientConfig.getConnectTimeoutMillis()) @@ -322,7 +322,7 @@ public class NettyRemotingClient extends NettyRemotingAbstract implements Remoti if (update) { Collections.shuffle(addrs); - log.info("name server address updated. NEW : {} , OLD: {}",addrs,old); + log.info("name server address updated. NEW : {} , OLD: {}", addrs, old); this.namesrvAddrList.set(addrs); } } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingServer.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingServer.java index b2041b2ac21dcbd67fae8cd7ec1e1e48517a6468..7cf82c96d0bddb1ac81a36cc9f55b2a2964d5538 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingServer.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyRemotingServer.java @@ -78,7 +78,8 @@ public class NettyRemotingServer extends NettyRemotingAbstract implements Remoti this(nettyServerConfig, null); } - public NettyRemotingServer(final NettyServerConfig nettyServerConfig, final ChannelEventListener channelEventListener) { + public NettyRemotingServer(final NettyServerConfig nettyServerConfig, + final ChannelEventListener channelEventListener) { super(nettyServerConfig.getServerOnewaySemaphoreValue(), nettyServerConfig.getServerAsyncSemaphoreValue()); this.serverBootstrap = new ServerBootstrap(); this.nettyServerConfig = nettyServerConfig; diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyServerConfig.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyServerConfig.java index c4354e9264fe708cc600c778027ef8f430e5ee8a..a5e2a232dd59a101948ef722386fe2eabd35e1c6 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyServerConfig.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettyServerConfig.java @@ -16,11 +16,6 @@ */ package org.apache.rocketmq.remoting.netty; -/** - - * - * - */ public class NettyServerConfig implements Cloneable { private int listenPort = 8888; private int serverWorkerThreads = 8; diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettySystemConfig.java b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettySystemConfig.java index 52556fc0b70691fbb0d6daf2ad4cc541e1ac25e6..2e0a81e87a1c5fdf7de3a818b7d6eccaa2a73217 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettySystemConfig.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/netty/NettySystemConfig.java @@ -20,23 +20,23 @@ package org.apache.rocketmq.remoting.netty; public class NettySystemConfig { public static final String COM_ROCKETMQ_REMOTING_NETTY_POOLED_BYTE_BUF_ALLOCATOR_ENABLE = "com.rocketmq.remoting.nettyPooledByteBufAllocatorEnable"; - public static final String COM_ROCKETMQ_REMOTING_SOCKET_SNDBUF_SIZE = // + public static final String COM_ROCKETMQ_REMOTING_SOCKET_SNDBUF_SIZE = "com.rocketmq.remoting.socket.sndbuf.size"; - public static final String COM_ROCKETMQ_REMOTING_SOCKET_RCVBUF_SIZE = // + public static final String COM_ROCKETMQ_REMOTING_SOCKET_RCVBUF_SIZE = "com.rocketmq.remoting.socket.rcvbuf.size"; - public static final String COM_ROCKETMQ_REMOTING_CLIENT_ASYNC_SEMAPHORE_VALUE = // + public static final String COM_ROCKETMQ_REMOTING_CLIENT_ASYNC_SEMAPHORE_VALUE = "com.rocketmq.remoting.clientAsyncSemaphoreValue"; - public static final String COM_ROCKETMQ_REMOTING_CLIENT_ONEWAY_SEMAPHORE_VALUE = // + public static final String COM_ROCKETMQ_REMOTING_CLIENT_ONEWAY_SEMAPHORE_VALUE = "com.rocketmq.remoting.clientOnewaySemaphoreValue"; - public static final boolean NETTY_POOLED_BYTE_BUF_ALLOCATOR_ENABLE = // + public static final boolean NETTY_POOLED_BYTE_BUF_ALLOCATOR_ENABLE = Boolean .parseBoolean(System.getProperty(COM_ROCKETMQ_REMOTING_NETTY_POOLED_BYTE_BUF_ALLOCATOR_ENABLE, "false")); - public static final int CLIENT_ASYNC_SEMAPHORE_VALUE = // + public static final int CLIENT_ASYNC_SEMAPHORE_VALUE = Integer.parseInt(System.getProperty(COM_ROCKETMQ_REMOTING_CLIENT_ASYNC_SEMAPHORE_VALUE, "65535")); - public static final int CLIENT_ONEWAY_SEMAPHORE_VALUE = // + public static final int CLIENT_ONEWAY_SEMAPHORE_VALUE = Integer.parseInt(System.getProperty(COM_ROCKETMQ_REMOTING_CLIENT_ONEWAY_SEMAPHORE_VALUE, "65535")); - public static int socketSndbufSize = // + public static int socketSndbufSize = Integer.parseInt(System.getProperty(COM_ROCKETMQ_REMOTING_SOCKET_SNDBUF_SIZE, "65535")); - public static int socketRcvbufSize = // + public static int socketRcvbufSize = Integer.parseInt(System.getProperty(COM_ROCKETMQ_REMOTING_SOCKET_RCVBUF_SIZE, "65535")); } diff --git a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java index bee9b12c8037cd78676f77528932d7a20ea463ca..2f8cb388440fb17a1f97dfb1a177d99f9585e189 100644 --- a/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java +++ b/remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java @@ -43,7 +43,7 @@ public class RemotingCommand { private static final Map CANONICAL_NAME_CACHE = new HashMap(); // 1, Oneway // 1, RESPONSE_COMMAND - private static final Map NOT_NULL_ANNOTATION_CACHE = new HashMap(); + private static final Map NULLABLE_FIELD_CACHE = new HashMap(); private static final String STRING_CANONICAL_NAME = String.class.getCanonicalName(); private static final String DOUBLE_CANONICAL_NAME_1 = Double.class.getCanonicalName(); private static final String DOUBLE_CANONICAL_NAME_2 = double.class.getCanonicalName(); @@ -252,11 +252,9 @@ public class RemotingCommand { try { String value = this.extFields.get(fieldName); if (null == value) { - Annotation annotation = getNotNullAnnotation(field); - if (annotation != null) { + if (!isFieldNullable(field)) { throw new RemotingCommandException("the custom field <" + fieldName + "> is null"); } - continue; } @@ -305,16 +303,14 @@ public class RemotingCommand { return field; } - private Annotation getNotNullAnnotation(Field field) { - Annotation annotation = NOT_NULL_ANNOTATION_CACHE.get(field); - - if (annotation == null) { - annotation = field.getAnnotation(CFNotNull.class); - synchronized (NOT_NULL_ANNOTATION_CACHE) { - NOT_NULL_ANNOTATION_CACHE.put(field, annotation); + private boolean isFieldNullable(Field field) { + if (!NULLABLE_FIELD_CACHE.containsKey(field)) { + Annotation annotation = field.getAnnotation(CFNotNull.class); + synchronized (NULLABLE_FIELD_CACHE) { + NULLABLE_FIELD_CACHE.put(field, annotation == null); } } - return annotation; + return NULLABLE_FIELD_CACHE.get(field); } private String getCanonicalName(Class clazz) { diff --git a/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/RemotingCommandTest.java b/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/RemotingCommandTest.java index 0f5da6e198a121b7998e902a00e9b6b951301155..2bd41cec839d8365eb46da5e029f03310f74d225 100644 --- a/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/RemotingCommandTest.java +++ b/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/RemotingCommandTest.java @@ -16,8 +16,11 @@ */ package org.apache.rocketmq.remoting.protocol; +import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.nio.ByteBuffer; import org.apache.rocketmq.remoting.CommandCustomHeader; +import org.apache.rocketmq.remoting.annotation.CFNotNull; import org.apache.rocketmq.remoting.exception.RemotingCommandException; import org.junit.Test; @@ -29,7 +32,7 @@ public class RemotingCommandTest { int source = 261; SerializeType type = SerializeType.JSON; byte[] result = RemotingCommand.markProtocolType(source, type); - assertThat(result).isEqualTo(new byte[]{0, 0, 1, 5}); + assertThat(result).isEqualTo(new byte[] {0, 0, 1, 5}); } @Test @@ -37,7 +40,7 @@ public class RemotingCommandTest { int source = 16777215; SerializeType type = SerializeType.ROCKETMQ; byte[] result = RemotingCommand.markProtocolType(source, type); - assertThat(result).isEqualTo(new byte[]{1, -1, -1, -1}); + assertThat(result).isEqualTo(new byte[] {1, -1, -1, -1}); } @Test @@ -58,7 +61,7 @@ public class RemotingCommandTest { int code = RemotingSysResponseCode.SUCCESS; String remark = "Sample remark"; - RemotingCommand cmd = RemotingCommand.createResponseCommand(code ,remark, SampleCommandCustomHeader.class); + RemotingCommand cmd = RemotingCommand.createResponseCommand(code, remark, SampleCommandCustomHeader.class); assertThat(cmd.getCode()).isEqualTo(code); assertThat(cmd.getVersion()).isEqualTo(2333); assertThat(cmd.getRemark()).isEqualTo(remark); @@ -71,7 +74,7 @@ public class RemotingCommandTest { int code = RemotingSysResponseCode.SUCCESS; String remark = "Sample remark"; - RemotingCommand cmd = RemotingCommand.createResponseCommand(code ,remark); + RemotingCommand cmd = RemotingCommand.createResponseCommand(code, remark); assertThat(cmd.getCode()).isEqualTo(code); assertThat(cmd.getVersion()).isEqualTo(2333); assertThat(cmd.getRemark()).isEqualTo(remark); @@ -84,7 +87,7 @@ public class RemotingCommandTest { int code = RemotingSysResponseCode.SUCCESS; String remark = "Sample remark"; - RemotingCommand cmd = RemotingCommand.createResponseCommand(code ,remark, CommandCustomHeader.class); + RemotingCommand cmd = RemotingCommand.createResponseCommand(code, remark, CommandCustomHeader.class); assertThat(cmd).isNull(); } @@ -128,7 +131,7 @@ public class RemotingCommandTest { int code = 103; //org.apache.rocketmq.common.protocol.RequestCode.REGISTER_BROKER CommandCustomHeader header = new SampleCommandCustomHeader(); RemotingCommand cmd = RemotingCommand.createRequestCommand(code, header); - cmd.setBody(new byte[] { 0, 1, 2, 3, 4}); + cmd.setBody(new byte[] {0, 1, 2, 3, 4}); ByteBuffer buffer = cmd.encode(); @@ -141,7 +144,7 @@ public class RemotingCommandTest { RemotingCommand decodedCommand = RemotingCommand.decode(buffer); assertThat(decodedCommand.getSerializeTypeCurrentRPC()).isEqualTo(SerializeType.JSON); - assertThat(decodedCommand.getBody()).isEqualTo(new byte[]{ 0, 1, 2, 3, 4}); + assertThat(decodedCommand.getBody()).isEqualTo(new byte[] {0, 1, 2, 3, 4}); } @Test @@ -179,6 +182,32 @@ public class RemotingCommandTest { assertThat(((ExtFieldsHeader) decodedHeader).isBooleanValue()).isEqualTo(true); assertThat(((ExtFieldsHeader) decodedHeader).getDoubleValue()).isBetween(0.617, 0.619); } + + @Test + public void testNotNullField() throws Exception { + RemotingCommand remotingCommand = new RemotingCommand(); + Method method = RemotingCommand.class.getDeclaredMethod("isFieldNullable", Field.class); + method.setAccessible(true); + + Field nullString = FieldTestClass.class.getDeclaredField("nullString"); + assertThat(method.invoke(remotingCommand, nullString)).isEqualTo(false); + + Field nullableString = FieldTestClass.class.getDeclaredField("nullable"); + assertThat(method.invoke(remotingCommand, nullableString)).isEqualTo(true); + + Field value = FieldTestClass.class.getDeclaredField("value"); + assertThat(method.invoke(remotingCommand, value)).isEqualTo(false); + } +} + +class FieldTestClass { + @CFNotNull + String nullString = null; + + String nullable = null; + + @CFNotNull + String value = "NotNull"; } class SampleCommandCustomHeader implements CommandCustomHeader { diff --git a/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/RemotingSerializableTest.java b/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/RemotingSerializableTest.java index 38548cd882f0bbb05c85ed01679b0ce972dae8c0..3e8b7a90ae625b3b8600d02f26821dacf2eef2f7 100644 --- a/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/RemotingSerializableTest.java +++ b/remoting/src/test/java/org/apache/rocketmq/remoting/protocol/RemotingSerializableTest.java @@ -86,7 +86,7 @@ class Sample { private String stringValue = "string"; private int intValue = 2333; private Integer integerValue = 666; - private double[] doubleArray = new double[]{0.618, 1.618}; + private double[] doubleArray = new double[] {0.618, 1.618}; private List stringList = Arrays.asList("a", "o", "e", "i", "u", "v"); public String getStringValue() { @@ -136,7 +136,7 @@ class Sample { if (o == null || getClass() != o.getClass()) return false; - Sample sample = (Sample)o; + Sample sample = (Sample) o; if (intValue != sample.intValue) return false; diff --git a/store/src/main/java/org/apache/rocketmq/store/AppendMessageCallback.java b/store/src/main/java/org/apache/rocketmq/store/AppendMessageCallback.java index 16a62fa48cf3d3ead3d1702f450719d664073d69..d33763847f94e779218e3346af24ce116bb830c1 100644 --- a/store/src/main/java/org/apache/rocketmq/store/AppendMessageCallback.java +++ b/store/src/main/java/org/apache/rocketmq/store/AppendMessageCallback.java @@ -27,23 +27,17 @@ public interface AppendMessageCallback { /** * After message serialization, write MapedByteBuffer * - * @param byteBuffer - * @param maxBlank - * @param msg * @return How many bytes to write */ AppendMessageResult doAppend(final long fileFromOffset, final ByteBuffer byteBuffer, - final int maxBlank, final MessageExtBrokerInner msg); + final int maxBlank, final MessageExtBrokerInner msg); /** * After batched message serialization, write MapedByteBuffer * - * @param byteBuffer - * @param maxBlank * @param messageExtBatch, backed up by a byte array - * * @return How many bytes to write */ AppendMessageResult doAppend(final long fileFromOffset, final ByteBuffer byteBuffer, - final int maxBlank, final MessageExtBatch messageExtBatch); + final int maxBlank, final MessageExtBatch messageExtBatch); } diff --git a/store/src/main/java/org/apache/rocketmq/store/CommitLog.java b/store/src/main/java/org/apache/rocketmq/store/CommitLog.java index 0810d0ca3d6f85f86d757577178ca19fa9ce9e3e..edd68a58420328dc2f20b44f2967b30badf9c43e 100644 --- a/store/src/main/java/org/apache/rocketmq/store/CommitLog.java +++ b/store/src/main/java/org/apache/rocketmq/store/CommitLog.java @@ -62,6 +62,7 @@ public class CommitLog { private volatile long beginTimeInLock = 0; private final PutMessageLock putMessageLock; + public CommitLog(final DefaultMessageStore defaultMessageStore) { this.mappedFileQueue = new MappedFileQueue(defaultMessageStore.getMessageStoreConfig().getStorePathCommitLog(), defaultMessageStore.getMessageStoreConfig().getMapedFileSizeCommitLog(), defaultMessageStore.getAllocateMappedFileService()); @@ -77,11 +78,12 @@ public class CommitLog { this.appendMessageCallback = new DefaultAppendMessageCallback(defaultMessageStore.getMessageStoreConfig().getMaxMessageSize()); batchEncoderThreadLocal = new ThreadLocal() { - @Override protected MessageExtBatchEncoder initialValue() { + @Override + protected MessageExtBatchEncoder initialValue() { return new MessageExtBatchEncoder(defaultMessageStore.getMessageStoreConfig().getMaxMessageSize()); } }; - this.putMessageLock = defaultMessageStore.getMessageStoreConfig().isUseReentrantLockWhenPutMessage() ? new PutMessageReentrantLock() : new PutMessageSpinLock(); + this.putMessageLock = defaultMessageStore.getMessageStoreConfig().isUseReentrantLockWhenPutMessage() ? new PutMessageReentrantLock() : new PutMessageSpinLock(); } @@ -125,11 +127,11 @@ public class CommitLog { return this.mappedFileQueue.remainHowManyDataToFlush(); } - public int deleteExpiredFile(// - final long expiredTime, // - final int deleteFilesInterval, // - final long intervalForcibly, // - final boolean cleanImmediately// + public int deleteExpiredFile( + final long expiredTime, + final int deleteFilesInterval, + final long intervalForcibly, + final boolean cleanImmediately ) { return this.mappedFileQueue.deleteExpiredFileByTime(expiredTime, deleteFilesInterval, intervalForcibly, cleanImmediately); } @@ -244,43 +246,30 @@ public class CommitLog { byte[] bytesContent = new byte[totalSize]; - // 3 BODYCRC int bodyCRC = byteBuffer.getInt(); - // 4 QUEUEID int queueId = byteBuffer.getInt(); - // 5 FLAG int flag = byteBuffer.getInt(); - // 6 QUEUEOFFSET long queueOffset = byteBuffer.getLong(); - // 7 PHYSICALOFFSET long physicOffset = byteBuffer.getLong(); - // 8 SYSFLAG int sysFlag = byteBuffer.getInt(); - // 9 BORNTIMESTAMP long bornTimeStamp = byteBuffer.getLong(); - // 10 ByteBuffer byteBuffer1 = byteBuffer.get(bytesContent, 0, 8); - // 11 STORETIMESTAMP long storeTimestamp = byteBuffer.getLong(); - // 12 ByteBuffer byteBuffer2 = byteBuffer.get(bytesContent, 0, 8); - // 13 RECONSUMETIMES int reconsumeTimes = byteBuffer.getInt(); - // 14 Prepared Transaction Offset long preparedTransactionOffset = byteBuffer.getLong(); - // 15 BODY int bodyLen = byteBuffer.getInt(); if (bodyLen > 0) { if (readBody) { @@ -298,7 +287,6 @@ public class CommitLog { } } - // 16 TOPIC byte topicLen = byteBuffer.get(); byteBuffer.get(bytesContent, 0, topicLen); String topic = new String(bytesContent, 0, topicLen, MessageDecoder.CHARSET_UTF8); @@ -307,7 +295,6 @@ public class CommitLog { String keys = ""; String uniqKey = null; - // 17 properties short propertiesLength = byteBuffer.getShort(); Map propertiesMap = null; if (propertiesLength > 0) { @@ -355,19 +342,19 @@ public class CommitLog { return new DispatchRequest(totalSize, false/* success */); } - return new DispatchRequest(// - topic, // 1 - queueId, // 2 - physicOffset, // 3 - totalSize, // 4 - tagsCode, // 5 - storeTimestamp, // 6 - queueOffset, // 7 - keys, // 8 - uniqKey, //9 - sysFlag, // 10 - preparedTransactionOffset, // 11 - propertiesMap // 12 + return new DispatchRequest( + topic, + queueId, + physicOffset, + totalSize, + tagsCode, + storeTimestamp, + queueOffset, + keys, + uniqKey, + sysFlag, + preparedTransactionOffset, + propertiesMap ); } catch (Exception e) { } @@ -376,24 +363,23 @@ public class CommitLog { } private static int calMsgLength(int bodyLength, int topicLength, int propertiesLength) { - final int msgLen = 4 // 1 TOTALSIZE - + 4 // 2 MAGICCODE - + 4 // 3 BODYCRC - + 4 // 4 QUEUEID - + 4 // 5 FLAG - + 8 // 6 QUEUEOFFSET - + 8 // 7 PHYSICALOFFSET - + 4 // 8 SYSFLAG - + 8 // 9 BORNTIMESTAMP - + 8 // 10 BORNHOST - + 8 // 11 STORETIMESTAMP - + 8 // 12 STOREHOSTADDRESS - + 4 // 13 RECONSUMETIMES - + 8 // 14 Prepared Transaction Offset - + 4 + (bodyLength > 0 ? bodyLength : 0) // 14 BODY - + 1 + topicLength // 15 TOPIC - + 2 + (propertiesLength > 0 ? propertiesLength : 0) // 16 - // propertiesLength + final int msgLen = 4 //TOTALSIZE + + 4 //MAGICCODE + + 4 //BODYCRC + + 4 //QUEUEID + + 4 //FLAG + + 8 //QUEUEOFFSET + + 8 //PHYSICALOFFSET + + 4 //SYSFLAG + + 8 //BORNTIMESTAMP + + 8 //BORNHOST + + 8 //STORETIMESTAMP + + 8 //STOREHOSTADDRESS + + 4 //RECONSUMETIMES + + 8 //Prepared Transaction Offset + + 4 + (bodyLength > 0 ? bodyLength : 0) //BODY + + 1 + topicLength //TOPIC + + 2 + (propertiesLength > 0 ? propertiesLength : 0) //propertiesLength + 0; return msgLen; } @@ -500,18 +486,18 @@ public class CommitLog { return false; } - if (this.defaultMessageStore.getMessageStoreConfig().isMessageIndexEnable()// + if (this.defaultMessageStore.getMessageStoreConfig().isMessageIndexEnable() && this.defaultMessageStore.getMessageStoreConfig().isMessageIndexSafe()) { if (storeTimestamp <= this.defaultMessageStore.getStoreCheckpoint().getMinTimestampIndex()) { - log.info("find check timestamp, {} {}", // - storeTimestamp, // + log.info("find check timestamp, {} {}", + storeTimestamp, UtilAll.timeMillisToHumanString(storeTimestamp)); return true; } } else { if (storeTimestamp <= this.defaultMessageStore.getStoreCheckpoint().getMinTimestamp()) { - log.info("find check timestamp, {} {}", // - storeTimestamp, // + log.info("find check timestamp, {} {}", + storeTimestamp, UtilAll.timeMillisToHumanString(storeTimestamp)); return true; } @@ -547,7 +533,7 @@ public class CommitLog { int queueId = msg.getQueueId(); final int tranType = MessageSysFlag.getTransactionValue(msg.getSysFlag()); - if (tranType == MessageSysFlag.TRANSACTION_NOT_TYPE// + if (tranType == MessageSysFlag.TRANSACTION_NOT_TYPE || tranType == MessageSysFlag.TRANSACTION_COMMIT_TYPE) { // Delay Delivery if (msg.getDelayTimeLevel() > 0) { @@ -677,7 +663,7 @@ public class CommitLog { if (messageExt.isWaitStoreMsgOK()) { // Determine whether to wait if (service.isSlaveOK(result.getWroteOffset() + result.getWroteBytes())) { - GroupCommitRequest request = new GroupCommitRequest(result.getWroteOffset() + result.getWroteBytes()); + GroupCommitRequest request = new GroupCommitRequest(result.getWroteOffset() + result.getWroteBytes()); service.putRequest(request); service.getWaitNotifyObject().wakeupAll(); boolean flushOK = @@ -774,7 +760,6 @@ public class CommitLog { putMessageLock.unlock(); } - if (eclipseTimeInLock > 500) { log.warn("[NOTIFYME]putMessages in lock cost time(ms)={}, bodyLength={} AppendMessageResult={}", eclipseTimeInLock, messageExtBatch.getBody().length, result); } @@ -789,7 +774,6 @@ public class CommitLog { storeStatsService.getSinglePutMessageTopicTimesTotal(messageExtBatch.getTopic()).addAndGet(result.getMsgNum()); storeStatsService.getSinglePutMessageTopicSizeTotal(messageExtBatch.getTopic()).addAndGet(result.getWroteBytes()); - handleDiskFlush(result, putMessageResult, messageExtBatch); handleHA(result, putMessageResult, messageExtBatch); @@ -901,8 +885,6 @@ public class CommitLog { return diff; } - - abstract class FlushCommitLogService extends ServiceThread { protected static final int RETRY_TIMES_OVER = 10; } @@ -1046,23 +1028,19 @@ public class CommitLog { private final CountDownLatch countDownLatch = new CountDownLatch(1); private volatile boolean flushOK = false; - public GroupCommitRequest(long nextOffset) { this.nextOffset = nextOffset; } - public long getNextOffset() { return nextOffset; } - public void wakeupCustomer(final boolean flushOK) { this.flushOK = flushOK; this.countDownLatch.countDown(); } - public boolean waitForFlush(long timeout) { try { this.countDownLatch.await(timeout, TimeUnit.MILLISECONDS); @@ -1270,8 +1248,6 @@ public class CommitLog { // 2 MAGICCODE this.msgStoreItemMemory.putInt(CommitLog.BLANK_MAGIC_CODE); // 3 The remaining space may be any value - // - // Here the length of the specially set maxBlank final long beginTimeMills = CommitLog.this.defaultMessageStore.now(); byteBuffer.put(this.msgStoreItemMemory.array(), 0, maxBlank); @@ -1391,7 +1367,6 @@ public class CommitLog { // 2 MAGICCODE this.msgStoreItemMemory.putInt(CommitLog.BLANK_MAGIC_CODE); // 3 The remaining space may be any value - // //ignore previous read messagesByteBuff.reset(); // Here the length of the specially set maxBlank @@ -1449,7 +1424,6 @@ public class CommitLog { this.maxMessageSize = size; } - public ByteBuffer encode(final MessageExtBatch messageExtBatch) { msgBatchMemory.clear(); //not thread-safe int totalMsgLen = 0; diff --git a/store/src/main/java/org/apache/rocketmq/store/ConsumeQueue.java b/store/src/main/java/org/apache/rocketmq/store/ConsumeQueue.java index 275334c05f3e45df9e628d21e08bf9865242cf2e..379162d7ddb3db1ce78e6cd071fd0544790cb310 100644 --- a/store/src/main/java/org/apache/rocketmq/store/ConsumeQueue.java +++ b/store/src/main/java/org/apache/rocketmq/store/ConsumeQueue.java @@ -350,7 +350,7 @@ public class ConsumeQueue { if (offsetPy >= phyMinOffset) { this.minLogicOffset = result.getMappedFile().getFileFromOffset() + i; log.info("Compute logical min offset: {}, topic: {}, queueId: {}", - this.getMinOffsetInQueue(), this.topic, this.queueId); + this.getMinOffsetInQueue(), this.topic, this.queueId); // This maybe not take effect, when not every consume queue has extend file. if (isExtAddr(tagsCode)) { minExtAddr = tagsCode; @@ -567,9 +567,6 @@ public class ConsumeQueue { /** * Check {@code tagsCode} is address of extend file or tags code. - * - * @param tagsCode - * @return */ public boolean isExtAddr(long tagsCode) { return isExtReadEnable() && this.consumeQueueExt.isExtAddr(tagsCode); diff --git a/store/src/main/java/org/apache/rocketmq/store/ConsumeQueueExt.java b/store/src/main/java/org/apache/rocketmq/store/ConsumeQueueExt.java index 1a177e99d57abf0b4a5b49d635f1f04996a290b5..a118cde73b7e946302161a4c415347c54b4ebcbe 100644 --- a/store/src/main/java/org/apache/rocketmq/store/ConsumeQueueExt.java +++ b/store/src/main/java/org/apache/rocketmq/store/ConsumeQueueExt.java @@ -58,17 +58,17 @@ public class ConsumeQueueExt { /** * Constructor. * - * @param topic topic - * @param queueId id of queue - * @param storePath root dir of files to store. + * @param topic topic + * @param queueId id of queue + * @param storePath root dir of files to store. * @param mappedFileSize file size - * @param bitMapLength bit map length. + * @param bitMapLength bit map length. */ public ConsumeQueueExt(final String topic, - final int queueId, - final String storePath, - final int mappedFileSize, - final int bitMapLength) { + final int queueId, + final String storePath, + final int mappedFileSize, + final int bitMapLength) { this.storePath = storePath; this.mappedFileSize = mappedFileSize; @@ -94,9 +94,6 @@ public class ConsumeQueueExt { *

    * Just test {@code address} is less than 0. *

    - * - * @param address - * @return */ public boolean isExtAddr(final long address) { return address <= MAX_ADDR; @@ -108,9 +105,6 @@ public class ConsumeQueueExt { * if {@code address} is less than 0, return {@code address} - {@link java.lang.Long#MIN_VALUE}; * else, just return {@code address} *

    - * - * @param address - * @return */ public long unDecorate(final long address) { if (isExtAddr(address)) { @@ -126,7 +120,6 @@ public class ConsumeQueueExt { * else, just return {@code offset} *

    * - * @param offset * @return ext address(value is less than 0) */ public long decorate(final long offset) { @@ -140,7 +133,6 @@ public class ConsumeQueueExt { * Get data from buffer. * * @param address less than 0 - * @return */ public CqExtUnit get(final long address) { CqExtUnit cqExtUnit = new CqExtUnit(); @@ -154,9 +146,7 @@ public class ConsumeQueueExt { /** * Get data from buffer, and set to {@code cqExtUnit} * - * @param address less than 0 - * @param cqExtUnit - * @return + * @param address less than 0 */ public boolean get(final long address, final CqExtUnit cqExtUnit) { if (!isExtAddr(address)) { @@ -194,7 +184,6 @@ public class ConsumeQueueExt { * Be careful, this method is not thread safe. *

    * - * @param cqExtUnit * @return success: < 0: fail: >=0 */ public long put(final CqExtUnit cqExtUnit) { @@ -259,8 +248,6 @@ public class ConsumeQueueExt { /** * Load data from file when startup. - * - * @return */ public boolean load() { boolean result = this.mappedFileQueue.load(); @@ -379,9 +366,6 @@ public class ConsumeQueueExt { /** * flush buffer to file. - * - * @param flushLeastPages - * @return */ public boolean flush(final int flushLeastPages) { return this.mappedFileQueue.flush(flushLeastPages); @@ -400,8 +384,6 @@ public class ConsumeQueueExt { *

    * Be careful: it's an address just when invoking this method. *

    - * - * @return */ public long getMaxAddress() { MappedFile mappedFile = this.mappedFileQueue.getLastMappedFile(); @@ -413,8 +395,6 @@ public class ConsumeQueueExt { /** * Minus address saved in file. - * - * @return */ public long getMinAddress() { MappedFile firstFile = this.mappedFileQueue.getFirstMappedFile(); @@ -435,7 +415,8 @@ public class ConsumeQueueExt { public static final int MAX_EXT_UNIT_SIZE = Short.MAX_VALUE; - public CqExtUnit() {} + public CqExtUnit() { + } public CqExtUnit(Long tagsCode, long msgStoreTime, byte[] filterBitMap) { this.tagsCode = tagsCode == null ? 0 : tagsCode; @@ -468,9 +449,6 @@ public class ConsumeQueueExt { /** * build unit from buffer from current position. - * - * @param buffer - * @return */ private boolean read(final ByteBuffer buffer) { if (buffer.position() + 2 > buffer.limit()) { @@ -507,8 +485,6 @@ public class ConsumeQueueExt { *

    * if size <= 0, nothing to do. *

    - * - * @param buffer */ private void readBySkip(final ByteBuffer buffer) { ByteBuffer temp = buffer.slice(); @@ -527,9 +503,6 @@ public class ConsumeQueueExt { *
  • 1. @{code container} can be null, it will be created if null.
  • *
  • 2. if capacity of @{code container} is less than unit size, it will be created also.
  • *
  • 3. Pls be sure that size of unit is not greater than {@link #MAX_EXT_UNIT_SIZE}
  • - * - * @param container - * @return */ private byte[] write(final ByteBuffer container) { this.bitMapSize = (short) (filterBitMap == null ? 0 : filterBitMap.length); @@ -557,8 +530,6 @@ public class ConsumeQueueExt { /** * Calculate unit size by current data. - * - * @return */ private int calcUnitSize() { int sizeTemp = MIN_EXT_UNIT_SIZE + (filterBitMap == null ? 0 : filterBitMap.length); @@ -600,16 +571,23 @@ public class ConsumeQueueExt { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof CqExtUnit)) return false; + if (this == o) + return true; + if (!(o instanceof CqExtUnit)) + return false; CqExtUnit cqExtUnit = (CqExtUnit) o; - if (bitMapSize != cqExtUnit.bitMapSize) return false; - if (msgStoreTime != cqExtUnit.msgStoreTime) return false; - if (size != cqExtUnit.size) return false; - if (tagsCode != cqExtUnit.tagsCode) return false; - if (!Arrays.equals(filterBitMap, cqExtUnit.filterBitMap)) return false; + if (bitMapSize != cqExtUnit.bitMapSize) + return false; + if (msgStoreTime != cqExtUnit.msgStoreTime) + return false; + if (size != cqExtUnit.size) + return false; + if (tagsCode != cqExtUnit.tagsCode) + return false; + if (!Arrays.equals(filterBitMap, cqExtUnit.filterBitMap)) + return false; return true; } diff --git a/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java b/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java index b5bac3f721f62512093b953fa9d5db43658f558f..95a017aee6ff0705599a18d5d9e172c6084dacb7 100644 --- a/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java +++ b/store/src/main/java/org/apache/rocketmq/store/DefaultMessageStore.java @@ -218,9 +218,6 @@ public class DefaultMessageStore implements MessageStore { this.shutdown = false; } - /** - - */ public void shutdown() { if (!this.shutdown) { this.shutdown = true; @@ -392,7 +389,7 @@ public class DefaultMessageStore implements MessageStore { long begin = this.getCommitLog().getBeginTimeInLock(); long diff = this.systemClock.now() - begin; - if (diff < 10000000 // + if (diff < 10000000 && diff > this.messageStoreConfig.getOsPageCacheBusyTimeOutMills()) { return true; } @@ -413,8 +410,9 @@ public class DefaultMessageStore implements MessageStore { return commitLog; } - public GetMessageResult getMessage(final String group, final String topic, final int queueId, final long offset, final int maxMsgNums, - final MessageFilter messageFilter) { + public GetMessageResult getMessage(final String group, final String topic, final int queueId, final long offset, + final int maxMsgNums, + final MessageFilter messageFilter) { if (this.shutdown) { log.warn("message store has shutdown, so getMessage is forbidden"); return null; @@ -578,9 +576,6 @@ public class DefaultMessageStore implements MessageStore { return getResult; } - /** - - */ public long getMaxOffsetInQueue(String topic, int queueId) { ConsumeQueue logic = this.findConsumeQueue(topic, queueId); if (logic != null) { @@ -591,9 +586,6 @@ public class DefaultMessageStore implements MessageStore { return 0; } - /** - - */ public long getMinOffsetInQueue(String topic, int queueId) { ConsumeQueue logic = this.findConsumeQueue(topic, queueId); if (logic != null) { @@ -717,22 +709,27 @@ public class DefaultMessageStore implements MessageStore { long minLogicOffset = logicQueue.getMinLogicOffset(); SelectMappedBufferResult result = logicQueue.getIndexBuffer(minLogicOffset / ConsumeQueue.CQ_STORE_UNIT_SIZE); - if (result != null) { - try { - final long phyOffset = result.getByteBuffer().getLong(); - final int size = result.getByteBuffer().getInt(); - long storeTime = this.getCommitLog().pickupStoreTimestamp(phyOffset, size); - return storeTime; - } catch (Exception e) { - } finally { - result.release(); - } - } + return getStoreTime(result); } return -1; } + private long getStoreTime(SelectMappedBufferResult result) { + if (result != null) { + try { + final long phyOffset = result.getByteBuffer().getLong(); + final int size = result.getByteBuffer().getInt(); + long storeTime = this.getCommitLog().pickupStoreTimestamp(phyOffset, size); + return storeTime; + } catch (Exception e) { + } finally { + result.release(); + } + } + return -1; + } + @Override public long getEarliestMessageTime() { final long minPhyOffset = this.getMinPhyOffset(); @@ -745,17 +742,7 @@ public class DefaultMessageStore implements MessageStore { ConsumeQueue logicQueue = this.findConsumeQueue(topic, queueId); if (logicQueue != null) { SelectMappedBufferResult result = logicQueue.getIndexBuffer(consumeQueueOffset); - if (result != null) { - try { - final long phyOffset = result.getByteBuffer().getLong(); - final int size = result.getByteBuffer().getInt(); - long storeTime = this.getCommitLog().pickupStoreTimestamp(phyOffset, size); - return storeTime; - } catch (Exception ignored) { - } finally { - result.release(); - } - } + return getStoreTime(result); } return -1; @@ -895,9 +882,9 @@ public class DefaultMessageStore implements MessageStore { ConcurrentMap queueTable = next.getValue(); for (ConsumeQueue cq : queueTable.values()) { cq.destroy(); - log.info("cleanUnusedTopic: {} {} ConsumeQueue cleaned", // - cq.getTopic(), // - cq.getQueueId() // + log.info("cleanUnusedTopic: {} {} ConsumeQueue cleaned", + cq.getTopic(), + cq.getQueueId() ); this.commitLog.removeQueueFromTopicQueueTable(cq.getTopic(), cq.getQueueId()); @@ -926,17 +913,17 @@ public class DefaultMessageStore implements MessageStore { long maxCLOffsetInConsumeQueue = nextQT.getValue().getLastOffset(); if (maxCLOffsetInConsumeQueue == -1) { - log.warn("maybe ConsumeQueue was created just now. topic={} queueId={} maxPhysicOffset={} minLogicOffset={}.", // - nextQT.getValue().getTopic(), // - nextQT.getValue().getQueueId(), // - nextQT.getValue().getMaxPhysicOffset(), // + log.warn("maybe ConsumeQueue was created just now. topic={} queueId={} maxPhysicOffset={} minLogicOffset={}.", + nextQT.getValue().getTopic(), + nextQT.getValue().getQueueId(), + nextQT.getValue().getMaxPhysicOffset(), nextQT.getValue().getMinLogicOffset()); } else if (maxCLOffsetInConsumeQueue < minCommitLogOffset) { log.info( - "cleanExpiredConsumerQueue: {} {} consumer queue destroyed, minCommitLogOffset: {} maxCLOffsetInConsumeQueue: {}", // - topic, // - nextQT.getKey(), // - minCommitLogOffset, // + "cleanExpiredConsumerQueue: {} {} consumer queue destroyed, minCommitLogOffset: {} maxCLOffsetInConsumeQueue: {}", + topic, + nextQT.getKey(), + minCommitLogOffset, maxCLOffsetInConsumeQueue); DefaultMessageStore.this.commitLog.removeQueueFromTopicQueueTable(nextQT.getValue().getTopic(), @@ -955,7 +942,8 @@ public class DefaultMessageStore implements MessageStore { } } - public Map getMessageIds(final String topic, final int queueId, long minOffset, long maxOffset, SocketAddress storeHost) { + public Map getMessageIds(final String topic, final int queueId, long minOffset, long maxOffset, + SocketAddress storeHost) { Map messageIds = new HashMap(); if (this.shutdown) { return messageIds; @@ -1075,11 +1063,11 @@ public class DefaultMessageStore implements MessageStore { ConsumeQueue logic = map.get(queueId); if (null == logic) { - ConsumeQueue newLogic = new ConsumeQueue(// - topic, // - queueId, // - StorePathConfigHelper.getStorePathConsumeQueue(this.messageStoreConfig.getStorePathRootDir()), // - this.getMessageStoreConfig().getMapedFileSizeConsumeQueue(), // + ConsumeQueue newLogic = new ConsumeQueue( + topic, + queueId, + StorePathConfigHelper.getStorePathConsumeQueue(this.messageStoreConfig.getStorePathRootDir()), + this.getMessageStoreConfig().getMapedFileSizeConsumeQueue(), this); ConsumeQueue oldLogic = map.putIfAbsent(queueId, newLogic); if (oldLogic != null) { @@ -1111,7 +1099,7 @@ public class DefaultMessageStore implements MessageStore { return false; } - if ((messageTotal + 1) >= maxMsgNums) { + if (maxMsgNums <= messageTotal) { return true; } @@ -1120,7 +1108,7 @@ public class DefaultMessageStore implements MessageStore { return true; } - if ((messageTotal + 1) > this.messageStoreConfig.getMaxTransferCountOnMessageInDisk()) { + if (messageTotal > this.messageStoreConfig.getMaxTransferCountOnMessageInDisk() - 1) { return true; } } else { @@ -1128,7 +1116,7 @@ public class DefaultMessageStore implements MessageStore { return true; } - if ((messageTotal + 1) > this.messageStoreConfig.getMaxTransferCountOnMessageInMemory()) { + if (messageTotal > this.messageStoreConfig.getMaxTransferCountOnMessageInMemory() - 1) { return true; } } @@ -1465,11 +1453,11 @@ public class DefaultMessageStore implements MessageStore { boolean cleanAtOnce = DefaultMessageStore.this.getMessageStoreConfig().isCleanFileForciblyEnable() && this.cleanImmediately; - log.info("begin to delete before {} hours file. timeup: {} spacefull: {} manualDeleteFileSeveralTimes: {} cleanAtOnce: {}", // - fileReservedTime, // - timeup, // - spacefull, // - manualDeleteFileSeveralTimes, // + log.info("begin to delete before {} hours file. timeup: {} spacefull: {} manualDeleteFileSeveralTimes: {} cleanAtOnce: {}", + fileReservedTime, + timeup, + spacefull, + manualDeleteFileSeveralTimes, cleanAtOnce); fileReservedTime *= 60 * 60 * 1000; @@ -1728,7 +1716,7 @@ public class DefaultMessageStore implements MessageStore { private void doReput() { for (boolean doNext = true; this.isCommitLogAvailable() && doNext; ) { - if (DefaultMessageStore.this.getMessageStoreConfig().isDuplicationEnable() // + if (DefaultMessageStore.this.getMessageStoreConfig().isDuplicationEnable() && this.reputFromOffset >= DefaultMessageStore.this.getConfirmOffset()) { break; } @@ -1754,7 +1742,7 @@ public class DefaultMessageStore implements MessageStore { dispatchRequest.getTagsCode(), dispatchRequest.getStoreTimestamp(), dispatchRequest.getBitMap(), dispatchRequest.getPropertiesMap()); } - // FIXED BUG By shijia + this.reputFromOffset += size; readSize += size; if (DefaultMessageStore.this.getMessageStoreConfig().getBrokerRole() == BrokerRole.SLAVE) { diff --git a/store/src/main/java/org/apache/rocketmq/store/DispatchRequest.java b/store/src/main/java/org/apache/rocketmq/store/DispatchRequest.java index 3d33eaf3635834aa15f9d5a5ffce578eba652711..819bb948c758d7ecfab5a982c8b5454b5907daad 100644 --- a/store/src/main/java/org/apache/rocketmq/store/DispatchRequest.java +++ b/store/src/main/java/org/apache/rocketmq/store/DispatchRequest.java @@ -66,23 +66,14 @@ public class DispatchRequest { } public DispatchRequest(int size) { - // 1 this.topic = ""; - // 2 this.queueId = 0; - // 3 this.commitLogOffset = 0; - // 4 this.msgSize = size; - // 5 this.tagsCode = 0; - // 6 this.storeTimestamp = 0; - // 7 this.consumeQueueOffset = 0; - // 8 this.keys = ""; - //9 this.uniqKey = null; this.sysFlag = 0; this.preparedTransactionOffset = 0; @@ -91,23 +82,14 @@ public class DispatchRequest { } public DispatchRequest(int size, boolean success) { - // 1 this.topic = ""; - // 2 this.queueId = 0; - // 3 this.commitLogOffset = 0; - // 4 this.msgSize = size; - // 5 this.tagsCode = 0; - // 6 this.storeTimestamp = 0; - // 7 this.consumeQueueOffset = 0; - // 8 this.keys = ""; - // 9 this.uniqKey = null; this.sysFlag = 0; this.preparedTransactionOffset = 0; diff --git a/store/src/main/java/org/apache/rocketmq/store/MappedFile.java b/store/src/main/java/org/apache/rocketmq/store/MappedFile.java index 42504509aeebbac0d07b5fd0e744a20b2adad1fe..492ac5f26cfafe7848c06e5d08829c922813d0f5 100644 --- a/store/src/main/java/org/apache/rocketmq/store/MappedFile.java +++ b/store/src/main/java/org/apache/rocketmq/store/MappedFile.java @@ -73,7 +73,8 @@ public class MappedFile extends ReferenceResource { init(fileName, fileSize); } - public MappedFile(final String fileName, final int fileSize, final TransientStorePool transientStorePool) throws IOException { + public MappedFile(final String fileName, final int fileSize, + final TransientStorePool transientStorePool) throws IOException { init(fileName, fileSize, transientStorePool); } @@ -142,7 +143,8 @@ public class MappedFile extends ReferenceResource { return TOTAL_MAPPED_VIRTUAL_MEMORY.get(); } - public void init(final String fileName, final int fileSize, final TransientStorePool transientStorePool) throws IOException { + public void init(final String fileName, final int fileSize, + final TransientStorePool transientStorePool) throws IOException { init(fileName, fileSize); this.writeBuffer = transientStorePool.borrowBuffer(); this.transientStorePool = transientStorePool; @@ -209,7 +211,7 @@ public class MappedFile extends ReferenceResource { if (messageExt instanceof MessageExtBrokerInner) { result = cb.doAppend(this.getFileFromOffset(), byteBuffer, this.fileSize - currentPos, (MessageExtBrokerInner) messageExt); } else if (messageExt instanceof MessageExtBatch) { - result = cb.doAppend(this.getFileFromOffset(), byteBuffer, this.fileSize - currentPos, (MessageExtBatch)messageExt); + result = cb.doAppend(this.getFileFromOffset(), byteBuffer, this.fileSize - currentPos, (MessageExtBatch) messageExt); } else { return new AppendMessageResult(AppendMessageStatus.UNKNOWN_ERROR); } @@ -217,16 +219,14 @@ public class MappedFile extends ReferenceResource { this.storeTimestamp = result.getStoreTimestamp(); return result; } - log.error("MappedFile.appendMessage return null, wrotePosition: {} fileSize: {}", currentPos, this.fileSize); + log.error("MappedFile.appendMessage return null, wrotePosition: {} fileSize: {}", currentPos, this.fileSize); return new AppendMessageResult(AppendMessageStatus.UNKNOWN_ERROR); } - public long getFileFromOffset() { return this.fileFromOffset; } - public boolean appendMessage(final byte[] data) { int currentPos = this.wrotePosition.get(); @@ -247,10 +247,8 @@ public class MappedFile extends ReferenceResource { /** * Content of data from offset to offset + length will be wrote to file. * - * @param data * @param offset The offset of the subarray to be used. * @param length The length of the subarray to be used. - * @return */ public boolean appendMessage(final byte[] data, final int offset, final int length) { int currentPos = this.wrotePosition.get(); @@ -270,7 +268,6 @@ public class MappedFile extends ReferenceResource { } /** - * @param flushLeastPages * @return The current flushed position */ public int flush(final int flushLeastPages) { @@ -404,9 +401,6 @@ public class MappedFile extends ReferenceResource { return null; } - /** - - */ public SelectMappedBufferResult selectMappedBuffer(int pos) { int readPosition = getReadPosition(); if (pos < readPosition && pos >= 0) { diff --git a/store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java b/store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java index a8fa36485e27c298e026fb81fcabe80cb9457f86..edf4c9184608b3fef74ce08ac5e4b7149452346d 100644 --- a/store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java +++ b/store/src/main/java/org/apache/rocketmq/store/MappedFileQueue.java @@ -405,7 +405,6 @@ public class MappedFileQueue { break; } - // TODO: Externalize this hardcoded value if (destroy && mappedFile.destroy(1000 * 60)) { files.add(mappedFile); deleteCount++; diff --git a/store/src/main/java/org/apache/rocketmq/store/MessageArrivingListener.java b/store/src/main/java/org/apache/rocketmq/store/MessageArrivingListener.java index dee1bc75274a10044a325f8b878b8b81bc36e3bd..bae7a16168980e4e597763688760779666892f4e 100644 --- a/store/src/main/java/org/apache/rocketmq/store/MessageArrivingListener.java +++ b/store/src/main/java/org/apache/rocketmq/store/MessageArrivingListener.java @@ -21,5 +21,5 @@ import java.util.Map; public interface MessageArrivingListener { void arriving(String topic, int queueId, long logicOffset, long tagsCode, - long msgStoreTime, byte[] filterBitMap, Map properties); + long msgStoreTime, byte[] filterBitMap, Map properties); } diff --git a/store/src/main/java/org/apache/rocketmq/store/MessageFilter.java b/store/src/main/java/org/apache/rocketmq/store/MessageFilter.java index 6b34758b43cdce32348c79fd68ea280a67de0151..3dd0fee2907607bcca82c9fb8f6f736302367cad 100644 --- a/store/src/main/java/org/apache/rocketmq/store/MessageFilter.java +++ b/store/src/main/java/org/apache/rocketmq/store/MessageFilter.java @@ -24,22 +24,20 @@ public interface MessageFilter { * match by tags code or filter bit map which is calculated when message received * and stored in consume queue ext. * - * @param tagsCode tagsCode - * @param cqExtUnit extend unit of consume queue - * @return + * @param tagsCode tagsCode + * @param cqExtUnit extend unit of consume queue */ boolean isMatchedByConsumeQueue(final Long tagsCode, - final ConsumeQueueExt.CqExtUnit cqExtUnit); + final ConsumeQueueExt.CqExtUnit cqExtUnit); /** * match by message content which are stored in commit log. *
    {@code msgBuffer} and {@code properties} are not all null.If invoked in store, * {@code properties} is null;If invoked in {@code PullRequestHoldService}, {@code msgBuffer} is null. * - * @param msgBuffer message buffer in commit log, may be null if not invoked in store. - * @param properties message properties, should decode from buffer if null by yourself. - * @return + * @param msgBuffer message buffer in commit log, may be null if not invoked in store. + * @param properties message properties, should decode from buffer if null by yourself. */ boolean isMatchedByCommitLog(final ByteBuffer msgBuffer, - final Map properties); + final Map properties); } diff --git a/store/src/main/java/org/apache/rocketmq/store/MessageStore.java b/store/src/main/java/org/apache/rocketmq/store/MessageStore.java index 55572ce10f4624553741be9b8ed2510f110d1f5d..907dfe2093b79d86c5b3cca4cc49e02a425a8f46 100644 --- a/store/src/main/java/org/apache/rocketmq/store/MessageStore.java +++ b/store/src/main/java/org/apache/rocketmq/store/MessageStore.java @@ -29,12 +29,14 @@ public interface MessageStore { /** * Load previously stored messages. + * * @return true if success; false otherwise. */ boolean load(); /** * Launch this message store. + * * @throws Exception if there is any error. */ void start() throws Exception; @@ -51,6 +53,7 @@ public interface MessageStore { /** * Store a message into store. + * * @param msg Message instance to store * @return result of store operation. */ @@ -58,6 +61,7 @@ public interface MessageStore { /** * Store a batch of messages. + * * @param messageExtBatch Message batch. * @return result of storing batch messages. */ @@ -80,6 +84,7 @@ public interface MessageStore { /** * Get maximum offset of the topic queue. + * * @param topic Topic name. * @param queueId Queue ID. * @return Maximum offset at present. @@ -88,6 +93,7 @@ public interface MessageStore { /** * Get the minimum offset of the topic queue. + * * @param topic Topic name. * @param queueId Queue ID. * @return Minimum offset at present. @@ -96,6 +102,7 @@ public interface MessageStore { /** * Get the offset of the message in the commit log, which is also known as physical offset. + * * @param topic Topic of the message to lookup. * @param queueId Queue ID. * @param consumeQueueOffset offset of consume queue. @@ -105,6 +112,7 @@ public interface MessageStore { /** * Look up the physical offset of the message whose store timestamp is as specified. + * * @param topic Topic of the message. * @param queueId Queue ID. * @param timestamp Timestamp to look up. @@ -114,6 +122,7 @@ public interface MessageStore { /** * Look up the message by given commit log offset. + * * @param commitLogOffset physical offset. * @return Message whose physical offset is as specified. */ @@ -121,6 +130,7 @@ public interface MessageStore { /** * Get one message from the specified commit log offset. + * * @param commitLogOffset commit log offset. * @return wrapped result of the message. */ @@ -128,6 +138,7 @@ public interface MessageStore { /** * Get one message from the specified commit log offset. + * * @param commitLogOffset commit log offset. * @param msgSize message size. * @return wrapped result of the message. @@ -136,30 +147,35 @@ public interface MessageStore { /** * Get the running information of this store. + * * @return message store running info. */ String getRunningDataInfo(); /** * Message store runtime information, which should generally contains various statistical information. + * * @return runtime information of the message store in format of key-value pairs. */ HashMap getRuntimeInfo(); /** * Get the maximum commit log offset. + * * @return maximum commit log offset. */ long getMaxPhyOffset(); /** * Get the minimum commit log offset. + * * @return minimum commit log offset. */ long getMinPhyOffset(); /** * Get the store time of the earliest message in the given queue. + * * @param topic Topic of the messages to query. * @param queueId Queue ID to find. * @return store time of the earliest message. @@ -168,12 +184,14 @@ public interface MessageStore { /** * Get the store time of the earliest message in this store. + * * @return timestamp of the earliest message in this store. */ long getEarliestMessageTime(); /** * Get the store time of the message specified. + * * @param topic message topic. * @param queueId queue ID. * @param consumeQueueOffset consume queue offset. @@ -183,6 +201,7 @@ public interface MessageStore { /** * Get the total number of the messages in the specified queue. + * * @param topic Topic * @param queueId Queue ID. * @return total number. @@ -191,6 +210,7 @@ public interface MessageStore { /** * Get the raw commit log data starting from the given offset, which should used for replication purpose. + * * @param offset starting offset. * @return commit log data. */ @@ -198,6 +218,7 @@ public interface MessageStore { /** * Append data to commit log. + * * @param startOffset starting offset. * @param data data to append. * @return true if success; false otherwise. @@ -211,36 +232,40 @@ public interface MessageStore { /** * Query messages by given key. + * * @param topic topic of the message. * @param key message key. * @param maxNum maximum number of the messages possible. * @param begin begin timestamp. * @param end end timestamp. - * @return */ QueryMessageResult queryMessage(final String topic, final String key, final int maxNum, final long begin, final long end); /** * Update HA master address. + * * @param newAddr new address. */ void updateHaMasterAddress(final String newAddr); /** * Return how much the slave falls behind. + * * @return number of bytes that slave falls behind. */ long slaveFallBehindMuch(); /** * Return the current timestamp of the store. + * * @return current time in milliseconds since 1970-01-01. */ long now(); /** * Clean unused topics. + * * @param topics all valid topics. * @return number of the topics deleted. */ @@ -253,6 +278,7 @@ public interface MessageStore { /** * Check if the given message has been swapped out of the memory. + * * @param topic topic. * @param queueId queue ID. * @param consumeOffset consume queue offset. @@ -262,18 +288,21 @@ public interface MessageStore { /** * Get number of the bytes that have been stored in commit log and not yet dispatched to consume queue. + * * @return number of the bytes to dispatch. */ long dispatchBehindBytes(); /** * Flush the message store to persist all data. + * * @return maximum offset flushed to persistent storage device. */ long flush(); /** * Reset written offset. + * * @param phyOffset new offset. * @return true if success; false otherwise. */ @@ -281,42 +310,49 @@ public interface MessageStore { /** * Get confirm offset. + * * @return confirm offset. */ long getConfirmOffset(); /** * Set confirm offset. + * * @param phyOffset confirm offset to set. */ void setConfirmOffset(long phyOffset); /** * Check if the operation system page cache is busy or not. + * * @return true if the OS page cache is busy; false otherwise. */ boolean isOSPageCacheBusy(); /** * Get lock time in milliseconds of the store by far. + * * @return lock time in milliseconds. */ long lockTimeMills(); /** * Check if the transient store pool is deficient. + * * @return true if the transient store pool is running out; false otherwise. */ boolean isTransientStorePoolDeficient(); /** * Get the dispatcher list. + * * @return list of the dispatcher. */ LinkedList getDispatcherList(); /** * Get consume queue of the topic/queue. + * * @param topic Topic. * @param queueId Queue ID. * @return Consume queue. diff --git a/store/src/main/java/org/apache/rocketmq/store/PutMessageLock.java b/store/src/main/java/org/apache/rocketmq/store/PutMessageLock.java index a03e41adf7291f60de527709d3d59a7385c0c655..758f4378832173b744d1b18110b31501dfe6093c 100644 --- a/store/src/main/java/org/apache/rocketmq/store/PutMessageLock.java +++ b/store/src/main/java/org/apache/rocketmq/store/PutMessageLock.java @@ -21,5 +21,6 @@ package org.apache.rocketmq.store; */ public interface PutMessageLock { void lock(); + void unlock(); } diff --git a/store/src/main/java/org/apache/rocketmq/store/PutMessageReentrantLock.java b/store/src/main/java/org/apache/rocketmq/store/PutMessageReentrantLock.java index 9198f1c6f51703224d7fa8e36a14d7a98ad3df5c..9aa80d867217ba3183e82c7382b6f1e0b66e6ce2 100644 --- a/store/src/main/java/org/apache/rocketmq/store/PutMessageReentrantLock.java +++ b/store/src/main/java/org/apache/rocketmq/store/PutMessageReentrantLock.java @@ -16,7 +16,6 @@ */ package org.apache.rocketmq.store; - import java.util.concurrent.locks.ReentrantLock; /** diff --git a/store/src/main/java/org/apache/rocketmq/store/PutMessageSpinLock.java b/store/src/main/java/org/apache/rocketmq/store/PutMessageSpinLock.java index baa809db9e03926dda207bcad02970d0960faed2..39a32cc444c8843161f4bcbdfd6c29d723fc4c93 100644 --- a/store/src/main/java/org/apache/rocketmq/store/PutMessageSpinLock.java +++ b/store/src/main/java/org/apache/rocketmq/store/PutMessageSpinLock.java @@ -16,12 +16,10 @@ */ package org.apache.rocketmq.store; - import java.util.concurrent.atomic.AtomicBoolean; /** * Spin lock Implementation to put message, suggest using this witb low race conditions - * */ public class PutMessageSpinLock implements PutMessageLock { //true: Can lock, false : in lock. diff --git a/store/src/main/java/org/apache/rocketmq/store/RunningFlags.java b/store/src/main/java/org/apache/rocketmq/store/RunningFlags.java index 3dcd8611ab4af86af4b2190fdb9761ac44dc5e9a..7ff11a282a3ad1f61ce0e135d4427c24c27c369d 100644 --- a/store/src/main/java/org/apache/rocketmq/store/RunningFlags.java +++ b/store/src/main/java/org/apache/rocketmq/store/RunningFlags.java @@ -28,7 +28,6 @@ public class RunningFlags { private static final int DISK_FULL_BIT = 1 << 4; - private volatile int flagBits = 0; public RunningFlags() { diff --git a/store/src/main/java/org/apache/rocketmq/store/config/MessageStoreConfig.java b/store/src/main/java/org/apache/rocketmq/store/config/MessageStoreConfig.java index 19ed2113dfaef48da58fb04b9b2a40fc58648d06..02aa84a3e6b590b43901e529b810b4812144ff72 100644 --- a/store/src/main/java/org/apache/rocketmq/store/config/MessageStoreConfig.java +++ b/store/src/main/java/org/apache/rocketmq/store/config/MessageStoreConfig.java @@ -143,7 +143,6 @@ public class MessageStoreConfig { private int transientStorePoolSize = 5; private boolean fastFailIfNoBufferInStorePool = false; - public boolean isDebugLockEnable() { return debugLockEnable; } @@ -605,7 +604,8 @@ public class MessageStoreConfig { } /** - * Enable transient commitLog store poll only if transientStorePoolEnable is true and the FlushDiskType is ASYNC_FLUSH + * Enable transient commitLog store poll only if transientStorePoolEnable is true and the FlushDiskType is + * ASYNC_FLUSH * * @return true or false */ diff --git a/store/src/main/java/org/apache/rocketmq/store/ha/HAConnection.java b/store/src/main/java/org/apache/rocketmq/store/ha/HAConnection.java index 3967b643133ca3a0b005785e9524b8db4bbd9243..8b9750464f12790dcd01ddf75f0c786648df190a 100644 --- a/store/src/main/java/org/apache/rocketmq/store/ha/HAConnection.java +++ b/store/src/main/java/org/apache/rocketmq/store/ha/HAConnection.java @@ -78,10 +78,6 @@ public class HAConnection { return socketChannel; } - /** - - * - */ class ReadSocketService extends ServiceThread { private static final int READ_MAX_BUFFER_SIZE = 1024 * 1024; private final Selector selector; @@ -194,10 +190,6 @@ public class HAConnection { } } - /** - - * - */ class WriteSocketService extends ServiceThread { private final Selector selector; private final SocketChannel socketChannel; @@ -333,9 +325,6 @@ public class HAConnection { HAConnection.log.info(this.getServiceName() + " service end"); } - /** - - */ private boolean transferData() throws Exception { int writeSizeZeroTimes = 0; // Write Header diff --git a/store/src/main/java/org/apache/rocketmq/store/ha/HAService.java b/store/src/main/java/org/apache/rocketmq/store/ha/HAService.java index f507b368f07b4dd913b9f9ec857bf76f60085b10..51a8a27035a3d233663b75b9499daf94fa58ba3e 100644 --- a/store/src/main/java/org/apache/rocketmq/store/ha/HAService.java +++ b/store/src/main/java/org/apache/rocketmq/store/ha/HAService.java @@ -85,9 +85,6 @@ public class HAService { return result; } - /** - - */ public void notifyTransferSome(final long offset) { for (long value = this.push2SlaveMaxOffset.get(); offset > value; ) { boolean ok = this.push2SlaveMaxOffset.compareAndSet(value, offset); @@ -182,7 +179,9 @@ public class HAService { this.serverSocketChannel.register(this.selector, SelectionKey.OP_ACCEPT); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override public void shutdown(final boolean interrupt) { super.shutdown(interrupt); @@ -194,7 +193,9 @@ public class HAService { } } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override public void run() { log.info(this.getServiceName() + " service started"); @@ -237,7 +238,9 @@ public class HAService { log.info(this.getServiceName() + " service end"); } - /** {@inheritDoc} */ + /** + * {@inheritDoc} + */ @Override public String getServiceName() { return AcceptSocketService.class.getSimpleName(); @@ -374,17 +377,6 @@ public class HAService { return !this.reportOffset.hasRemaining(); } - // private void reallocateByteBuffer() { - // ByteBuffer bb = ByteBuffer.allocate(READ_MAX_BUFFER_SIZE); - // int remain = this.byteBufferRead.limit() - this.dispatchPostion; - // bb.put(this.byteBufferRead.array(), this.dispatchPostion, remain); - // this.dispatchPostion = 0; - // this.byteBufferRead = bb; - // } - - /** - - */ private void reallocateByteBuffer() { int remain = READ_MAX_BUFFER_SIZE - this.dispatchPostion; if (remain > 0) { @@ -426,7 +418,6 @@ public class HAService { break; } } else { - // TODO ERROR log.info("HAClient, processReadEvent read socket < 0"); return false; } @@ -598,8 +589,6 @@ public class HAService { log.info(this.getServiceName() + " service end"); } - - // // private void disableWriteFlag() { // if (this.socketChannel != null) { // SelectionKey sk = this.socketChannel.keyFor(this.selector); @@ -610,8 +599,6 @@ public class HAService { // } // } // } - // - // // private void enableWriteFlag() { // if (this.socketChannel != null) { // SelectionKey sk = this.socketChannel.keyFor(this.selector); diff --git a/store/src/main/java/org/apache/rocketmq/store/index/IndexFile.java b/store/src/main/java/org/apache/rocketmq/store/index/IndexFile.java index 54f573270872084f189f6e6e9c55725622b6e3bc..edc24764e751c3f9429f20dd91cd64e83f9247e8 100644 --- a/store/src/main/java/org/apache/rocketmq/store/index/IndexFile.java +++ b/store/src/main/java/org/apache/rocketmq/store/index/IndexFile.java @@ -208,9 +208,8 @@ public class IndexFile { if (slotValue <= invalidIndex || slotValue > this.indexHeader.getIndexCount() || this.indexHeader.getIndexCount() <= 1) { - // TODO NOTFOUND } else { - for (int nextIndexToRead = slotValue;;) { + for (int nextIndexToRead = slotValue; ; ) { if (phyOffsets.size() >= maxNum) { break; } diff --git a/store/src/main/java/org/apache/rocketmq/store/index/IndexHeader.java b/store/src/main/java/org/apache/rocketmq/store/index/IndexHeader.java index 5102a216a41f51abbd8ef8a9989f0c7d8b9c40fd..44021cd58958c3fdcd6a7bcac7a775dd4d147221 100644 --- a/store/src/main/java/org/apache/rocketmq/store/index/IndexHeader.java +++ b/store/src/main/java/org/apache/rocketmq/store/index/IndexHeader.java @@ -20,11 +20,6 @@ import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; -/** - - * - * - */ public class IndexHeader { public static final int INDEX_HEADER_SIZE = 40; private static int beginTimestampIndex = 0; diff --git a/store/src/main/java/org/apache/rocketmq/store/index/IndexService.java b/store/src/main/java/org/apache/rocketmq/store/index/IndexService.java index c434df58e797085072cacbd22748f98e704b2b49..b565349e12f647033b95d47ca71df88c5fd4544f 100644 --- a/store/src/main/java/org/apache/rocketmq/store/index/IndexService.java +++ b/store/src/main/java/org/apache/rocketmq/store/index/IndexService.java @@ -35,7 +35,9 @@ import org.slf4j.LoggerFactory; public class IndexService { private static final Logger log = LoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME); - /** Maximum times to attempt index file creation. */ + /** + * Maximum times to attempt index file creation. + */ private static final int MAX_TRY_IDX_CREATE = 3; private final DefaultMessageStore defaultMessageStore; private final int hashSlotNum; @@ -140,7 +142,7 @@ public class IndexService { public void destroy() { try { - this.readWriteLock.readLock().lock(); + this.readWriteLock.writeLock().lock(); for (IndexFile f : this.indexFileList) { f.destroy(1000 * 3); } @@ -148,7 +150,7 @@ public class IndexService { } catch (Exception e) { log.error("destroy exception", e); } finally { - this.readWriteLock.readLock().unlock(); + this.readWriteLock.writeLock().unlock(); } } diff --git a/store/src/main/java/org/apache/rocketmq/store/schedule/ScheduleMessageService.java b/store/src/main/java/org/apache/rocketmq/store/schedule/ScheduleMessageService.java index 25640a467e4442d46f9999de75a026311a8ff497..35b8e8565ea15b02794e5d23345c1bd99e8c0128 100644 --- a/store/src/main/java/org/apache/rocketmq/store/schedule/ScheduleMessageService.java +++ b/store/src/main/java/org/apache/rocketmq/store/schedule/ScheduleMessageService.java @@ -336,10 +336,7 @@ public class ScheduleMessageService extends ConfigManager { } } // end of if (bufferCQ != null) else { - /* - - */ long cqMinOffset = cq.getMinOffsetInQueue(); if (offset < cqMinOffset) { failScheduleOffset = cqMinOffset; diff --git a/store/src/main/java/org/apache/rocketmq/store/stats/BrokerStats.java b/store/src/main/java/org/apache/rocketmq/store/stats/BrokerStats.java index 5555b8b6ba236e3a79803c2c9c1b06c49f52ae46..a3240a4695a63daa753fd3182ac86f10ba708adc 100644 --- a/store/src/main/java/org/apache/rocketmq/store/stats/BrokerStats.java +++ b/store/src/main/java/org/apache/rocketmq/store/stats/BrokerStats.java @@ -38,9 +38,6 @@ public class BrokerStats { this.defaultMessageStore = defaultMessageStore; } - /** - - */ public void record() { this.msgPutTotalYesterdayMorning = this.msgPutTotalTodayMorning; this.msgGetTotalYesterdayMorning = this.msgGetTotalTodayMorning; diff --git a/store/src/main/java/org/apache/rocketmq/store/stats/BrokerStatsManager.java b/store/src/main/java/org/apache/rocketmq/store/stats/BrokerStatsManager.java index 1515eb477131900e26ff622985675a96ce3b05c9..64f76cabacd3a8c24ae751fae35f527f4c1ebc4f 100644 --- a/store/src/main/java/org/apache/rocketmq/store/stats/BrokerStatsManager.java +++ b/store/src/main/java/org/apache/rocketmq/store/stats/BrokerStatsManager.java @@ -123,9 +123,11 @@ public class BrokerStatsManager { public void incTopicPutNums(final String topic) { this.statsTable.get(TOPIC_PUT_NUMS).addValue(topic, 1, 1); } + public void incTopicPutNums(final String topic, int num, int times) { this.statsTable.get(TOPIC_PUT_NUMS).addValue(topic, num, times); } + public void incTopicPutSize(final String topic, final int size) { this.statsTable.get(TOPIC_PUT_SIZE).addValue(topic, size, 1); } @@ -156,9 +158,11 @@ public class BrokerStatsManager { public void incBrokerPutNums() { this.statsTable.get(BROKER_PUT_NUMS).getAndCreateStatsItem(this.clusterName).getValue().incrementAndGet(); } + public void incBrokerPutNums(final int incValue) { this.statsTable.get(BROKER_PUT_NUMS).getAndCreateStatsItem(this.clusterName).getValue().addAndGet(incValue); } + public void incBrokerGetNums(final int incValue) { this.statsTable.get(BROKER_GET_NUMS).getAndCreateStatsItem(this.clusterName).getValue().addAndGet(incValue); } @@ -173,12 +177,14 @@ public class BrokerStatsManager { return this.statsTable.get(GROUP_GET_NUMS).getStatsDataInMinute(statsKey).getTps(); } - public void recordDiskFallBehindTime(final String group, final String topic, final int queueId, final long fallBehind) { + public void recordDiskFallBehindTime(final String group, final String topic, final int queueId, + final long fallBehind) { final String statsKey = String.format("%d@%s@%s", queueId, topic, group); this.momentStatsItemSetFallTime.getAndCreateStatsItem(statsKey).getValue().set(fallBehind); } - public void recordDiskFallBehindSize(final String group, final String topic, final int queueId, final long fallBehind) { + public void recordDiskFallBehindSize(final String group, final String topic, final int queueId, + final long fallBehind) { final String statsKey = String.format("%d@%s@%s", queueId, topic, group); this.momentStatsItemSetFallSize.getAndCreateStatsItem(statsKey).getValue().set(fallBehind); } diff --git a/store/src/test/java/org/apache/rocketmq/store/AppendCallbackTest.java b/store/src/test/java/org/apache/rocketmq/store/AppendCallbackTest.java index fc667b6318bf4923a7ff02c612deb763a5e04cdd..7f88d36e9a7283cc494b5d83055b6cc954671c0d 100644 --- a/store/src/test/java/org/apache/rocketmq/store/AppendCallbackTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/AppendCallbackTest.java @@ -6,18 +6,17 @@ * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.rocketmq.store; - import java.io.File; import java.net.InetSocketAddress; import java.nio.ByteBuffer; @@ -25,18 +24,20 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; + +import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.common.message.MessageDecoder; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.message.MessageExtBatch; import org.apache.rocketmq.store.config.MessageStoreConfig; +import org.junit.After; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; - public class AppendCallbackTest { AppendMessageCallback callback; @@ -44,7 +45,7 @@ public class AppendCallbackTest { CommitLog.MessageExtBatchEncoder batchEncoder = new CommitLog.MessageExtBatchEncoder(10 * 1024 * 1024); @Before - public void init() throws Exception{ + public void init() throws Exception { MessageStoreConfig messageStoreConfig = new MessageStoreConfig(); messageStoreConfig.setMapedFileSizeCommitLog(1024 * 8); messageStoreConfig.setMapedFileSizeConsumeQueue(1024 * 4); @@ -58,12 +59,16 @@ public class AppendCallbackTest { callback = commitLog.new DefaultAppendMessageCallback(1024); } + @After + public void destroy() { + UtilAll.deleteFile(new File(System.getProperty("user.home") + File.separator + "unitteststore")); + } @Test - public void testAppendMessageBatchEndOfFile() throws Exception{ - List messages = new ArrayList<>(); + public void testAppendMessageBatchEndOfFile() throws Exception { + List messages = new ArrayList<>(); String topic = "test-topic"; - int queue= 0; + int queue = 0; for (int i = 0; i < 10; i++) { Message msg = new Message(); msg.setBody("body".getBytes()); @@ -75,8 +80,8 @@ public class AppendCallbackTest { messageExtBatch.setTopic(topic); messageExtBatch.setQueueId(queue); messageExtBatch.setBornTimestamp(System.currentTimeMillis()); - messageExtBatch.setBornHost(new InetSocketAddress("127.0.0.1",123)); - messageExtBatch.setStoreHost(new InetSocketAddress("127.0.0.1",124)); + messageExtBatch.setBornHost(new InetSocketAddress("127.0.0.1", 123)); + messageExtBatch.setStoreHost(new InetSocketAddress("127.0.0.1", 124)); messageExtBatch.setBody(MessageDecoder.encodeMessages(messages)); messageExtBatch.setEncodedBuff(batchEncoder.encode(messageExtBatch)); @@ -91,11 +96,12 @@ public class AppendCallbackTest { assertTrue(result.getMsgId().length() > 0); //should have already constructed some message ids } + @Test public void testAppendMessageBatchSucc() throws Exception { - List messages = new ArrayList<>(); + List messages = new ArrayList<>(); String topic = "test-topic"; - int queue= 0; + int queue = 0; for (int i = 0; i < 10; i++) { Message msg = new Message(); msg.setBody("body".getBytes()); @@ -107,8 +113,8 @@ public class AppendCallbackTest { messageExtBatch.setTopic(topic); messageExtBatch.setQueueId(queue); messageExtBatch.setBornTimestamp(System.currentTimeMillis()); - messageExtBatch.setBornHost(new InetSocketAddress("127.0.0.1",123)); - messageExtBatch.setStoreHost(new InetSocketAddress("127.0.0.1",124)); + messageExtBatch.setBornHost(new InetSocketAddress("127.0.0.1", 123)); + messageExtBatch.setStoreHost(new InetSocketAddress("127.0.0.1", 124)); messageExtBatch.setBody(MessageDecoder.encodeMessages(messages)); messageExtBatch.setEncodedBuff(batchEncoder.encode(messageExtBatch)); @@ -123,7 +129,7 @@ public class AppendCallbackTest { assertEquals(messages.size(), allresult.getMsgNum()); Set msgIds = new HashSet<>(); - for (String msgId: allresult.getMsgId().split(",")) { + for (String msgId : allresult.getMsgId().split(",")) { assertEquals(32, msgId.length()); msgIds.add(msgId); } diff --git a/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueExtTest.java b/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueExtTest.java index 5dbc5848adb13928e0900515c89bd12aee009dbe..e213a025c84ecfe27c0977a547f2635d6f17f85a 100644 --- a/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueExtTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueExtTest.java @@ -17,6 +17,8 @@ package org.apache.rocketmq.store; +import org.apache.rocketmq.common.UtilAll; +import org.junit.After; import org.junit.Test; import java.io.File; @@ -34,7 +36,6 @@ public class ConsumeQueueExtTest { private static final int cqExtFileSize = 10 * unitSizeWithBitMap; private static final int unitCount = 20; - protected ConsumeQueueExt genExt() { return new ConsumeQueueExt( topic, queueId, storePath, cqExtFileSize, bitMapLength @@ -62,24 +63,8 @@ public class ConsumeQueueExtTest { return cqExtUnit; } - protected void deleteDirectory(String rootPath) { - File file = new File(rootPath); - deleteFile(file); - } - - protected void deleteFile(File file) { - File[] subFiles = file.listFiles(); - if (subFiles != null) { - for (File sub : subFiles) { - deleteFile(sub); - } - } - - file.delete(); - } - protected void putSth(ConsumeQueueExt consumeQueueExt, boolean getAfterPut, - boolean unitSameSize, int unitCount) { + boolean unitSameSize, int unitCount) { for (int i = 0; i < unitCount; i++) { ConsumeQueueExt.CqExtUnit putUnit = unitSameSize ? genUnit(true) : genUnit(i % 2 == 0); @@ -111,7 +96,7 @@ public class ConsumeQueueExtTest { putSth(consumeQueueExt, true, false, unitCount); } finally { consumeQueueExt.destroy(); - deleteDirectory(storePath); + UtilAll.deleteFile(new File(storePath)); } } @@ -139,7 +124,7 @@ public class ConsumeQueueExtTest { } } finally { consumeQueueExt.destroy(); - deleteDirectory(storePath); + UtilAll.deleteFile(new File(storePath)); } } @@ -161,7 +146,7 @@ public class ConsumeQueueExtTest { assertThat(unit).isNull(); } finally { consumeQueueExt.destroy(); - deleteDirectory(storePath); + UtilAll.deleteFile(new File(storePath)); } } @@ -199,7 +184,7 @@ public class ConsumeQueueExtTest { } finally { putCqExt.destroy(); loadCqExt.destroy(); - deleteDirectory(storePath); + UtilAll.deleteFile(new File(storePath)); } } @@ -222,7 +207,7 @@ public class ConsumeQueueExtTest { assertThat(expectMinAddress).isEqualTo(minAddress); } finally { consumeQueueExt.destroy(); - deleteDirectory(storePath); + UtilAll.deleteFile(new File(storePath)); } } @@ -245,7 +230,12 @@ public class ConsumeQueueExtTest { assertThat(expectMaxAddress).isEqualTo(maxAddress); } finally { consumeQueueExt.destroy(); - deleteDirectory(storePath); + UtilAll.deleteFile(new File(storePath)); } } + + @After + public void destroy() { + UtilAll.deleteFile(new File(storePath)); + } } diff --git a/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueTest.java b/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueTest.java index 9c42fb91d24a112a871c26a2104e8b1781f26e79..b03f2fce7a0d2dd5aacc35d1bcbb3430c718bfd2 100644 --- a/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/ConsumeQueueTest.java @@ -18,6 +18,7 @@ package org.apache.rocketmq.store; import org.apache.rocketmq.common.BrokerConfig; +import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.message.MessageDecoder; import org.apache.rocketmq.store.config.MessageStoreConfig; import org.apache.rocketmq.store.stats.BrokerStatsManager; @@ -82,9 +83,8 @@ public class ConsumeQueueTest { return msg; } - public MessageStoreConfig buildStoreConfig(int commitLogFileSize, int cqFileSize, - boolean enableCqExt, int cqExtFileSize) { + boolean enableCqExt, int cqExtFileSize) { MessageStoreConfig messageStoreConfig = new MessageStoreConfig(); messageStoreConfig.setMapedFileSizeCommitLog(commitLogFileSize); messageStoreConfig.setMapedFileSizeConsumeQueue(cqFileSize); @@ -111,7 +111,7 @@ public class ConsumeQueueTest { new MessageArrivingListener() { @Override public void arriving(String topic, int queueId, long logicOffset, long tagsCode, - long msgStoreTime, byte[] filterBitMap, Map properties) { + long msgStoreTime, byte[] filterBitMap, Map properties) { } } , brokerConfig); @@ -131,22 +131,6 @@ public class ConsumeQueueTest { } } - protected void deleteDirectory(String rootPath) { - File file = new File(rootPath); - deleteFile(file); - } - - protected void deleteFile(File file) { - File[] subFiles = file.listFiles(); - if (subFiles != null) { - for (File sub : subFiles) { - deleteFile(sub); - } - } - - file.delete(); - } - @Test public void testConsumeQueueWithExtendData() { DefaultMessageStore master = null; @@ -220,7 +204,7 @@ public class ConsumeQueueTest { } finally { master.shutdown(); master.destroy(); - deleteDirectory(storePath); + UtilAll.deleteFile(new File(storePath)); } } } diff --git a/store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java b/store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java index 75f1de94128c0f6b329a86d9e08621f4e89088f5..6e37b705f7435003edae4eeac3654566f7a6cacc 100644 --- a/store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/DefaultMessageStoreTest.java @@ -17,14 +17,19 @@ package org.apache.rocketmq.store; +import java.io.File; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; + import org.apache.rocketmq.common.BrokerConfig; +import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.store.config.FlushDiskType; import org.apache.rocketmq.store.config.MessageStoreConfig; +import org.junit.After; +import org.apache.rocketmq.store.stats.BrokerStatsManager; import org.junit.Before; import org.junit.Test; @@ -38,11 +43,37 @@ public class DefaultMessageStoreTest { private SocketAddress BornHost; private SocketAddress StoreHost; private byte[] MessageBody; + private MessageStore messageStore; @Before public void init() throws Exception { StoreHost = new InetSocketAddress(InetAddress.getLocalHost(), 8123); BornHost = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0); + + messageStore = buildMessageStore(); + boolean load = messageStore.load(); + assertTrue(load); + messageStore.start(); + } + + @After + public void destory() { + messageStore.shutdown(); + messageStore.destroy(); + + MessageStoreConfig messageStoreConfig = new MessageStoreConfig(); + File file = new File(messageStoreConfig.getStorePathRootDir()); + UtilAll.deleteFile(file); + } + + public MessageStore buildMessageStore() throws Exception { + MessageStoreConfig messageStoreConfig = new MessageStoreConfig(); + messageStoreConfig.setMapedFileSizeCommitLog(1024 * 1024 * 10); + messageStoreConfig.setMapedFileSizeConsumeQueue(1024 * 1024 * 10); + messageStoreConfig.setMaxHashSlotNum(10000); + messageStoreConfig.setMaxIndexNum(100 * 100); + messageStoreConfig.setFlushDiskType(FlushDiskType.SYNC_FLUSH); + return new DefaultMessageStore(messageStoreConfig, new BrokerStatsManager("simpleTest"), new MyMessageArrivingListener(), new BrokerConfig()); } @Test @@ -50,32 +81,16 @@ public class DefaultMessageStoreTest { long totalMsgs = 100; QUEUE_TOTAL = 1; MessageBody = StoreMessage.getBytes(); + for (long i = 0; i < totalMsgs; i++) { + messageStore.putMessage(buildMessage()); + } - MessageStoreConfig messageStoreConfig = new MessageStoreConfig(); - messageStoreConfig.setMapedFileSizeCommitLog(1024 * 8); - messageStoreConfig.setMapedFileSizeConsumeQueue(1024 * 4); - messageStoreConfig.setMaxHashSlotNum(100); - messageStoreConfig.setMaxIndexNum(100 * 10); - MessageStore master = new DefaultMessageStore(messageStoreConfig, null, new MyMessageArrivingListener(), new BrokerConfig()); - - boolean load = master.load(); - assertTrue(load); - - master.start(); - try { - for (long i = 0; i < totalMsgs; i++) { - master.putMessage(buildMessage()); - } - - for (long i = 0; i < totalMsgs; i++) { - GetMessageResult result = master.getMessage("GROUP_A", "TOPIC_A", 0, i, 1024 * 1024, null); - assertThat(result).isNotNull(); - result.release(); - } - } finally { - master.shutdown(); - master.destroy(); + for (long i = 0; i < totalMsgs; i++) { + GetMessageResult result = messageStore.getMessage("GROUP_A", "TOPIC_A", 0, i, 1024 * 1024, null); + assertThat(result).isNotNull(); + result.release(); } + verifyThatMasterIsFunctional(totalMsgs, messageStore); } public MessageExtBrokerInner buildMessage() { @@ -86,7 +101,7 @@ public class DefaultMessageStoreTest { msg.setBody(MessageBody); msg.setKeys(String.valueOf(System.currentTimeMillis())); msg.setQueueId(Math.abs(QueueId.getAndIncrement()) % QUEUE_TOTAL); - msg.setSysFlag(4); + msg.setSysFlag(0); msg.setBornTimestamp(System.currentTimeMillis()); msg.setStoreHost(StoreHost); msg.setBornHost(BornHost); @@ -95,38 +110,61 @@ public class DefaultMessageStoreTest { @Test public void testGroupCommit() throws Exception { - long totalMsgs = 100; + long totalMsgs = 10; QUEUE_TOTAL = 1; MessageBody = StoreMessage.getBytes(); - MessageStoreConfig messageStoreConfig = new MessageStoreConfig(); - messageStoreConfig.setMapedFileSizeCommitLog(1024 * 8); - messageStoreConfig.setFlushDiskType(FlushDiskType.SYNC_FLUSH); - MessageStore master = new DefaultMessageStore(messageStoreConfig, null, new MyMessageArrivingListener(), new BrokerConfig()); - boolean load = master.load(); - assertTrue(load); + for (long i = 0; i < totalMsgs; i++) { + messageStore.putMessage(buildMessage()); + } + + for (long i = 0; i < totalMsgs; i++) { + GetMessageResult result = messageStore.getMessage("GROUP_A", "TOPIC_A", 0, i, 1024 * 1024, null); + assertThat(result).isNotNull(); + result.release(); + } + verifyThatMasterIsFunctional(totalMsgs, messageStore); + } + + private void verifyThatMasterIsFunctional(long totalMsgs, MessageStore master) { + for (long i = 0; i < totalMsgs; i++) { + master.putMessage(buildMessage()); + } + + for (long i = 0; i < totalMsgs; i++) { + GetMessageResult result = master.getMessage("GROUP_A", "TOPIC_A", 0, i, 1024 * 1024, null); + assertThat(result).isNotNull(); + result.release(); + + } + } - master.start(); - try { - for (long i = 0; i < totalMsgs; i++) { - master.putMessage(buildMessage()); - } - - for (long i = 0; i < totalMsgs; i++) { - GetMessageResult result = master.getMessage("GROUP_A", "TOPIC_A", 0, i, 1024 * 1024, null); - assertThat(result).isNotNull(); - result.release(); - - } - } finally { - master.shutdown(); - master.destroy(); + @Test + public void testPullSize() throws Exception { + String topic = "pullSizeTopic"; + + for (int i = 0; i < 32; i++) { + MessageExtBrokerInner messageExtBrokerInner = buildMessage(); + messageExtBrokerInner.setTopic(topic); + messageExtBrokerInner.setQueueId(0); + messageStore.putMessage(messageExtBrokerInner); } + //wait for consume queue build + Thread.sleep(10); + String group = "simple"; + GetMessageResult getMessageResult32 = messageStore.getMessage(group, topic, 0, 0, 32, null); + assertThat(getMessageResult32.getMessageBufferList().size()).isEqualTo(32); + + GetMessageResult getMessageResult20 = messageStore.getMessage(group, topic, 0, 0, 20, null); + assertThat(getMessageResult20.getMessageBufferList().size()).isEqualTo(20); + + GetMessageResult getMessageResult45 = messageStore.getMessage(group, topic, 0, 0, 10, null); + assertThat(getMessageResult45.getMessageBufferList().size()).isEqualTo(10); } private class MyMessageArrivingListener implements MessageArrivingListener { @Override public void arriving(String topic, int queueId, long logicOffset, long tagsCode, long msgStoreTime, - byte[] filterBitMap, Map properties) { + byte[] filterBitMap, Map properties) { } } } diff --git a/store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java b/store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java index f1f9c1fb1b001c45bab9f8b19f783eb07fd85b50..203dfcd565f4d5491c648f0219c99eff925f3330 100644 --- a/store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/MappedFileQueueTest.java @@ -17,8 +17,13 @@ package org.apache.rocketmq.store; +import java.io.File; import java.nio.ByteBuffer; import java.util.Arrays; + +import org.apache.rocketmq.common.UtilAll; +import org.apache.rocketmq.store.config.MessageStoreConfig; +import org.junit.After; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -176,4 +181,10 @@ public class MappedFileQueueTest { mappedFileQueue.shutdown(1000); mappedFileQueue.destroy(); } + + @After + public void destory() { + File file = new File("target/unit_test_store"); + UtilAll.deleteFile(file); + } } diff --git a/store/src/test/java/org/apache/rocketmq/store/MappedFileTest.java b/store/src/test/java/org/apache/rocketmq/store/MappedFileTest.java index d2736acd077b2316a8beb530062ebb2c6f92ea16..50d0ae47f03a0a729f1baf9ac1206fa3db9a172d 100644 --- a/store/src/test/java/org/apache/rocketmq/store/MappedFileTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/MappedFileTest.java @@ -20,7 +20,11 @@ */ package org.apache.rocketmq.store; +import java.io.File; import java.io.IOException; + +import org.apache.rocketmq.common.UtilAll; +import org.junit.After; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -47,4 +51,10 @@ public class MappedFileTest { assertThat(mappedFile.isCleanupOver()).isTrue(); assertThat(mappedFile.destroy(1000)).isTrue(); } + + @After + public void destory() { + File file = new File("target/unit_test_store"); + UtilAll.deleteFile(file); + } } diff --git a/store/src/test/java/org/apache/rocketmq/store/StoreCheckpointTest.java b/store/src/test/java/org/apache/rocketmq/store/StoreCheckpointTest.java index 1af63d4f27515bf52ce0b811847ac7a3898be24b..3c0d9253afa9862540aa5c0e71f99b2063e51e78 100644 --- a/store/src/test/java/org/apache/rocketmq/store/StoreCheckpointTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/StoreCheckpointTest.java @@ -20,7 +20,11 @@ */ package org.apache.rocketmq.store; +import java.io.File; import java.io.IOException; + +import org.apache.rocketmq.common.UtilAll; +import org.junit.After; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -42,4 +46,10 @@ public class StoreCheckpointTest { assertThat(storeCheckpoint.getPhysicMsgTimestamp()).isEqualTo(physicMsgTimestamp); assertThat(storeCheckpoint.getLogicsMsgTimestamp()).isEqualTo(logicsMsgTimestamp); } + + @After + public void destory() { + File file = new File("target/checkpoint_test"); + UtilAll.deleteFile(file); + } } diff --git a/store/src/test/java/org/apache/rocketmq/store/index/IndexFileTest.java b/store/src/test/java/org/apache/rocketmq/store/index/IndexFileTest.java index f172e65a53827b2411300bc759ff892670024db8..7ad5b38db1d8ddb571bd2a934bfb542992c5ba91 100644 --- a/store/src/test/java/org/apache/rocketmq/store/index/IndexFileTest.java +++ b/store/src/test/java/org/apache/rocketmq/store/index/IndexFileTest.java @@ -20,8 +20,11 @@ */ package org.apache.rocketmq.store.index; +import java.io.File; import java.util.ArrayList; import java.util.List; + +import org.apache.rocketmq.common.UtilAll; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -42,6 +45,8 @@ public class IndexFileTest { boolean putResult = indexFile.putKey(Long.toString(400), 400, System.currentTimeMillis()); assertThat(putResult).isFalse(); indexFile.destroy(0); + File file = new File("100"); + UtilAll.deleteFile(file); } @Test @@ -62,5 +67,7 @@ public class IndexFileTest { assertThat(phyOffsets).isNotEmpty(); assertThat(phyOffsets.size()).isEqualTo(1); indexFile.destroy(0); + File file = new File("200"); + UtilAll.deleteFile(file); } } diff --git a/style/rmq_checkstyle.xml b/style/rmq_checkstyle.xml index 6ec2ad08fdde9efd531eba31768e20b2fb6c2d53..e93b353aaa18a00cbebd37784b52beb036fecc97 100644 --- a/style/rmq_checkstyle.xml +++ b/style/rmq_checkstyle.xml @@ -126,8 +126,8 @@ - - + + diff --git a/test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQSqlConsumer.java b/test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQSqlConsumer.java index cb0210f44ec51fb68f71e0571efae3899130f30d..3c03ee714e68c83c89642385254e6553b0f1b097 100644 --- a/test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQSqlConsumer.java +++ b/test/src/main/java/org/apache/rocketmq/test/client/rmq/RMQSqlConsumer.java @@ -24,6 +24,7 @@ import org.apache.rocketmq.test.listener.AbstractListener; public class RMQSqlConsumer extends RMQNormalConsumer { private static Logger logger = Logger.getLogger(RMQSqlConsumer.class); private MessageSelector selector; + public RMQSqlConsumer(String nsAddr, String topic, MessageSelector selector, String consumerGroup, AbstractListener listener) { super(nsAddr, topic, "*", consumerGroup, listener); diff --git a/test/src/test/java/org/apache/rocketmq/test/base/BaseConf.java b/test/src/test/java/org/apache/rocketmq/test/base/BaseConf.java index 92f77b8533d34e0a3015455fc21c6b1d34f15a25..8516779e4363149ac5d206113c553297978f60d4 100644 --- a/test/src/test/java/org/apache/rocketmq/test/base/BaseConf.java +++ b/test/src/test/java/org/apache/rocketmq/test/base/BaseConf.java @@ -41,7 +41,7 @@ public class BaseConf { protected static String clusterName; protected static int brokerNum; protected static int waitTime = 5; - protected static int consumeTime = 1 * 60 * 1000; + protected static int consumeTime = 5 * 60 * 1000; protected static NamesrvController namesrvController; protected static BrokerController brokerController1; protected static BrokerController brokerController2; diff --git a/test/src/test/java/org/apache/rocketmq/test/base/IntegrationTestBase.java b/test/src/test/java/org/apache/rocketmq/test/base/IntegrationTestBase.java index 07af7aa6e3d3ac101d0b984f51705ae45dfd912e..e1b8c9102d13490ffa9a223acf5c494c9482fc69 100644 --- a/test/src/test/java/org/apache/rocketmq/test/base/IntegrationTestBase.java +++ b/test/src/test/java/org/apache/rocketmq/test/base/IntegrationTestBase.java @@ -25,6 +25,7 @@ import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; import org.apache.rocketmq.broker.BrokerController; import org.apache.rocketmq.common.BrokerConfig; +import org.apache.rocketmq.common.UtilAll; import org.apache.rocketmq.common.namesrv.NamesrvConfig; import org.apache.rocketmq.namesrv.NamesrvController; import org.apache.rocketmq.remoting.netty.NettyClientConfig; @@ -54,7 +55,8 @@ public class IntegrationTestBase { static { Runtime.getRuntime().addShutdownHook(new Thread() { - @Override public void run() { + @Override + public void run() { try { for (BrokerController brokerController : BROKER_CONTROLLERS) { if (brokerController != null) { @@ -75,9 +77,9 @@ public class IntegrationTestBase { } } for (File file : TMPE_FILES) { - deleteFile(file); + UtilAll.deleteFile(file); } - } catch (Exception e){ + } catch (Exception e) { logger.error("Shutdown error", e); } } @@ -148,12 +150,12 @@ public class IntegrationTestBase { return brokerController; } - public static boolean initTopic(String topic, String nsAddr, String clusterName) { + public static boolean initTopic(String topic, String nsAddr, String clusterName, int queueNumbers) { long startTime = System.currentTimeMillis(); boolean createResult; while (true) { - createResult = MQAdmin.createTopic(nsAddr, clusterName, topic, 8); + createResult = MQAdmin.createTopic(nsAddr, clusterName, topic, queueNumbers); if (createResult) { break; } else if (System.currentTimeMillis() - startTime > topicCreateTime) { @@ -169,6 +171,10 @@ public class IntegrationTestBase { return createResult; } + public static boolean initTopic(String topic, String nsAddr, String clusterName) { + return initTopic(topic, nsAddr, clusterName, 8); + } + public static void deleteFile(File file) { if (!file.exists()) { return; diff --git a/test/src/test/java/org/apache/rocketmq/test/client/consumer/broadcast/order/OrderMsgBroadCastIT.java b/test/src/test/java/org/apache/rocketmq/test/client/consumer/broadcast/order/OrderMsgBroadCastIT.java index 2c9abc067fca1a4f323cec5f7ab5b78d0e1ae049..9d8aeb3313ec20eb71a2a6b556318673134f79dd 100644 --- a/test/src/test/java/org/apache/rocketmq/test/client/consumer/broadcast/order/OrderMsgBroadCastIT.java +++ b/test/src/test/java/org/apache/rocketmq/test/client/consumer/broadcast/order/OrderMsgBroadCastIT.java @@ -38,6 +38,8 @@ public class OrderMsgBroadCastIT extends BaseBroadCastIT { private RMQNormalProducer producer = null; private String topic = null; + private int broadcastConsumeTime = 1 * 60 * 1000; + @Before public void setUp() { topic = initTopic(); @@ -63,9 +65,8 @@ public class OrderMsgBroadCastIT extends BaseBroadCastIT { List mqs = producer.getMessageQueue(); MessageQueueMsg mqMsgs = new MessageQueueMsg(mqs, msgSize); producer.send(mqMsgs.getMsgsWithMQ()); - - consumer1.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime); - consumer2.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime); + consumer1.getListener().waitForMessageConsume(producer.getAllMsgBody(), broadcastConsumeTime); + consumer2.getListener().waitForMessageConsume(producer.getAllMsgBody(), broadcastConsumeTime); assertThat(VerifyUtils.verifyOrder(((RMQOrderListener) consumer1.getListener()).getMsgs())) .isEqualTo(true); diff --git a/test/src/test/java/org/apache/rocketmq/test/client/consumer/filter/SqlFilterIT.java b/test/src/test/java/org/apache/rocketmq/test/client/consumer/filter/SqlFilterIT.java index 115595d28d95d3349e50ab12eb144b253d32b328..15d91a1423ce14cb6fe6c48a7b406c09e1ceb3a3 100644 --- a/test/src/test/java/org/apache/rocketmq/test/client/consumer/filter/SqlFilterIT.java +++ b/test/src/test/java/org/apache/rocketmq/test/client/consumer/filter/SqlFilterIT.java @@ -67,7 +67,7 @@ public class SqlFilterIT extends BaseConf { consumer.getListener().waitForMessageConsume(msgSize * 2, consumeTime); assertThat(producer.getAllMsgBody()) .containsAllIn(VerifyUtils.getFilterdMessage(producer.getAllMsgBody(), - consumer.getListener().getAllMsgBody())); + consumer.getListener().getAllMsgBody())); assertThat(consumer.getListener().getAllMsgBody().size()).isEqualTo(msgSize * 2); } diff --git a/test/src/test/java/org/apache/rocketmq/test/client/producer/batch/BatchSendIT.java b/test/src/test/java/org/apache/rocketmq/test/client/producer/batch/BatchSendIT.java index e372a1b2601b05a14b15ef9a6c903e009a632a31..6fb34af6d614b9f4decf9fdc3b954cc0f90673ca 100644 --- a/test/src/test/java/org/apache/rocketmq/test/client/producer/batch/BatchSendIT.java +++ b/test/src/test/java/org/apache/rocketmq/test/client/producer/batch/BatchSendIT.java @@ -77,7 +77,6 @@ public class BatchSendIT extends BaseConf { } } - @Test public void testBatchSend_CheckProperties() throws Exception { List messageList = new ArrayList<>(); @@ -91,7 +90,6 @@ public class BatchSendIT extends BaseConf { message.setBody("body".getBytes()); messageList.add(message); - DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr); SendResult sendResult = producer.send(messageList); Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus()); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java index 409ea3322f213573edd79c731a2fdfa371ad5569..eb45de22f3e0427a560b4141b09acff77d79f6a9 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java @@ -119,12 +119,14 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { } @Override - public MessageExt viewMessage(String offsetMsgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + public MessageExt viewMessage( + String offsetMsgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { return defaultMQAdminExtImpl.viewMessage(offsetMsgId); } @Override - public QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end) throws MQClientException, + public QueryResult queryMessage(String topic, String key, int maxNum, long begin, + long end) throws MQClientException, InterruptedException { return defaultMQAdminExtImpl.queryMessage(topic, key, maxNum, begin, end); } @@ -140,7 +142,8 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { } @Override - public void updateBrokerConfig(String brokerAddr, Properties properties) throws RemotingConnectException, RemotingSendRequestException, + public void updateBrokerConfig(String brokerAddr, + Properties properties) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, UnsupportedEncodingException, InterruptedException, MQBrokerException { defaultMQAdminExtImpl.updateBrokerConfig(brokerAddr, properties); } @@ -158,7 +161,8 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { } @Override - public void createAndUpdateSubscriptionGroupConfig(String addr, SubscriptionGroupConfig config) throws RemotingException, + public void createAndUpdateSubscriptionGroupConfig(String addr, + SubscriptionGroupConfig config) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { defaultMQAdminExtImpl.createAndUpdateSubscriptionGroupConfig(addr, config); } @@ -174,7 +178,8 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { } @Override - public TopicStatsTable examineTopicStats(String topic) throws RemotingException, MQClientException, InterruptedException, + public TopicStatsTable examineTopicStats( + String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { return defaultMQAdminExtImpl.examineTopicStats(topic); } @@ -185,24 +190,28 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { } @Override - public TopicList fetchTopicsByCLuster(String clusterName) throws RemotingException, MQClientException, InterruptedException { + public TopicList fetchTopicsByCLuster( + String clusterName) throws RemotingException, MQClientException, InterruptedException { return this.defaultMQAdminExtImpl.fetchTopicsByCLuster(clusterName); } @Override - public KVTable fetchBrokerRuntimeStats(final String brokerAddr) throws RemotingConnectException, RemotingSendRequestException, + public KVTable fetchBrokerRuntimeStats( + final String brokerAddr) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { return this.defaultMQAdminExtImpl.fetchBrokerRuntimeStats(brokerAddr); } @Override - public ConsumeStats examineConsumeStats(String consumerGroup) throws RemotingException, MQClientException, InterruptedException, + public ConsumeStats examineConsumeStats( + String consumerGroup) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { return examineConsumeStats(consumerGroup, null); } @Override - public ConsumeStats examineConsumeStats(String consumerGroup, String topic) throws RemotingException, MQClientException, + public ConsumeStats examineConsumeStats(String consumerGroup, + String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { return defaultMQAdminExtImpl.examineConsumeStats(consumerGroup, topic); } @@ -214,18 +223,21 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { } @Override - public TopicRouteData examineTopicRouteInfo(String topic) throws RemotingException, MQClientException, InterruptedException { + public TopicRouteData examineTopicRouteInfo( + String topic) throws RemotingException, MQClientException, InterruptedException { return defaultMQAdminExtImpl.examineTopicRouteInfo(topic); } @Override - public ConsumerConnection examineConsumerConnectionInfo(String consumerGroup) throws InterruptedException, MQBrokerException, + public ConsumerConnection examineConsumerConnectionInfo( + String consumerGroup) throws InterruptedException, MQBrokerException, RemotingException, MQClientException { return defaultMQAdminExtImpl.examineConsumerConnectionInfo(consumerGroup); } @Override - public ProducerConnection examineProducerConnectionInfo(String producerGroup, final String topic) throws RemotingException, + public ProducerConnection examineProducerConnectionInfo(String producerGroup, + final String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { return defaultMQAdminExtImpl.examineProducerConnectionInfo(producerGroup, topic); } @@ -247,46 +259,54 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { } @Override - public String getKVConfig(String namespace, String key) throws RemotingException, MQClientException, InterruptedException { + public String getKVConfig(String namespace, + String key) throws RemotingException, MQClientException, InterruptedException { return defaultMQAdminExtImpl.getKVConfig(namespace, key); } @Override - public KVTable getKVListByNamespace(String namespace) throws RemotingException, MQClientException, InterruptedException { + public KVTable getKVListByNamespace( + String namespace) throws RemotingException, MQClientException, InterruptedException { return defaultMQAdminExtImpl.getKVListByNamespace(namespace); } @Override - public void deleteTopicInBroker(Set addrs, String topic) throws RemotingException, MQBrokerException, InterruptedException, + public void deleteTopicInBroker(Set addrs, + String topic) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { defaultMQAdminExtImpl.deleteTopicInBroker(addrs, topic); } @Override - public void deleteTopicInNameServer(Set addrs, String topic) throws RemotingException, MQBrokerException, InterruptedException, + public void deleteTopicInNameServer(Set addrs, + String topic) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { defaultMQAdminExtImpl.deleteTopicInNameServer(addrs, topic); } @Override - public void deleteSubscriptionGroup(String addr, String groupName) throws RemotingException, MQBrokerException, InterruptedException, + public void deleteSubscriptionGroup(String addr, + String groupName) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { defaultMQAdminExtImpl.deleteSubscriptionGroup(addr, groupName); } @Override - public void createAndUpdateKvConfig(String namespace, String key, String value) throws RemotingException, MQBrokerException, + public void createAndUpdateKvConfig(String namespace, String key, + String value) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { defaultMQAdminExtImpl.createAndUpdateKvConfig(namespace, key, value); } @Override - public void deleteKvConfig(String namespace, String key) throws RemotingException, MQBrokerException, InterruptedException, + public void deleteKvConfig(String namespace, + String key) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { defaultMQAdminExtImpl.deleteKvConfig(namespace, key); } - public List resetOffsetByTimestampOld(String consumerGroup, String topic, long timestamp, boolean force) + public List resetOffsetByTimestampOld(String consumerGroup, String topic, long timestamp, + boolean force) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { return defaultMQAdminExtImpl.resetOffsetByTimestampOld(consumerGroup, topic, timestamp, force); } @@ -297,49 +317,57 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { return resetOffsetByTimestamp(topic, group, timestamp, isForce, false); } - public Map resetOffsetByTimestamp(String topic, String group, long timestamp, boolean isForce, boolean isC) + public Map resetOffsetByTimestamp(String topic, String group, long timestamp, boolean isForce, + boolean isC) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { return defaultMQAdminExtImpl.resetOffsetByTimestamp(topic, group, timestamp, isForce, isC); } @Override - public void resetOffsetNew(String consumerGroup, String topic, long timestamp) throws RemotingException, MQBrokerException, + public void resetOffsetNew(String consumerGroup, String topic, + long timestamp) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { this.defaultMQAdminExtImpl.resetOffsetNew(consumerGroup, topic, timestamp); } @Override - public Map> getConsumeStatus(String topic, String group, String clientAddr) throws RemotingException, + public Map> getConsumeStatus(String topic, String group, + String clientAddr) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { return defaultMQAdminExtImpl.getConsumeStatus(topic, group, clientAddr); } @Override - public void createOrUpdateOrderConf(String key, String value, boolean isCluster) throws RemotingException, MQBrokerException, + public void createOrUpdateOrderConf(String key, String value, + boolean isCluster) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { defaultMQAdminExtImpl.createOrUpdateOrderConf(key, value, isCluster); } @Override - public GroupList queryTopicConsumeByWho(String topic) throws InterruptedException, MQBrokerException, RemotingException, + public GroupList queryTopicConsumeByWho( + String topic) throws InterruptedException, MQBrokerException, RemotingException, MQClientException { return this.defaultMQAdminExtImpl.queryTopicConsumeByWho(topic); } @Override - public List queryConsumeTimeSpan(final String topic, final String group) throws InterruptedException, MQBrokerException, + public List queryConsumeTimeSpan(final String topic, + final String group) throws InterruptedException, MQBrokerException, RemotingException, MQClientException { return this.defaultMQAdminExtImpl.queryConsumeTimeSpan(topic, group); } @Override - public boolean cleanExpiredConsumerQueue(String cluster) throws RemotingConnectException, RemotingSendRequestException, + public boolean cleanExpiredConsumerQueue( + String cluster) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { return defaultMQAdminExtImpl.cleanExpiredConsumerQueue(cluster); } @Override - public boolean cleanExpiredConsumerQueueByAddr(String addr) throws RemotingConnectException, RemotingSendRequestException, + public boolean cleanExpiredConsumerQueueByAddr( + String addr) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { return defaultMQAdminExtImpl.cleanExpiredConsumerQueueByAddr(addr); } @@ -357,7 +385,8 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { } @Override - public ConsumerRunningInfo getConsumerRunningInfo(String consumerGroup, String clientId, boolean jstack) throws RemotingException, + public ConsumerRunningInfo getConsumerRunningInfo(String consumerGroup, String clientId, + boolean jstack) throws RemotingException, MQClientException, InterruptedException { return defaultMQAdminExtImpl.getConsumerRunningInfo(consumerGroup, clientId, jstack); } @@ -369,25 +398,29 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { } @Override - public ConsumeMessageDirectlyResult consumeMessageDirectly(final String consumerGroup, final String clientId, final String topic, + public ConsumeMessageDirectlyResult consumeMessageDirectly(final String consumerGroup, final String clientId, + final String topic, final String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { return defaultMQAdminExtImpl.consumeMessageDirectly(consumerGroup, clientId, topic, msgId); } @Override - public List messageTrackDetail(MessageExt msg) throws RemotingException, MQClientException, InterruptedException, + public List messageTrackDetail( + MessageExt msg) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { return this.defaultMQAdminExtImpl.messageTrackDetail(msg); } @Override - public void cloneGroupOffset(String srcGroup, String destGroup, String topic, boolean isOffline) throws RemotingException, + public void cloneGroupOffset(String srcGroup, String destGroup, String topic, + boolean isOffline) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { this.defaultMQAdminExtImpl.cloneGroupOffset(srcGroup, destGroup, topic, isOffline); } @Override - public BrokerStatsData viewBrokerStatsData(String brokerAddr, String statsName, String statsKey) throws RemotingConnectException, + public BrokerStatsData viewBrokerStatsData(String brokerAddr, String statsName, + String statsKey) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { return this.defaultMQAdminExtImpl.viewBrokerStatsData(brokerAddr, statsName, statsKey); } @@ -406,7 +439,8 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { } @Override - public Set getTopicClusterList(final String topic) throws InterruptedException, MQBrokerException, MQClientException, RemotingException { + public Set getTopicClusterList( + final String topic) throws InterruptedException, MQBrokerException, MQClientException, RemotingException { return this.defaultMQAdminExtImpl.getTopicClusterList(topic); } @@ -472,7 +506,8 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { } @Override - public QueryConsumeQueueResponseBody queryConsumeQueue(String brokerAddr, String topic, int queueId, long index, int count, String consumerGroup) + public QueryConsumeQueueResponseBody queryConsumeQueue(String brokerAddr, String topic, int queueId, long index, + int count, String consumerGroup) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQClientException { return this.defaultMQAdminExtImpl.queryConsumeQueue( brokerAddr, topic, queueId, index, count, consumerGroup diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java index 157ae21eba3b49342215e2e79b5bb9ec319d9343..c93c40067a1f7d3798359a67a680decef5021d62 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExtImpl.java @@ -119,7 +119,7 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { if (!registerOK) { this.serviceState = ServiceState.CREATE_JUST; throw new MQClientException("The adminExt group[" + this.defaultMQAdminExt.getAdminExtGroup() - + "] has created already, specifed another name please."// + + "] has created already, specifed another name please." + FAQUrl.suggestTodo(FAQUrl.GROUP_NAME_DUPLICATE_URL), null); } @@ -132,8 +132,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { case RUNNING: case START_FAILED: case SHUTDOWN_ALREADY: - throw new MQClientException("The AdminExt service state not OK, maybe started once, "// - + this.serviceState// + throw new MQClientException("The AdminExt service state not OK, maybe started once, " + + this.serviceState + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK), null); default: break; @@ -160,7 +160,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public void updateBrokerConfig(String brokerAddr, Properties properties) throws RemotingConnectException, RemotingSendRequestException, + public void updateBrokerConfig(String brokerAddr, + Properties properties) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, UnsupportedEncodingException, InterruptedException, MQBrokerException { this.mqClientInstance.getMQClientAPIImpl().updateBrokerConfig(brokerAddr, properties, timeoutMillis); } @@ -178,25 +179,25 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public void createAndUpdateSubscriptionGroupConfig(String addr, SubscriptionGroupConfig config) throws RemotingException, + public void createAndUpdateSubscriptionGroupConfig(String addr, + SubscriptionGroupConfig config) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { this.mqClientInstance.getMQClientAPIImpl().createSubscriptionGroup(addr, config, timeoutMillis); } @Override public SubscriptionGroupConfig examineSubscriptionGroupConfig(String addr, String group) { - // TODO Auto-generated method stub return null; } @Override public TopicConfig examineTopicConfig(String addr, String topic) { - // TODO Auto-generated method stub return null; } @Override - public TopicStatsTable examineTopicStats(String topic) throws RemotingException, MQClientException, InterruptedException, + public TopicStatsTable examineTopicStats( + String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic); TopicStatsTable topicStatsTable = new TopicStatsTable(); @@ -222,24 +223,28 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public TopicList fetchTopicsByCLuster(String clusterName) throws RemotingException, MQClientException, InterruptedException { + public TopicList fetchTopicsByCLuster( + String clusterName) throws RemotingException, MQClientException, InterruptedException { return this.mqClientInstance.getMQClientAPIImpl().getTopicsByCluster(clusterName, timeoutMillis); } @Override - public KVTable fetchBrokerRuntimeStats(final String brokerAddr) throws RemotingConnectException, RemotingSendRequestException, + public KVTable fetchBrokerRuntimeStats( + final String brokerAddr) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException { return this.mqClientInstance.getMQClientAPIImpl().getBrokerRuntimeInfo(brokerAddr, timeoutMillis); } @Override - public ConsumeStats examineConsumeStats(String consumerGroup) throws RemotingException, MQClientException, InterruptedException, + public ConsumeStats examineConsumeStats( + String consumerGroup) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { return examineConsumeStats(consumerGroup, null); } @Override - public ConsumeStats examineConsumeStats(String consumerGroup, String topic) throws RemotingException, MQClientException, + public ConsumeStats examineConsumeStats(String consumerGroup, + String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { String retryTopic = MixAll.getRetryTopic(consumerGroup); TopicRouteData topicRouteData = this.examineTopicRouteInfo(retryTopic); @@ -271,12 +276,14 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public TopicRouteData examineTopicRouteInfo(String topic) throws RemotingException, MQClientException, InterruptedException { + public TopicRouteData examineTopicRouteInfo( + String topic) throws RemotingException, MQClientException, InterruptedException { return this.mqClientInstance.getMQClientAPIImpl().getTopicRouteInfoFromNameServer(topic, timeoutMillis); } @Override - public MessageExt viewMessage(String topic, String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + public MessageExt viewMessage(String topic, + String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { try { MessageDecoder.decodeMessageId(msgId); return this.viewMessage(msgId); @@ -287,7 +294,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public ConsumerConnection examineConsumerConnectionInfo(String consumerGroup) throws InterruptedException, MQBrokerException, + public ConsumerConnection examineConsumerConnectionInfo( + String consumerGroup) throws InterruptedException, MQBrokerException, RemotingException, MQClientException { ConsumerConnection result = new ConsumerConnection(); String topic = MixAll.getRetryTopic(consumerGroup); @@ -310,7 +318,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public ProducerConnection examineProducerConnectionInfo(String producerGroup, final String topic) throws RemotingException, + public ProducerConnection examineProducerConnectionInfo(String producerGroup, + final String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { ProducerConnection result = new ProducerConnection(); List brokers = this.examineTopicRouteInfo(topic).getBrokerDatas(); @@ -344,22 +353,23 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { @Override public void putKVConfig(String namespace, String key, String value) { - // TODO Auto-generated method stub - } @Override - public String getKVConfig(String namespace, String key) throws RemotingException, MQClientException, InterruptedException { + public String getKVConfig(String namespace, + String key) throws RemotingException, MQClientException, InterruptedException { return this.mqClientInstance.getMQClientAPIImpl().getKVConfigValue(namespace, key, timeoutMillis); } @Override - public KVTable getKVListByNamespace(String namespace) throws RemotingException, MQClientException, InterruptedException { + public KVTable getKVListByNamespace( + String namespace) throws RemotingException, MQClientException, InterruptedException { return this.mqClientInstance.getMQClientAPIImpl().getKVListByNamespace(namespace, timeoutMillis); } @Override - public void deleteTopicInBroker(Set addrs, String topic) throws RemotingException, MQBrokerException, InterruptedException, + public void deleteTopicInBroker(Set addrs, + String topic) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { for (String addr : addrs) { this.mqClientInstance.getMQClientAPIImpl().deleteTopicInBroker(addr, topic, timeoutMillis); @@ -367,7 +377,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public void deleteTopicInNameServer(Set addrs, String topic) throws RemotingException, MQBrokerException, InterruptedException, + public void deleteTopicInNameServer(Set addrs, + String topic) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { if (addrs == null) { String ns = this.mqClientInstance.getMQClientAPIImpl().fetchNameServerAddr(); @@ -379,25 +390,29 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public void deleteSubscriptionGroup(String addr, String groupName) throws RemotingException, MQBrokerException, InterruptedException, + public void deleteSubscriptionGroup(String addr, + String groupName) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { this.mqClientInstance.getMQClientAPIImpl().deleteSubscriptionGroup(addr, groupName, timeoutMillis); } @Override - public void createAndUpdateKvConfig(String namespace, String key, String value) throws RemotingException, MQBrokerException, + public void createAndUpdateKvConfig(String namespace, String key, + String value) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { this.mqClientInstance.getMQClientAPIImpl().putKVConfigValue(namespace, key, value, timeoutMillis); } @Override - public void deleteKvConfig(String namespace, String key) throws RemotingException, MQBrokerException, InterruptedException, + public void deleteKvConfig(String namespace, + String key) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { this.mqClientInstance.getMQClientAPIImpl().deleteKVConfigValue(namespace, key, timeoutMillis); } @Override - public List resetOffsetByTimestampOld(String consumerGroup, String topic, long timestamp, boolean force) + public List resetOffsetByTimestampOld(String consumerGroup, String topic, long timestamp, + boolean force) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic); List rollbackStatsList = new ArrayList(); @@ -448,7 +463,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public void resetOffsetNew(String consumerGroup, String topic, long timestamp) throws RemotingException, MQBrokerException, + public void resetOffsetNew(String consumerGroup, String topic, + long timestamp) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { try { this.resetOffsetByTimestamp(topic, consumerGroup, timestamp, true); @@ -461,7 +477,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } } - public Map resetOffsetByTimestamp(String topic, String group, long timestamp, boolean isForce, boolean isC) + public Map resetOffsetByTimestamp(String topic, String group, long timestamp, boolean isForce, + boolean isC) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic); List brokerDatas = topicRouteData.getBrokerDatas(); @@ -482,7 +499,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { return allOffsetTable; } - private RollbackStats resetOffsetConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue queue, OffsetWrapper offsetWrapper, + private RollbackStats resetOffsetConsumeOffset(String brokerAddr, String consumeGroup, MessageQueue queue, + OffsetWrapper offsetWrapper, long timestamp, boolean force) throws RemotingException, InterruptedException, MQBrokerException { long resetOffset; if (timestamp == -1) { @@ -515,7 +533,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public Map> getConsumeStatus(String topic, String group, String clientAddr) throws RemotingException, + public Map> getConsumeStatus(String topic, String group, + String clientAddr) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic); List brokerDatas = topicRouteData.getBrokerDatas(); @@ -529,7 +548,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { return Collections.EMPTY_MAP; } - public void createOrUpdateOrderConf(String key, String value, boolean isCluster) throws RemotingException, MQBrokerException, + public void createOrUpdateOrderConf(String key, String value, + boolean isCluster) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { if (isCluster) { @@ -568,7 +588,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public GroupList queryTopicConsumeByWho(String topic) throws InterruptedException, MQBrokerException, RemotingException, + public GroupList queryTopicConsumeByWho( + String topic) throws InterruptedException, MQBrokerException, RemotingException, MQClientException { TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic); @@ -585,7 +606,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public List queryConsumeTimeSpan(final String topic, final String group) throws InterruptedException, MQBrokerException, + public List queryConsumeTimeSpan(final String topic, + final String group) throws InterruptedException, MQBrokerException, RemotingException, MQClientException { List spanSet = new ArrayList(); TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic); @@ -599,7 +621,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public boolean cleanExpiredConsumerQueue(String cluster) throws RemotingConnectException, RemotingSendRequestException, + public boolean cleanExpiredConsumerQueue( + String cluster) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { boolean result = false; try { @@ -618,7 +641,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { return result; } - public boolean cleanExpiredConsumerQueueByCluster(ClusterInfo clusterInfo, String cluster) throws RemotingConnectException, + public boolean cleanExpiredConsumerQueueByCluster(ClusterInfo clusterInfo, + String cluster) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { boolean result = false; String[] addrs = clusterInfo.retrieveAllAddrByCluster(cluster); @@ -629,7 +653,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public boolean cleanExpiredConsumerQueueByAddr(String addr) throws RemotingConnectException, RemotingSendRequestException, + public boolean cleanExpiredConsumerQueueByAddr( + String addr) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { boolean result = mqClientInstance.getMQClientAPIImpl().cleanExpiredConsumeQueue(addr, timeoutMillis); log.warn("clean expired ConsumeQueue on target " + addr + " broker " + result); @@ -675,7 +700,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public ConsumerRunningInfo getConsumerRunningInfo(String consumerGroup, String clientId, boolean jstack) throws RemotingException, + public ConsumerRunningInfo getConsumerRunningInfo(String consumerGroup, String clientId, + boolean jstack) throws RemotingException, MQClientException, InterruptedException { String topic = MixAll.RETRY_GROUP_TOPIC_PREFIX + consumerGroup; TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic); @@ -702,7 +728,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public ConsumeMessageDirectlyResult consumeMessageDirectly(final String consumerGroup, final String clientId, final String topic, + public ConsumeMessageDirectlyResult consumeMessageDirectly(final String consumerGroup, final String clientId, + final String topic, final String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { MessageExt msg = this.viewMessage(topic, msgId); if (msg.getProperty(MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX) == null) { @@ -716,7 +743,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public List messageTrackDetail(MessageExt msg) throws RemotingException, MQClientException, InterruptedException, + public List messageTrackDetail( + MessageExt msg) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { List result = new ArrayList(); @@ -798,7 +826,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { return result; } - public boolean consumed(final MessageExt msg, final String group) throws RemotingException, MQClientException, InterruptedException, + public boolean consumed(final MessageExt msg, + final String group) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { ConsumeStats cstats = this.examineConsumeStats(group); @@ -826,7 +855,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public void cloneGroupOffset(String srcGroup, String destGroup, String topic, boolean isOffline) throws RemotingException, + public void cloneGroupOffset(String srcGroup, String destGroup, String topic, + boolean isOffline) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { String retryTopic = MixAll.getRetryTopic(srcGroup); TopicRouteData topicRouteData = this.examineTopicRouteInfo(retryTopic); @@ -840,7 +870,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public BrokerStatsData viewBrokerStatsData(String brokerAddr, String statsName, String statsKey) throws RemotingConnectException, + public BrokerStatsData viewBrokerStatsData(String brokerAddr, String statsName, + String statsKey) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException { return this.mqClientInstance.getMQClientAPIImpl().viewBrokerStatsData(brokerAddr, statsName, statsKey, timeoutMillis); } @@ -859,7 +890,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public Set getTopicClusterList(final String topic) throws InterruptedException, MQBrokerException, MQClientException, + public Set getTopicClusterList( + final String topic) throws InterruptedException, MQBrokerException, MQClientException, RemotingException { Set clusterSet = new HashSet(); ClusterInfo clusterInfo = examineBrokerClusterInfo(); @@ -877,13 +909,15 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr, long timeoutMillis) throws InterruptedException, + public SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr, + long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { return this.mqClientInstance.getMQClientAPIImpl().getAllSubscriptionGroup(brokerAddr, timeoutMillis); } @Override - public TopicConfigSerializeWrapper getAllTopicGroup(final String brokerAddr, long timeoutMillis) throws InterruptedException, + public TopicConfigSerializeWrapper getAllTopicGroup(final String brokerAddr, + long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException { return this.mqClientInstance.getMQClientAPIImpl().getAllTopicConfig(brokerAddr, timeoutMillis); } @@ -919,12 +953,14 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public MessageExt viewMessage(String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { + public MessageExt viewMessage( + String msgId) throws RemotingException, MQBrokerException, InterruptedException, MQClientException { return this.mqClientInstance.getMQAdminImpl().viewMessage(msgId); } @Override - public QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end) throws MQClientException, + public QueryResult queryMessage(String topic, String key, int maxNum, long begin, + long end) throws MQClientException, InterruptedException { return this.mqClientInstance.getMQAdminImpl().queryMessage(topic, key, maxNum, begin, end); } @@ -957,7 +993,8 @@ public class DefaultMQAdminExtImpl implements MQAdminExt, MQAdminExtInner { } @Override - public QueryConsumeQueueResponseBody queryConsumeQueue(String brokerAddr, String topic, int queueId, long index, int count, String consumerGroup) + public QueryConsumeQueueResponseBody queryConsumeQueue(String brokerAddr, String topic, int queueId, long index, + int count, String consumerGroup) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQClientException { return this.mqClientInstance.getMQClientAPIImpl().queryConsumeQueue( brokerAddr, topic, queueId, index, count, consumerGroup, timeoutMillis diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java index 82add92b2d60d721fdd2a4029e4d35a1f16a26be..16b4427575faaa021ba97ea1828ebdab95f7bc8c 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/MQAdminExt.java @@ -64,42 +64,51 @@ public interface MQAdminExt extends MQAdmin { Properties getBrokerConfig(final String brokerAddr) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, UnsupportedEncodingException, InterruptedException, MQBrokerException; - void createAndUpdateTopicConfig(final String addr, final TopicConfig config) throws RemotingException, MQBrokerException, + void createAndUpdateTopicConfig(final String addr, + final TopicConfig config) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; - void createAndUpdateSubscriptionGroupConfig(final String addr, final SubscriptionGroupConfig config) throws RemotingException, + void createAndUpdateSubscriptionGroupConfig(final String addr, + final SubscriptionGroupConfig config) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; SubscriptionGroupConfig examineSubscriptionGroupConfig(final String addr, final String group); TopicConfig examineTopicConfig(final String addr, final String topic); - TopicStatsTable examineTopicStats(final String topic) throws RemotingException, MQClientException, InterruptedException, + TopicStatsTable examineTopicStats( + final String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException; TopicList fetchAllTopicList() throws RemotingException, MQClientException, InterruptedException; - TopicList fetchTopicsByCLuster(String clusterName) throws RemotingException, MQClientException, InterruptedException; + TopicList fetchTopicsByCLuster( + String clusterName) throws RemotingException, MQClientException, InterruptedException; - KVTable fetchBrokerRuntimeStats(final String brokerAddr) throws RemotingConnectException, RemotingSendRequestException, + KVTable fetchBrokerRuntimeStats( + final String brokerAddr) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException; - ConsumeStats examineConsumeStats(final String consumerGroup) throws RemotingException, MQClientException, InterruptedException, + ConsumeStats examineConsumeStats( + final String consumerGroup) throws RemotingException, MQClientException, InterruptedException, MQBrokerException; - ConsumeStats examineConsumeStats(final String consumerGroup, final String topic) throws RemotingException, MQClientException, + ConsumeStats examineConsumeStats(final String consumerGroup, + final String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException; ClusterInfo examineBrokerClusterInfo() throws InterruptedException, MQBrokerException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException; - TopicRouteData examineTopicRouteInfo(final String topic) throws RemotingException, MQClientException, InterruptedException; + TopicRouteData examineTopicRouteInfo( + final String topic) throws RemotingException, MQClientException, InterruptedException; ConsumerConnection examineConsumerConnectionInfo(final String consumerGroup) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException, RemotingException, MQClientException; - ProducerConnection examineProducerConnectionInfo(final String producerGroup, final String topic) throws RemotingException, + ProducerConnection examineProducerConnectionInfo(final String producerGroup, + final String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException; List getNameServerAddressList(); @@ -109,20 +118,24 @@ public interface MQAdminExt extends MQAdmin { void putKVConfig(final String namespace, final String key, final String value); - String getKVConfig(final String namespace, final String key) throws RemotingException, MQClientException, InterruptedException; + String getKVConfig(final String namespace, + final String key) throws RemotingException, MQClientException, InterruptedException; - KVTable getKVListByNamespace(final String namespace) throws RemotingException, MQClientException, InterruptedException; + KVTable getKVListByNamespace( + final String namespace) throws RemotingException, MQClientException, InterruptedException; void deleteTopicInBroker(final Set addrs, final String topic) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; - void deleteTopicInNameServer(final Set addrs, final String topic) throws RemotingException, MQBrokerException, + void deleteTopicInNameServer(final Set addrs, + final String topic) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; void deleteSubscriptionGroup(final String addr, String groupName) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; - void createAndUpdateKvConfig(String namespace, String key, String value) throws RemotingException, MQBrokerException, + void createAndUpdateKvConfig(String namespace, String key, + String value) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; void deleteKvConfig(String namespace, String key) throws RemotingException, MQBrokerException, InterruptedException, @@ -137,16 +150,19 @@ public interface MQAdminExt extends MQAdmin { void resetOffsetNew(String consumerGroup, String topic, long timestamp) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; - Map> getConsumeStatus(String topic, String group, String clientAddr) throws RemotingException, + Map> getConsumeStatus(String topic, String group, + String clientAddr) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; - void createOrUpdateOrderConf(String key, String value, boolean isCluster) throws RemotingException, MQBrokerException, + void createOrUpdateOrderConf(String key, String value, + boolean isCluster) throws RemotingException, MQBrokerException, InterruptedException, MQClientException; GroupList queryTopicConsumeByWho(final String topic) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException, MQBrokerException, RemotingException, MQClientException; - List queryConsumeTimeSpan(final String topic, final String group) throws InterruptedException, MQBrokerException, + List queryConsumeTimeSpan(final String topic, + final String group) throws InterruptedException, MQBrokerException, RemotingException, MQClientException; boolean cleanExpiredConsumerQueue(String cluster) throws RemotingConnectException, RemotingSendRequestException, @@ -173,7 +189,8 @@ public interface MQAdminExt extends MQAdmin { String topic, String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException; - List messageTrackDetail(MessageExt msg) throws RemotingException, MQClientException, InterruptedException, + List messageTrackDetail( + MessageExt msg) throws RemotingException, MQClientException, InterruptedException, MQBrokerException; void cloneGroupOffset(String srcGroup, String destGroup, String topic, boolean isOffline) throws RemotingException, @@ -190,7 +207,8 @@ public interface MQAdminExt extends MQAdmin { long timeoutMillis) throws RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, InterruptedException; - Set getTopicClusterList(final String topic) throws InterruptedException, MQBrokerException, MQClientException, RemotingException; + Set getTopicClusterList( + final String topic) throws InterruptedException, MQBrokerException, MQClientException, RemotingException; SubscriptionGroupWrapper getAllSubscriptionGroup(final String brokerAddr, long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, @@ -209,18 +227,9 @@ public interface MQAdminExt extends MQAdmin { * Command Code : RequestCode.UPDATE_NAMESRV_CONFIG * *
    If param(nameServers) is null or empty, will use name servers from ns! - * - * @param properties - * @param nameServers - * @throws InterruptedException - * @throws RemotingConnectException - * @throws UnsupportedEncodingException - * @throws RemotingSendRequestException - * @throws RemotingTimeoutException - * @throws MQClientException - * @throws MQBrokerException */ - void updateNameServerConfig(final Properties properties, final List nameServers) throws InterruptedException, RemotingConnectException, + void updateNameServerConfig(final Properties properties, + final List nameServers) throws InterruptedException, RemotingConnectException, UnsupportedEncodingException, RemotingSendRequestException, RemotingTimeoutException, MQClientException, MQBrokerException; @@ -230,14 +239,7 @@ public interface MQAdminExt extends MQAdmin { * Command Code : RequestCode.GET_NAMESRV_CONFIG *
    If param(nameServers) is null or empty, will use name servers from ns! * - * @param nameServers * @return The fetched name server config - * @throws InterruptedException - * @throws RemotingTimeoutException - * @throws RemotingSendRequestException - * @throws RemotingConnectException - * @throws MQClientException - * @throws UnsupportedEncodingException */ Map getNameServerConfig(final List nameServers) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, @@ -252,15 +254,9 @@ public interface MQAdminExt extends MQAdmin { * @param index start offset * @param count how many * @param consumerGroup group - * @return - * @throws InterruptedException - * @throws RemotingTimeoutException - * @throws RemotingSendRequestException - * @throws RemotingConnectException - * @throws MQClientException */ QueryConsumeQueueResponseBody queryConsumeQueue(final String brokerAddr, - final String topic, final int queueId, - final long index, final int count, final String consumerGroup) + final String topic, final int queueId, + final long index, final int count, final String consumerGroup) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQClientException; } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/broker/GetBrokerConfigCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/broker/GetBrokerConfigCommand.java index 919f673e29b0ff1e2a07cddd4aa63d1252b5ce1c..11a36048328f4e40ebcfc0decb3092cd19f4238c 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/broker/GetBrokerConfigCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/broker/GetBrokerConfigCommand.java @@ -60,7 +60,8 @@ public class GetBrokerConfigCommand implements SubCommand { } @Override - public void execute(final CommandLine commandLine, final Options options, final RPCHook rpcHook) throws SubCommandException { + public void execute(final CommandLine commandLine, final Options options, + final RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/cluster/ClusterListSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/cluster/ClusterListSubCommand.java index c7b8ac546757af23e62addf338332e72c91ed864..6a0cd71c177b5f2ebffef15d6c0402bbaedca59d 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/cluster/ClusterListSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/cluster/ClusterListSubCommand.java @@ -61,7 +61,8 @@ public class ClusterListSubCommand implements SubCommand { } @Override - public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) throws SubCommandException { + public void execute(final CommandLine commandLine, final Options options, + RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); @@ -164,7 +165,8 @@ public class ClusterListSubCommand implements SubCommand { } } - private void printClusterBaseInfo(final DefaultMQAdminExt defaultMQAdminExt) throws RemotingConnectException, RemotingTimeoutException, + private void printClusterBaseInfo( + final DefaultMQAdminExt defaultMQAdminExt) throws RemotingConnectException, RemotingTimeoutException, RemotingSendRequestException, InterruptedException, MQBrokerException { ClusterInfo clusterInfoSerializeWrapper = defaultMQAdminExt.examineBrokerClusterInfo(); @@ -253,16 +255,16 @@ public class ClusterListSubCommand implements SubCommand { } System.out.printf("%-16s %-22s %-4s %-22s %-16s %19s %19s %10s %5s %6s%n", - clusterName, - brokerName, - next1.getKey(), - next1.getValue(), - version, - String.format("%9.2f(%s,%sms)", in, sendThreadPoolQueueSize, sendThreadPoolQueueHeadWaitTimeMills), - String.format("%9.2f(%s,%sms)", out, pullThreadPoolQueueSize, pullThreadPoolQueueHeadWaitTimeMills), - pageCacheLockTimeMills, - String.format("%2.2f", hour), - String.format("%.4f", space) + clusterName, + brokerName, + next1.getKey(), + next1.getValue(), + version, + String.format("%9.2f(%s,%sms)", in, sendThreadPoolQueueSize, sendThreadPoolQueueHeadWaitTimeMills), + String.format("%9.2f(%s,%sms)", out, pullThreadPoolQueueSize, pullThreadPoolQueueHeadWaitTimeMills), + pageCacheLockTimeMills, + String.format("%2.2f", hour), + String.format("%.4f", space) ); } } diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/UpdateSubGroupSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/UpdateSubGroupSubCommand.java index 910eb1c032c7d7bad16a413c96f1f9bb69f7cb94..7316526be01f4855e11ea9efd749f79628bedb17 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/UpdateSubGroupSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/consumer/UpdateSubGroupSubCommand.java @@ -90,7 +90,8 @@ public class UpdateSubGroupSubCommand implements SubCommand { } @Override - public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) throws SubCommandException { + public void execute(final CommandLine commandLine, final Options options, + RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/DecodeMessageIdCommond.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/DecodeMessageIdCommond.java index 64f634e92d07f3d36bdbc1f3f19204be22c80524..d233b65aa948863dabe9e5054079819a1b1ca162 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/DecodeMessageIdCommond.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/DecodeMessageIdCommond.java @@ -45,7 +45,8 @@ public class DecodeMessageIdCommond implements SubCommand { } @Override - public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) throws SubCommandException { + public void execute(final CommandLine commandLine, final Options options, + RPCHook rpcHook) throws SubCommandException { String messageId = commandLine.getOptionValue('i').trim(); try { diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/PrintMessageByQueueCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/PrintMessageByQueueCommand.java index ac51267161c399d5c03129b88226a586640560c2..46c5f74735265066c96050579db1ec9efbfb10a2 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/PrintMessageByQueueCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/PrintMessageByQueueCommand.java @@ -52,7 +52,8 @@ public class PrintMessageByQueueCommand implements SubCommand { return timestamp; } - private static void calculateByTag(final List msgs, final Map tagCalmap, final boolean calByTag) { + private static void calculateByTag(final List msgs, final Map tagCalmap, + final boolean calByTag) { if (!calByTag) return; @@ -85,7 +86,8 @@ public class PrintMessageByQueueCommand implements SubCommand { } } - public static void printMessage(final List msgs, final String charsetName, boolean printMsg, boolean printBody) { + public static void printMessage(final List msgs, final String charsetName, boolean printMsg, + boolean printBody) { if (!printMsg) return; @@ -162,11 +164,11 @@ public class PrintMessageByQueueCommand implements SubCommand { String charsetName = !commandLine.hasOption('c') ? "UTF-8" : commandLine.getOptionValue('c').trim(); boolean printMsg = - commandLine.hasOption('p') && Boolean.parseBoolean(commandLine.getOptionValue('p').trim()); + commandLine.hasOption('p') && Boolean.parseBoolean(commandLine.getOptionValue('p').trim()); boolean printBody = - commandLine.hasOption('d') && Boolean.parseBoolean(commandLine.getOptionValue('d').trim()); + commandLine.hasOption('d') && Boolean.parseBoolean(commandLine.getOptionValue('d').trim()); boolean calByTag = - commandLine.hasOption('f') && Boolean.parseBoolean(commandLine.getOptionValue('f').trim()); + commandLine.hasOption('f') && Boolean.parseBoolean(commandLine.getOptionValue('f').trim()); String subExpression = !commandLine.hasOption('s') ? "*" : commandLine.getOptionValue('s').trim(); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/PrintMessageSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/PrintMessageSubCommand.java index ac485199c04c39b5e45bbc22e86248cb3f2c59fd..d46d6fb629d610d150a2b1ea9685f9f2897adaa2 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/PrintMessageSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/PrintMessageSubCommand.java @@ -51,7 +51,6 @@ public class PrintMessageSubCommand implements SubCommand { System.out.printf("MSGID: %s %s BODY: %s%n", msg.getMsgId(), msg.toString(), printBody ? new String(msg.getBody(), charsetName) : "NOT PRINT BODY"); } catch (UnsupportedEncodingException e) { - // } } } @@ -108,10 +107,10 @@ public class PrintMessageSubCommand implements SubCommand { try { String topic = commandLine.getOptionValue('t').trim(); - String charsetName = // + String charsetName = !commandLine.hasOption('c') ? "UTF-8" : commandLine.getOptionValue('c').trim(); - String subExpression = // + String subExpression = !commandLine.hasOption('s') ? "*" : commandLine.getOptionValue('s').trim(); boolean printBody = !commandLine.hasOption('d') || Boolean.parseBoolean(commandLine.getOptionValue('d').trim()); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByIdSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByIdSubCommand.java index 05ae003084fea4968a09ceec70636234d052f0f3..39abbc9c4c0bf754412a74e19485b8706e9d6f38 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByIdSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByIdSubCommand.java @@ -262,7 +262,8 @@ public class QueryMsgByIdSubCommand implements SubCommand { } } - private void pushMsg(final DefaultMQAdminExt defaultMQAdminExt, final String consumerGroup, final String clientId, final String msgId) { + private void pushMsg(final DefaultMQAdminExt defaultMQAdminExt, final String consumerGroup, final String clientId, + final String msgId) { try { ConsumeMessageDirectlyResult result = defaultMQAdminExt.consumeMessageDirectly(consumerGroup, clientId, msgId); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommand.java index 5c93ad7985b12f247f4d9aeb7bea2dc2c51dfc20..0103b50b35db83ff6c4c76bf4bd169658a9fa522 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommand.java @@ -39,7 +39,8 @@ import org.apache.rocketmq.tools.command.SubCommandException; public class QueryMsgByUniqueKeySubCommand implements SubCommand { - public static void queryById(final DefaultMQAdminExt admin, final String topic, final String msgId) throws MQClientException, + public static void queryById(final DefaultMQAdminExt admin, final String topic, + final String msgId) throws MQClientException, RemotingException, MQBrokerException, InterruptedException, IOException { MessageExt msg = admin.viewMessage(topic, msgId); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/GetNamesrvConfigCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/GetNamesrvConfigCommand.java index ce63616dce10ad56b8cb3e3b67b79ddc7f3b2b0c..22ce867b227e70f657348905b1989881785a285f 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/GetNamesrvConfigCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/GetNamesrvConfigCommand.java @@ -46,7 +46,8 @@ public class GetNamesrvConfigCommand implements SubCommand { } @Override - public void execute(final CommandLine commandLine, final Options options, final RPCHook rpcHook) throws SubCommandException { + public void execute(final CommandLine commandLine, final Options options, + final RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/UpdateNamesrvConfigCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/UpdateNamesrvConfigCommand.java index 250937027bb4e2ee089b680a539c6ed040b24531..1bb5b380292309fbcf7d4836ddd8db464aa5408e 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/UpdateNamesrvConfigCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/namesrv/UpdateNamesrvConfigCommand.java @@ -53,7 +53,8 @@ public class UpdateNamesrvConfigCommand implements SubCommand { } @Override - public void execute(final CommandLine commandLine, final Options options, final RPCHook rpcHook) throws SubCommandException { + public void execute(final CommandLine commandLine, final Options options, + final RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/queue/QueryConsumeQueueCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/queue/QueryConsumeQueueCommand.java index 611addd54566b344efe4f63d7372d220fe243330..24767cc46f7fe86b5a1820bd039b745acf4a8794 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/queue/QueryConsumeQueueCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/queue/QueryConsumeQueueCommand.java @@ -36,7 +36,7 @@ public class QueryConsumeQueueCommand implements SubCommand { QueryConsumeQueueCommand cmd = new QueryConsumeQueueCommand(); Options options = ServerUtil.buildCommandlineOptions(new Options()); - String[] subargs = new String[]{"-t TopicTest", "-q 0", "-i 6447", "-b 100.81.165.119:10911"}; + String[] subargs = new String[] {"-t TopicTest", "-q 0", "-i 6447", "-b 100.81.165.119:10911"}; final CommandLine commandLine = ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser()); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicClusterSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicClusterSubCommand.java index 7e2c7e3ae94cd0c9d5426bd383e7802d55fe21c5..a658b9829897a0b94154d97a07ee53d6f65e37f8 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicClusterSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicClusterSubCommand.java @@ -46,7 +46,8 @@ public class TopicClusterSubCommand implements SubCommand { } @Override - public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) throws SubCommandException { + public void execute(final CommandLine commandLine, final Options options, + RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); String topic = commandLine.getOptionValue('t').trim(); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicListSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicListSubCommand.java index 70f296ba9b4cd56db39331616bf60e8f63e91892..56aea2e8084460d694740019752dba55d9bdff7d 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicListSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicListSubCommand.java @@ -57,7 +57,8 @@ public class TopicListSubCommand implements SubCommand { } @Override - public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) throws SubCommandException { + public void execute(final CommandLine commandLine, final Options options, + RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicRouteSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicRouteSubCommand.java index d4efd900349cf9d1871a6c2d27d74982ac2e7943..c770db01d427c9e33c17a8a6cc20a76ed6760dfc 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicRouteSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicRouteSubCommand.java @@ -47,7 +47,8 @@ public class TopicRouteSubCommand implements SubCommand { } @Override - public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) throws SubCommandException { + public void execute(final CommandLine commandLine, final Options options, + RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicStatusSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicStatusSubCommand.java index f4ca80e530937891e74ca48c8f431db3883cb846..55440821b0e60b757d65262ba7dcace668ca13c3 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicStatusSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/TopicStatusSubCommand.java @@ -52,7 +52,8 @@ public class TopicStatusSubCommand implements SubCommand { } @Override - public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) throws SubCommandException { + public void execute(final CommandLine commandLine, final Options options, + RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateOrderConfCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateOrderConfCommand.java index de26255d2ada57b0aff05d70b53decda660b9c0b..bebc646b43ecce92bd8a77ca7a74374ea8ce8c3d 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateOrderConfCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateOrderConfCommand.java @@ -57,7 +57,8 @@ public class UpdateOrderConfCommand implements SubCommand { } @Override - public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) throws SubCommandException { + public void execute(final CommandLine commandLine, final Options options, + RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateTopicPermSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateTopicPermSubCommand.java index 764c72f5bf43d76b01801f6ed96d16263614dc81..69420913e46c9b324c2fcb6161570974cf234e1f 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateTopicPermSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateTopicPermSubCommand.java @@ -65,7 +65,8 @@ public class UpdateTopicPermSubCommand implements SubCommand { } @Override - public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) throws SubCommandException { + public void execute(final CommandLine commandLine, final Options options, + RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); try { diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateTopicSubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateTopicSubCommand.java index 4c84cd47e0c0a8fb8332a4423ee51288510320dc..9fdfcb38b244837554aec93579aef2dcb4abb737 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateTopicSubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/topic/UpdateTopicSubCommand.java @@ -83,7 +83,8 @@ public class UpdateTopicSubCommand implements SubCommand { } @Override - public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) throws SubCommandException { + public void execute(final CommandLine commandLine, final Options options, + RPCHook rpcHook) throws SubCommandException { DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook); defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis())); diff --git a/tools/src/test/java/org/apache/rocketmq/tools/command/namesrv/GetNamesrvConfigCommandTest.java b/tools/src/test/java/org/apache/rocketmq/tools/command/namesrv/GetNamesrvConfigCommandTest.java index 8d356fd2dbd119852b74958556413d6ab19b8434..8163fd15bc939c1aa1f7a978df5d59d048ad5b60 100644 --- a/tools/src/test/java/org/apache/rocketmq/tools/command/namesrv/GetNamesrvConfigCommandTest.java +++ b/tools/src/test/java/org/apache/rocketmq/tools/command/namesrv/GetNamesrvConfigCommandTest.java @@ -81,7 +81,7 @@ public class GetNamesrvConfigCommandTest { defaultMQAdminExt.shutdown(); } -// @Ignore + // @Ignore @Test public void testExecute() throws SubCommandException { GetNamesrvConfigCommand cmd = new GetNamesrvConfigCommand();