You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tubemq.apache.org by go...@apache.org on 2020/04/09 10:24:15 UTC

[incubator-tubemq] branch master updated: [TUBEMQ-60] Remove unnecessary synchronized & using IllegalArgumentException instead of IllegalStateException (#47)

This is an automated email from the ASF dual-hosted git repository.

gosonzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tubemq.git


The following commit(s) were added to refs/heads/master by this push:
     new 751b8a5  [TUBEMQ-60] Remove unnecessary synchronized & using IllegalArgumentException instead of IllegalStateException (#47)
751b8a5 is described below

commit 751b8a57bcfdea21c5800dc9c03412b61b2d8887
Author: Tboy <gu...@immomo.com>
AuthorDate: Thu Apr 9 18:24:06 2020 +0800

    [TUBEMQ-60] Remove unnecessary synchronized & using IllegalArgumentException instead of IllegalStateException (#47)
---
 .../tubemq/client/producer/ProducerManager.java     |  8 ++++----
 .../java/org/apache/tubemq/corebase/Message.java    | 21 +++++++++------------
 2 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/tubemq-client/src/main/java/org/apache/tubemq/client/producer/ProducerManager.java b/tubemq-client/src/main/java/org/apache/tubemq/client/producer/ProducerManager.java
index 5335464..2d7c633 100644
--- a/tubemq-client/src/main/java/org/apache/tubemq/client/producer/ProducerManager.java
+++ b/tubemq-client/src/main/java/org/apache/tubemq/client/producer/ProducerManager.java
@@ -167,7 +167,7 @@ public class ProducerManager {
      * @param topic topic name
      * @throws TubeClientException
      */
-    public synchronized void publish(final String topic) throws TubeClientException {
+    public void publish(final String topic) throws TubeClientException {
         checkServiceStatus();
         StringBuilder sBuilder = new StringBuilder(512);
         try {
@@ -212,7 +212,7 @@ public class ProducerManager {
      * @return a set of successful published topic names
      * @throws TubeClientException
      */
-    public synchronized Set<String> publish(Set<String> topicSet) throws TubeClientException {
+    public Set<String> publish(Set<String> topicSet) throws TubeClientException {
         checkServiceStatus();
         StringBuilder sBuilder = new StringBuilder(512);
         Set<String> failTopicSet = new HashSet<String>();
@@ -341,7 +341,7 @@ public class ProducerManager {
      *
      * @param topicSet
      */
-    public synchronized void removeTopic(Set<String> topicSet) {
+    public void removeTopic(Set<String> topicSet) {
         for (String topic : topicSet) {
             if (topic == null) {
                 continue;
@@ -499,7 +499,7 @@ public class ProducerManager {
         topicPartitionMap = partitionListMap;
     }
 
-    private synchronized String generateProducerID() throws Exception {
+    private String generateProducerID() throws Exception {
         String pidName = ManagementFactory.getRuntimeMXBean().getName();
         if (pidName != null && pidName.contains("@")) {
             pidName = pidName.split("@")[0];
diff --git a/tubemq-core/src/main/java/org/apache/tubemq/corebase/Message.java b/tubemq-core/src/main/java/org/apache/tubemq/corebase/Message.java
index dc1190e..fa04525 100644
--- a/tubemq-core/src/main/java/org/apache/tubemq/corebase/Message.java
+++ b/tubemq-core/src/main/java/org/apache/tubemq/corebase/Message.java
@@ -21,7 +21,6 @@ import java.io.Serializable;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
-import java.util.Date;
 import org.apache.tubemq.corebase.utils.TStringUtils;
 
 /**
@@ -120,15 +119,14 @@ public class Message implements Serializable {
         if (TStringUtils.isNotBlank(msgTime)) {
             String tmpMsgTime = msgTime.trim();
             if (tmpMsgTime.length() != 12) {
-                throw new IllegalStateException("Illegal parameter: msgTime's value "
+                throw new IllegalArgumentException("Illegal parameter: msgTime's value "
                         + "must 'yyyyMMddHHmm' format and length must equal 12!");
             }
-            Date tmpDate;
             SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
             try {
-                tmpDate = sdf.parse(tmpMsgTime);
+                sdf.parse(tmpMsgTime);
             } catch (ParseException e) {
-                throw new IllegalStateException("Illegal parameter: parse msgTime value"
+                throw new IllegalArgumentException("Illegal parameter: parse msgTime value"
                         + " failure , msgType's value must 'yyyyMMddHHmm' format!");
             }
             this.msgTime = tmpMsgTime;
@@ -201,7 +199,7 @@ public class Message implements Serializable {
      */
     public String getAttrValue(final String keyVal) {
         if (TStringUtils.isBlank(keyVal)) {
-            throw new IllegalStateException("keyVal's value is blank!");
+            throw new IllegalArgumentException("keyVal's value is blank!");
         }
         if (TStringUtils.isBlank(this.attribute)) {
             return null;
@@ -226,16 +224,16 @@ public class Message implements Serializable {
      */
     public void setAttrKeyVal(final String keyVal, final String valueVal) {
         if (TStringUtils.isBlank(keyVal)) {
-            throw new IllegalStateException("keyVal's value is blank!");
+            throw new IllegalArgumentException("keyVal's value is blank!");
         }
         if (TStringUtils.isBlank(valueVal)) {
-            throw new IllegalStateException("valueVal's value is blank!");
+            throw new IllegalArgumentException("valueVal's value is blank!");
         }
         if (keyVal.contains(TokenConstants.TOKEN_MSG_TYPE)
                 || keyVal.contains(TokenConstants.TOKEN_MSG_TIME)
                 || valueVal.contains(TokenConstants.TOKEN_MSG_TYPE)
                 || valueVal.contains(TokenConstants.TOKEN_MSG_TIME)) {
-            throw new IllegalStateException(new StringBuilder(512).append("System Headers(")
+            throw new IllegalArgumentException(new StringBuilder(512).append("System Headers(")
                     .append(TokenConstants.TOKEN_MSG_TYPE).append(",")
                     .append(TokenConstants.TOKEN_MSG_TIME)
                     .append(") are reserved tokens, can't include in keyVal or valueVal!").toString());
@@ -244,7 +242,7 @@ public class Message implements Serializable {
                 || keyVal.contains(TokenConstants.EQ))
                 || (valueVal.contains(TokenConstants.ARRAY_SEP)
                 || valueVal.contains(TokenConstants.EQ))) {
-            throw new IllegalStateException(new StringBuilder(512).append("(")
+            throw new IllegalArgumentException(new StringBuilder(512).append("(")
                     .append(TokenConstants.ARRAY_SEP).append(",")
                     .append(TokenConstants.EQ).append(
                             ") are reserved tokens, can't include in keyVal or valueVal!").toString());
@@ -339,10 +337,9 @@ public class Message implements Serializable {
                     } else if (strAttrItem.contains(TokenConstants.TOKEN_MSG_TIME)) {
                         String[] strItems = strAttrItem.split(TokenConstants.EQ);
                         if (strItems.length > 1) {
-                            Date tmpDate;
                             SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
                             try {
-                                tmpDate = sdf.parse(strItems[1]);
+                                sdf.parse(strItems[1]);
                                 this.msgTime = strItems[1];
                             } catch (ParseException e) {
                                 this.msgTime = "";