From 62063599314e832beb0a706bec6e805c07311204 Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Fri, 30 Jul 2021 23:05:04 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20Common=20=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=E5=8F=8A=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E8=B0=83=E6=95=B4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../threadpool/common/constant/Constants.java | 2 +- .../common/executor/ThreadPoolManager.java | 2 +- .../common/model/PoolParameterInfo.java | 2 + .../common/model/PoolRunStateInfo.java | 1 + .../common/toolkit/ContentUtil.java | 38 ++++++------------- .../threadpool/common/toolkit/GroupKey.java | 11 +----- .../threadpool/common/web/base/Result.java | 1 + 7 files changed, 20 insertions(+), 37 deletions(-) diff --git a/common/src/main/java/io/dynamic/threadpool/common/constant/Constants.java b/common/src/main/java/io/dynamic/threadpool/common/constant/Constants.java index 6e46ac9c..e6815d9b 100644 --- a/common/src/main/java/io/dynamic/threadpool/common/constant/Constants.java +++ b/common/src/main/java/io/dynamic/threadpool/common/constant/Constants.java @@ -26,7 +26,7 @@ public class Constants { public static final String GENERAL_SPLIT_SYMBOL = ","; - public static final String LONGPOLLING_LINE_SEPARATOR = "\r\n"; + public static final String LONG_POLLING_LINE_SEPARATOR = "\r\n"; public static final String BASE_PATH = "/v1/cs"; diff --git a/common/src/main/java/io/dynamic/threadpool/common/executor/ThreadPoolManager.java b/common/src/main/java/io/dynamic/threadpool/common/executor/ThreadPoolManager.java index e379ed38..e994c0ea 100644 --- a/common/src/main/java/io/dynamic/threadpool/common/executor/ThreadPoolManager.java +++ b/common/src/main/java/io/dynamic/threadpool/common/executor/ThreadPoolManager.java @@ -33,7 +33,7 @@ public class ThreadPoolManager { } private void init() { - resourcesManager = new ConcurrentHashMap>>(8); + resourcesManager = new ConcurrentHashMap(8); } public void register(String tenantId, String group, ExecutorService executor) { diff --git a/common/src/main/java/io/dynamic/threadpool/common/model/PoolParameterInfo.java b/common/src/main/java/io/dynamic/threadpool/common/model/PoolParameterInfo.java index b834dd69..8b8da771 100644 --- a/common/src/main/java/io/dynamic/threadpool/common/model/PoolParameterInfo.java +++ b/common/src/main/java/io/dynamic/threadpool/common/model/PoolParameterInfo.java @@ -1,6 +1,7 @@ package io.dynamic.threadpool.common.model; import lombok.Data; +import lombok.experimental.Accessors; import java.io.Serializable; @@ -11,6 +12,7 @@ import java.io.Serializable; * @date 2021/6/16 23:18 */ @Data +@Accessors(chain = true) public class PoolParameterInfo implements PoolParameter, Serializable { private static final long serialVersionUID = -7123935122108553864L; diff --git a/common/src/main/java/io/dynamic/threadpool/common/model/PoolRunStateInfo.java b/common/src/main/java/io/dynamic/threadpool/common/model/PoolRunStateInfo.java index 16218be2..52bfffc1 100644 --- a/common/src/main/java/io/dynamic/threadpool/common/model/PoolRunStateInfo.java +++ b/common/src/main/java/io/dynamic/threadpool/common/model/PoolRunStateInfo.java @@ -89,4 +89,5 @@ public class PoolRunStateInfo implements Serializable { * Host */ private String host; + } diff --git a/common/src/main/java/io/dynamic/threadpool/common/toolkit/ContentUtil.java b/common/src/main/java/io/dynamic/threadpool/common/toolkit/ContentUtil.java index 8fc7af44..41d5e6a4 100644 --- a/common/src/main/java/io/dynamic/threadpool/common/toolkit/ContentUtil.java +++ b/common/src/main/java/io/dynamic/threadpool/common/toolkit/ContentUtil.java @@ -13,34 +13,20 @@ import io.dynamic.threadpool.common.model.PoolParameterInfo; */ public class ContentUtil { - /*public static String getPoolContent(PoolParameter parameter) { - StringBuilder stringBuilder = new StringBuilder(); - String resultStr = stringBuilder.append(parameter.getCoreSize()) - .append(parameter.getMaxSize()) - .append(parameter.getQueueType()) - .append(parameter.getCapacity()) - .append(parameter.getKeepAliveTime()) - .append(parameter.getIsAlarm()) - .append(parameter.getCapacityAlarm()) - .append(parameter.getLivenessAlarm()) - .toString(); - return resultStr; - }*/ - public static String getPoolContent(PoolParameter parameter) { PoolParameterInfo poolInfo = new PoolParameterInfo(); - poolInfo.setTenantId(parameter.getTenantId()); - poolInfo.setItemId(parameter.getItemId()); - poolInfo.setTpId(parameter.getTpId()); - poolInfo.setCoreSize(parameter.getCoreSize()); - poolInfo.setMaxSize(parameter.getMaxSize()); - poolInfo.setQueueType(parameter.getQueueType()); - poolInfo.setCapacity(parameter.getCapacity()); - poolInfo.setKeepAliveTime(parameter.getKeepAliveTime()); - poolInfo.setIsAlarm(parameter.getIsAlarm()); - poolInfo.setCapacityAlarm(parameter.getCapacityAlarm()); - poolInfo.setLivenessAlarm(parameter.getLivenessAlarm()); - poolInfo.setRejectedType(parameter.getRejectedType()); + poolInfo.setTenantId(parameter.getTenantId()) + .setItemId(parameter.getItemId()) + .setTpId(parameter.getTpId()) + .setCoreSize(parameter.getCoreSize()) + .setMaxSize(parameter.getMaxSize()) + .setQueueType(parameter.getQueueType()) + .setCapacity(parameter.getCapacity()) + .setKeepAliveTime(parameter.getKeepAliveTime()) + .setIsAlarm(parameter.getIsAlarm()) + .setCapacityAlarm(parameter.getCapacityAlarm()) + .setLivenessAlarm(parameter.getLivenessAlarm()) + .setRejectedType(parameter.getRejectedType()); return JSON.toJSONString(poolInfo); } diff --git a/common/src/main/java/io/dynamic/threadpool/common/toolkit/GroupKey.java b/common/src/main/java/io/dynamic/threadpool/common/toolkit/GroupKey.java index f189541a..ef13ef36 100644 --- a/common/src/main/java/io/dynamic/threadpool/common/toolkit/GroupKey.java +++ b/common/src/main/java/io/dynamic/threadpool/common/toolkit/GroupKey.java @@ -9,6 +9,7 @@ import org.springframework.util.StringUtils; * @date 2021/6/24 21:12 */ public class GroupKey { + public static String getKey(String dataId, String group) { return getKey(dataId, group, ""); } @@ -34,12 +35,6 @@ public class GroupKey { return sb.toString(); } - /** - * Parse key. - * - * @param groupKey group key - * @return parsed key - */ public static String[] parseKey(String groupKey) { StringBuilder sb = new StringBuilder(); String dataId = null; @@ -88,9 +83,6 @@ public class GroupKey { return new String[]{dataId, group, tenant}; } - /** - * + -> %2B % -> %25. - */ public static void urlEncode(String str, StringBuilder sb) { for (int idx = 0; idx < str.length(); ++idx) { char c = str.charAt(idx); @@ -103,4 +95,5 @@ public class GroupKey { } } } + } diff --git a/common/src/main/java/io/dynamic/threadpool/common/web/base/Result.java b/common/src/main/java/io/dynamic/threadpool/common/web/base/Result.java index 638d99cb..ed2f85a1 100644 --- a/common/src/main/java/io/dynamic/threadpool/common/web/base/Result.java +++ b/common/src/main/java/io/dynamic/threadpool/common/web/base/Result.java @@ -32,4 +32,5 @@ public class Result implements Serializable { public boolean isFail() { return !isSuccess(); } + }