diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml new file mode 100644 index 0000000000000000000000000000000000000000..b95e6e4bd03a107e96d90627e03c8ab408ff3d9e --- /dev/null +++ b/.github/workflows/greetings.yml @@ -0,0 +1,29 @@ +# +# 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. +# + +name: Little RocketMQ +on: [pull_request_target, issues] +uses: actions/first-interaction@v1.1.0 +with: + # Token for the repository. Can be passed in using {{ secrets.GITHUB_TOKEN }} + repo-token: ${{ secrets.GITHUB_TOKEN }} + # Comment to post on an individual's first issue + issue-message: 'Make sure your issue is not the existence through the issue search. Follow the issue template, make more details for us. But please be aware that Issue should not be used for FAQs: if you have a question or are simply not sure if it is really an issue or not, please contact [us](https://rocketmq.apache.org/about/contact/) first before you create a new issue.' + # Comment to post on an individual's first pull request + pr-message: 'We always welcome new contributions, whether for trivial cleanups, [big new features](https://github.com/apache/rocketmq/wiki/RocketMQ-Improvement-Proposal) or other material rewards, more details see [here](http://rocketmq.apache.org/docs/how-to-contribute/).' diff --git a/acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java b/acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java index 6ec90ee3fad619f36517f1f96b5c40cf020d324b..1c10fae4b94f676ef3e6d81e8f5d94e42fc48ec2 100644 --- a/acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java +++ b/acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java @@ -167,7 +167,7 @@ public class RemoteAddressStrategyFactory { String[] strArray = StringUtils.split(remoteAddr, "."); if (analysis(strArray, 1) || analysis(strArray, 2) || analysis(strArray, 3)) { AclUtils.verify(remoteAddr, index - 1); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int j = 0; j < index; j++) { sb.append(strArray[j].trim()).append("."); } 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 aa6920817f14efeb58a421b4eb33fe33078cadaf..776c991c27ebd0a72c51f792ec6c3306b5920ae3 100644 --- a/common/src/main/java/org/apache/rocketmq/common/UtilAll.java +++ b/common/src/main/java/org/apache/rocketmq/common/UtilAll.java @@ -565,11 +565,11 @@ public class UtilAll { if (list == null || list.size() == 0) { return null; } - StringBuffer str = new StringBuffer(); + StringBuilder str = new StringBuilder(); for (int i = 0; i < list.size(); i++) { str.append(list.get(i)); if (i == list.size() - 1) { - continue; + break; } str.append(splitor); } diff --git a/common/src/main/java/org/apache/rocketmq/common/message/Message.java b/common/src/main/java/org/apache/rocketmq/common/message/Message.java index c9a133b4d0cfd4969b936fac7889b0788bc89edb..48e1f45a7f0f6439725a744ce4c6091393f9e739 100644 --- a/common/src/main/java/org/apache/rocketmq/common/message/Message.java +++ b/common/src/main/java/org/apache/rocketmq/common/message/Message.java @@ -43,11 +43,13 @@ public class Message implements Serializable { this.flag = flag; this.body = body; - if (tags != null && tags.length() > 0) + if (tags != null && tags.length() > 0) { this.setTags(tags); + } - if (keys != null && keys.length() > 0) + if (keys != null && keys.length() > 0) { this.setKeys(keys); + } this.setWaitStoreMsgOK(waitStoreMsgOK); } @@ -127,7 +129,7 @@ public class Message implements Serializable { } public void setKeys(Collection keys) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (String k : keys) { sb.append(k); sb.append(MessageConst.KEY_SEPARATOR); @@ -151,8 +153,9 @@ public class Message implements Serializable { public boolean isWaitStoreMsgOK() { String result = this.getProperty(MessageConst.PROPERTY_WAIT_STORE_MSG_OK); - if (null == result) + if (null == result) { return true; + } return Boolean.parseBoolean(result); } diff --git a/common/src/main/java/org/apache/rocketmq/common/protocol/NamespaceUtil.java b/common/src/main/java/org/apache/rocketmq/common/protocol/NamespaceUtil.java index 704eb90bd7a583029c6c1bb0bbece9d16272902c..60fadaab181ecc012d4ffcf15c00f96328a1d77c 100644 --- a/common/src/main/java/org/apache/rocketmq/common/protocol/NamespaceUtil.java +++ b/common/src/main/java/org/apache/rocketmq/common/protocol/NamespaceUtil.java @@ -120,7 +120,7 @@ public class NamespaceUtil { return null; } - return new StringBuffer() + return new StringBuilder() .append(MixAll.RETRY_GROUP_TOPIC_PREFIX) .append(wrapNamespace(namespace, consumerGroup)) .toString(); diff --git a/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java b/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java index b854099a5bd757a984d402e86d6da06b0119ae12..e1942b40837980432465ed1c6d498d3f606669eb 100644 --- a/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java +++ b/common/src/test/java/org/apache/rocketmq/common/UtilAllTest.java @@ -19,11 +19,15 @@ package org.apache.rocketmq.common; import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.Properties; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; +import static org.junit.Assert.assertEquals; public class UtilAllTest { @@ -109,6 +113,15 @@ public class UtilAllTest { assertThat(UtilAll.ipToIPv6Str(nonInternal.getAddress()).toUpperCase()).isEqualTo("2408:4004:0180:8100:3FAA:1DDE:2B3F:898A"); } + @Test + public void testList2String() { + List list = Arrays.asList("groupA=DENY", "groupB=PUB|SUB", "groupC=SUB"); + String comma = ","; + assertEquals("groupA=DENY,groupB=PUB|SUB,groupC=SUB", UtilAll.list2String(list, comma)); + assertEquals(null, UtilAll.list2String(null, comma)); + assertEquals(null, UtilAll.list2String(Collections.emptyList(), comma)); + } + static class DemoConfig { private int demoWidth = 0; private int demoLength = 0; diff --git a/common/src/test/java/org/apache/rocketmq/common/utils/IOTinyUtilsTest.java b/common/src/test/java/org/apache/rocketmq/common/utils/IOTinyUtilsTest.java index e03e0b9648e88305ea78135f167b3a2e85d49505..6a63eecc2230a5477aec8cc7cd729d01f609a8ea 100644 --- a/common/src/test/java/org/apache/rocketmq/common/utils/IOTinyUtilsTest.java +++ b/common/src/test/java/org/apache/rocketmq/common/utils/IOTinyUtilsTest.java @@ -82,7 +82,7 @@ public class IOTinyUtilsTest { @Test public void testReadLines() throws Exception { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < 10; i++) { sb.append("testReadLines").append("\n"); } @@ -95,7 +95,7 @@ public class IOTinyUtilsTest { @Test public void testToBufferedReader() throws Exception { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < 10; i++) { sb.append("testToBufferedReader").append("\n"); } diff --git a/docs/cn/RocketMQ_Example.md b/docs/cn/RocketMQ_Example.md index d924ce1d7d1f54e8c68ed63ddaa040ad5445f13d..62961d315091ee432a32b66f538db16a921573fa 100644 --- a/docs/cn/RocketMQ_Example.md +++ b/docs/cn/RocketMQ_Example.md @@ -120,13 +120,15 @@ public class AsyncProducer { producer.send(msg, new SendCallback() { @Override public void onSuccess(SendResult sendResult) { + countDownLatch.countDown(); System.out.printf("%-10d OK %s %n", index, sendResult.getMsgId()); } @Override public void onException(Throwable e) { - System.out.printf("%-10d Exception %s %n", index, e); - e.printStackTrace(); + countDownLatch.countDown(); + System.out.printf("%-10d Exception %s %n", index, e); + e.printStackTrace(); } }); } diff --git a/example/src/main/java/org/apache/rocketmq/example/benchmark/Consumer.java b/example/src/main/java/org/apache/rocketmq/example/benchmark/Consumer.java index d3ac36c2046042090bc6bac1f08ce306810bb846..154e6ed4dac017a953fc46c22ce33f2d40e68ec7 100644 --- a/example/src/main/java/org/apache/rocketmq/example/benchmark/Consumer.java +++ b/example/src/main/java/org/apache/rocketmq/example/benchmark/Consumer.java @@ -17,18 +17,11 @@ package org.apache.rocketmq.example.benchmark; -import java.io.IOException; -import java.util.LinkedList; -import java.util.List; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.ThreadLocalRandom; -import java.util.concurrent.atomic.AtomicLong; - import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.PosixParser; +import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.client.consumer.MessageSelector; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; @@ -42,6 +35,16 @@ import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.srvutil.ServerUtil; +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; +import java.util.TimerTask; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; + public class Consumer { public static void main(String[] args) throws MQClientException, IOException { @@ -71,11 +74,12 @@ public class Consumer { final StatsBenchmarkConsumer statsBenchmarkConsumer = new StatsBenchmarkConsumer(); - final Timer timer = new Timer("BenchmarkTimerThread", true); + ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1, + new BasicThreadFactory.Builder().namingPattern("BenchmarkTimerThread-%d").daemon(true).build()); final LinkedList snapshotList = new LinkedList(); - timer.scheduleAtFixedRate(new TimerTask() { + executorService.scheduleAtFixedRate(new TimerTask() { @Override public void run() { snapshotList.addLast(statsBenchmarkConsumer.createSnapshot()); @@ -83,9 +87,9 @@ public class Consumer { snapshotList.removeFirst(); } } - }, 1000, 1000); + }, 1000, 1000, TimeUnit.MILLISECONDS); - timer.scheduleAtFixedRate(new TimerTask() { + executorService.scheduleAtFixedRate(new TimerTask() { private void printStats() { if (snapshotList.size() >= 10) { Long[] begin = snapshotList.getFirst(); @@ -116,7 +120,7 @@ public class Consumer { e.printStackTrace(); } } - }, 10000, 10000); + }, 10000, 10000, TimeUnit.MILLISECONDS); RPCHook rpcHook = aclEnable ? AclClient.getAclRPCHook() : null; DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(group, rpcHook, new AllocateMessageQueueAveragely(), msgTraceEnable, null); 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 32d4b9f7462eb9e3a5ad373295fffc6932970e3a..b198a0fc99808cf0eeac4a81e005e004ec760cad 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 @@ -16,32 +16,34 @@ */ package org.apache.rocketmq.example.benchmark; -import java.io.UnsupportedEncodingException; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.Random; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicLong; - import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.PosixParser; +import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.apache.rocketmq.client.exception.MQBrokerException; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.log.ClientLogger; import org.apache.rocketmq.client.producer.DefaultMQProducer; -import org.apache.rocketmq.logging.InternalLogger; import org.apache.rocketmq.common.message.Message; +import org.apache.rocketmq.logging.InternalLogger; import org.apache.rocketmq.remoting.RPCHook; import org.apache.rocketmq.remoting.common.RemotingHelper; import org.apache.rocketmq.remoting.exception.RemotingException; import org.apache.rocketmq.srvutil.ServerUtil; +import java.io.UnsupportedEncodingException; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.Random; +import java.util.TimerTask; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.atomic.AtomicLong; + public class Producer { public static void main(String[] args) throws MQClientException, UnsupportedEncodingException { @@ -73,7 +75,8 @@ public class Producer { final StatsBenchmarkProducer statsBenchmark = new StatsBenchmarkProducer(); - final Timer timer = new Timer("BenchmarkTimerThread", true); + ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1, + new BasicThreadFactory.Builder().namingPattern("BenchmarkTimerThread-%d").daemon(true).build()); final LinkedList snapshotList = new LinkedList(); @@ -87,7 +90,7 @@ public class Producer { } } - timer.scheduleAtFixedRate(new TimerTask() { + executorService.scheduleAtFixedRate(new TimerTask() { @Override public void run() { snapshotList.addLast(statsBenchmark.createSnapshot()); @@ -95,9 +98,9 @@ public class Producer { snapshotList.removeFirst(); } } - }, 1000, 1000); + }, 1000, 1000, TimeUnit.MILLISECONDS); - timer.scheduleAtFixedRate(new TimerTask() { + executorService.scheduleAtFixedRate(new TimerTask() { private void printStats() { if (snapshotList.size() >= 10) { doPrintStats(snapshotList, statsBenchmark, false); @@ -112,7 +115,7 @@ public class Producer { e.printStackTrace(); } } - }, 10000, 10000); + }, 10000, 10000, TimeUnit.MILLISECONDS); RPCHook rpcHook = aclEnable ? AclClient.getAclRPCHook() : null; final DefaultMQProducer producer = new DefaultMQProducer("benchmark_producer", rpcHook, msgTraceEnable, null); @@ -224,7 +227,12 @@ public class Producer { try { sendThreadPool.shutdown(); sendThreadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); - timer.cancel(); + executorService.shutdown(); + try { + executorService.awaitTermination(5000, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + } + if (snapshotList.size() > 1) { doPrintStats(snapshotList, statsBenchmark, true); } else { diff --git a/example/src/main/java/org/apache/rocketmq/example/benchmark/TransactionProducer.java b/example/src/main/java/org/apache/rocketmq/example/benchmark/TransactionProducer.java index 1b511d8a9e5ffef29452badc44176ad5833855a7..c4f14a48b9b3ed795bbf92ee40f44144669ec109 100644 --- a/example/src/main/java/org/apache/rocketmq/example/benchmark/TransactionProducer.java +++ b/example/src/main/java/org/apache/rocketmq/example/benchmark/TransactionProducer.java @@ -17,26 +17,11 @@ package org.apache.rocketmq.example.benchmark; -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ThreadLocalRandom; -import java.util.concurrent.atomic.AtomicLong; - import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.PosixParser; +import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.producer.LocalTransactionState; import org.apache.rocketmq.client.producer.SendResult; @@ -48,6 +33,24 @@ import org.apache.rocketmq.common.message.MessageConst; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.srvutil.ServerUtil; +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.TimerTask; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + public class TransactionProducer { private static final long START_TIME = System.currentTimeMillis(); private static final AtomicLong MSG_COUNT = new AtomicLong(0); @@ -75,11 +78,12 @@ public class TransactionProducer { final StatsBenchmarkTProducer statsBenchmark = new StatsBenchmarkTProducer(); - final Timer timer = new Timer("BenchmarkTimerThread", true); + ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1, + new BasicThreadFactory.Builder().namingPattern("BenchmarkTimerThread-%d").daemon(true).build()); final LinkedList snapshotList = new LinkedList<>(); - timer.scheduleAtFixedRate(new TimerTask() { + executorService.scheduleAtFixedRate(new TimerTask() { @Override public void run() { snapshotList.addLast(statsBenchmark.createSnapshot()); @@ -87,9 +91,9 @@ public class TransactionProducer { snapshotList.removeFirst(); } } - }, 1000, 1000); + }, 1000, 1000, TimeUnit.MILLISECONDS); - timer.scheduleAtFixedRate(new TimerTask() { + executorService.scheduleAtFixedRate(new TimerTask() { private void printStats() { if (snapshotList.size() >= 10) { Snapshot begin = snapshotList.getFirst(); @@ -121,7 +125,7 @@ public class TransactionProducer { e.printStackTrace(); } } - }, 10000, 10000); + }, 10000, 10000, TimeUnit.MILLISECONDS); final TransactionListener transactionCheckListener = new TransactionListenerImpl(statsBenchmark, config); final TransactionMQProducer producer = new TransactionMQProducer( 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 24845fc058952bf5556372be7e0af8207016da13..7f18ddd54130b080b474b4a5977b25b9ba4715a0 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 @@ -53,6 +53,7 @@ public abstract class UnaryExpression implements Expression { public static Expression createNegate(Expression left) { return new UnaryExpression(left, UnaryType.NEGATE) { + @Override public Object evaluate(EvaluationContext context) throws Exception { Object rvalue = right.evaluate(context); if (rvalue == null) { @@ -64,6 +65,7 @@ public abstract class UnaryExpression implements Expression { return null; } + @Override public String getExpressionSymbol() { return "-"; } @@ -85,6 +87,7 @@ public abstract class UnaryExpression implements Expression { final Collection inList = t; return new UnaryInExpression(right, UnaryType.IN, inList, not) { + @Override public Object evaluate(EvaluationContext context) throws Exception { Object rvalue = right.evaluate(context); @@ -103,8 +106,9 @@ public abstract class UnaryExpression implements Expression { } + @Override public String toString() { - StringBuffer answer = new StringBuffer(); + StringBuilder answer = new StringBuilder(); answer.append(right); answer.append(" "); answer.append(getExpressionSymbol()); @@ -124,6 +128,7 @@ public abstract class UnaryExpression implements Expression { return answer.toString(); } + @Override public String getExpressionSymbol() { if (not) { return "NOT IN"; @@ -139,6 +144,7 @@ public abstract class UnaryExpression implements Expression { super(left, unaryType); } + @Override public boolean matches(EvaluationContext context) throws Exception { Object object = evaluate(context); return object != null && object == Boolean.TRUE; @@ -147,6 +153,7 @@ public abstract class UnaryExpression implements Expression { public static BooleanExpression createNOT(BooleanExpression left) { return new BooleanUnaryExpression(left, UnaryType.NOT) { + @Override public Object evaluate(EvaluationContext context) throws Exception { Boolean lvalue = (Boolean) right.evaluate(context); if (lvalue == null) { @@ -155,6 +162,7 @@ public abstract class UnaryExpression implements Expression { return lvalue.booleanValue() ? Boolean.FALSE : Boolean.TRUE; } + @Override public String getExpressionSymbol() { return "NOT"; } @@ -163,6 +171,7 @@ public abstract class UnaryExpression implements Expression { public static BooleanExpression createBooleanCast(Expression left) { return new BooleanUnaryExpression(left, UnaryType.BOOLEANCAST) { + @Override public Object evaluate(EvaluationContext context) throws Exception { Object rvalue = right.evaluate(context); if (rvalue == null) { @@ -174,10 +183,12 @@ public abstract class UnaryExpression implements Expression { return ((Boolean) rvalue).booleanValue() ? Boolean.TRUE : Boolean.FALSE; } + @Override public String toString() { return right.toString(); } + @Override public String getExpressionSymbol() { return ""; } @@ -233,6 +244,7 @@ public abstract class UnaryExpression implements Expression { /** * @see Object#toString() */ + @Override public String toString() { return "(" + getExpressionSymbol() + " " + right.toString() + ")"; } @@ -240,6 +252,7 @@ public abstract class UnaryExpression implements Expression { /** * @see Object#hashCode() */ + @Override public int hashCode() { return toString().hashCode(); } @@ -247,6 +260,7 @@ public abstract class UnaryExpression implements Expression { /** * @see Object#equals(Object) */ + @Override public boolean equals(Object o) { if (o == null || !this.getClass().equals(o.getClass())) { 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 06014cbcbed6e0a8d2e521c5ae05c575dcb991f5..0a327bea1c05bec62ba24ddfd4b191819b534217 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 @@ -106,7 +106,7 @@ public class ParseException extends Exception { int[][] expectedTokenSequences, String[] tokenImage) { String eol = System.getProperty("line.separator", "\n"); - StringBuffer expected = new StringBuffer(); + StringBuilder expected = new StringBuilder(); int maxSize = 0; for (int i = 0; i < expectedTokenSequences.length; i++) { if (maxSize < expectedTokenSequences[i].length) { @@ -123,8 +123,9 @@ public class ParseException extends Exception { String retval = "Encountered \""; Token tok = currentToken.next; for (int i = 0; i < maxSize; i++) { - if (i != 0) + if (i != 0) { retval += " "; + } if (tok.kind == 0) { retval += tokenImage[0]; break; @@ -157,7 +158,7 @@ public class ParseException extends Exception { * string literal. */ static String add_escapes(String str) { - StringBuffer retval = new StringBuffer(); + StringBuilder retval = new StringBuilder(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) { 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 e8132df5aac561730e62e9fe199f68e1ee7c0d53..0aeb27cf4caaf88f2460fc8f92303b19141883fd 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 @@ -66,7 +66,7 @@ public class TokenMgrError extends Error { * equivalents in the given string */ protected static final String addEscapes(String str) { - StringBuffer retval = new StringBuffer(); + StringBuilder retval = new StringBuilder(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) { @@ -141,6 +141,7 @@ public class TokenMgrError extends Error { *

* from this method for such cases in the release version of your parser. */ + @Override public String getMessage() { return super.getMessage(); } diff --git a/filter/src/test/java/org/apache/rocketmq/filter/ParserTest.java b/filter/src/test/java/org/apache/rocketmq/filter/ParserTest.java index 115632faa0a6741d4b112872d15b71800451f587..7dc2ab25468523e32c341f798378dc5368d11e63 100644 --- a/filter/src/test/java/org/apache/rocketmq/filter/ParserTest.java +++ b/filter/src/test/java/org/apache/rocketmq/filter/ParserTest.java @@ -84,7 +84,7 @@ public class ParserTest { @Test public void testParse_floatOverFlow() { try { - StringBuffer sb = new StringBuffer(210000); + StringBuilder sb = new StringBuilder(210000); sb.append("1"); for (int i = 0; i < 2048; i ++) { sb.append("111111111111111111111111111111111111111111111111111"); 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 f244bf4c853551ad8b4810f95a78b039ae6d239b..7dacea9c132360d6c54bd6b77c3b2da26b43b911 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 @@ -36,7 +36,7 @@ public class RemotingHelper { private static final InternalLogger log = InternalLoggerFactory.getLogger(ROCKETMQ_REMOTING); public static String exceptionSimpleDesc(final Throwable e) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); if (e != null) { sb.append(e.toString()); 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 e151844706601bad8a19a1e8784bc95ffa0a314e..7bb6a8b4f5a653801c82d52b93e38cfabfcf09d6 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 @@ -159,7 +159,7 @@ public class BrokerStatsManager { } public String buildStatsKey(String topic, String group) { - StringBuffer strBuilder = new StringBuffer(); + StringBuilder strBuilder = new StringBuilder(); strBuilder.append(topic); strBuilder.append("@"); strBuilder.append(group); @@ -217,7 +217,7 @@ public class BrokerStatsManager { } public String buildCommercialStatsKey(String owner, String topic, String group, String type) { - StringBuffer strBuilder = new StringBuffer(); + StringBuilder strBuilder = new StringBuilder(); strBuilder.append(owner); strBuilder.append("@"); strBuilder.append(topic); 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 8c7bec616d7068a8fab2c8c03d79cabcfb1e64cb..17abdf218cb366e6f8c902caea5d567674196c86 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 @@ -114,7 +114,7 @@ public class QueryMsgByUniqueKeySubCommand implements SubCommand { private static String createBodyFile(MessageExt msg, int index) throws IOException { DataOutputStream dos = null; try { - StringBuffer bodyTmpFilePath = new StringBuffer("/tmp/rocketmq/msgbodys"); + StringBuilder bodyTmpFilePath = new StringBuilder("/tmp/rocketmq/msgbodys"); File file = new File(bodyTmpFilePath.toString()); if (!file.exists()) { file.mkdirs(); @@ -127,8 +127,9 @@ public class QueryMsgByUniqueKeySubCommand implements SubCommand { dos.write(msg.getBody()); return bodyTmpFilePath.toString(); } finally { - if (dos != null) + if (dos != null) { dos.close(); + } } }