diff --git a/README.md b/README.md index e82336c..318c95a 100644 --- a/README.md +++ b/README.md @@ -257,7 +257,7 @@ You can import all vrml modules: group.rxcloud vrml - 1.1.3 + 1.1.4 pom import @@ -269,7 +269,7 @@ Latest feature branch: group.rxcloud vrml - 1.1.3 + 1.1.4 pom import diff --git a/README_CN.md b/README_CN.md index e5199e7..c400bc5 100644 --- a/README_CN.md +++ b/README_CN.md @@ -256,7 +256,7 @@ You can import all vrml modules: group.rxcloud vrml - 1.1.3 + 1.1.4 pom import @@ -269,7 +269,7 @@ Latest feature branch: group.rxcloud vrml - 1.1.3 + 1.1.4 pom import diff --git a/pom.xml b/pom.xml index 56d754a..c8fbcde 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ group.rxcloud vrml pom - 1.1.3 + 1.1.4 vrml Vrml is a useful api library for java work. diff --git a/vrml-alert/README.md b/vrml-alert/README.md index 04b8533..b8578c9 100644 --- a/vrml-alert/README.md +++ b/vrml-alert/README.md @@ -16,7 +16,7 @@ An alert API that supports multiple methods for [vrml](https://github.com/kevint group.rxcloud vrml-alert - 1.1.3 + 1.1.4 ``` @@ -177,7 +177,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-alert - 1.1.3 + 1.1.4 ``` diff --git a/vrml-alert/README_ZH.md b/vrml-alert/README_ZH.md index 1f1477e..dbc8be9 100644 --- a/vrml-alert/README_ZH.md +++ b/vrml-alert/README_ZH.md @@ -16,7 +16,7 @@ Alert支持各种快捷灵活方式的告警API,避免过程式的调用告警 group.rxcloud vrml-alert - 1.1.3 + 1.1.4 ``` @@ -177,7 +177,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-alert - 1.1.3 + 1.1.4 ``` diff --git a/vrml-alert/WIKI.md b/vrml-alert/WIKI.md index c20e405..bf9f62b 100644 --- a/vrml-alert/WIKI.md +++ b/vrml-alert/WIKI.md @@ -164,6 +164,6 @@ EmailAlertActor.onReceive(message); group.rxcloud vrml-alert - 1.1.3 + 1.1.4 ``` \ No newline at end of file diff --git a/vrml-alert/pom.xml b/vrml-alert/pom.xml index efc02aa..3a33bc5 100644 --- a/vrml-alert/pom.xml +++ b/vrml-alert/pom.xml @@ -7,7 +7,7 @@ group.rxcloud vrml - 1.1.3 + 1.1.4 vrml-alert diff --git a/vrml-all/pom.xml b/vrml-all/pom.xml index d8eb859..a6727ed 100644 --- a/vrml-all/pom.xml +++ b/vrml-all/pom.xml @@ -7,7 +7,7 @@ group.rxcloud vrml - 1.1.3 + 1.1.4 vrml-all diff --git a/vrml-api/README.md b/vrml-api/README.md index 8dbb857..8ba6c46 100644 --- a/vrml-api/README.md +++ b/vrml-api/README.md @@ -12,7 +12,7 @@ A Aspect to log request process for [vrml](https://github.com/kevinten10/vrml) l group.rxcloud vrml-api - 1.1.3 + 1.1.4 ``` @@ -150,7 +150,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-api - 1.1.3 + 1.1.4 ``` diff --git a/vrml-api/README_ZH.md b/vrml-api/README_ZH.md index 278351b..2ababb0 100644 --- a/vrml-api/README_ZH.md +++ b/vrml-api/README_ZH.md @@ -16,7 +16,7 @@ Api模块提供一个可拓展的切面,使用LogsAPI记录网络请求的日 group.rxcloud vrml-api - 1.1.3 + 1.1.4 ``` @@ -158,7 +158,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-api - 1.1.3 + 1.1.4 ``` diff --git a/vrml-api/WIKI.md b/vrml-api/WIKI.md index 0812ce7..a5dc786 100644 --- a/vrml-api/WIKI.md +++ b/vrml-api/WIKI.md @@ -176,6 +176,6 @@ public class ApiLogInterceptorAspectTest { group.rxcloud vrml-api - 1.1.3 + 1.1.4 ``` \ No newline at end of file diff --git a/vrml-api/pom.xml b/vrml-api/pom.xml index 6328e53..a939dd4 100644 --- a/vrml-api/pom.xml +++ b/vrml-api/pom.xml @@ -7,7 +7,7 @@ vrml group.rxcloud - 1.1.3 + 1.1.4 vrml-api diff --git a/vrml-compute/README.md b/vrml-compute/README.md index ad7a936..6c027a8 100644 --- a/vrml-compute/README.md +++ b/vrml-compute/README.md @@ -13,7 +13,7 @@ group.rxcloud vrml-compute - 1.1.3 + 1.1.4 ``` @@ -62,7 +62,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-compute - 1.1.3 + 1.1.4 ``` diff --git a/vrml-compute/pom.xml b/vrml-compute/pom.xml index 41ce30b..80c7d4d 100644 --- a/vrml-compute/pom.xml +++ b/vrml-compute/pom.xml @@ -7,7 +7,7 @@ vrml group.rxcloud - 1.1.3 + 1.1.4 vrml-compute diff --git a/vrml-core/README.md b/vrml-core/README.md index 5b25b95..bbb8c91 100644 --- a/vrml-core/README.md +++ b/vrml-core/README.md @@ -12,7 +12,7 @@ The core API for all vrml lib for [vrml](https://github.com/kevinten10/vrml) lib group.rxcloud vrml-core - 1.1.3 + 1.1.4 ``` @@ -150,7 +150,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-core - 1.1.3 + 1.1.4 ``` diff --git a/vrml-core/pom.xml b/vrml-core/pom.xml index adac6ec..3fa77ae 100644 --- a/vrml-core/pom.xml +++ b/vrml-core/pom.xml @@ -7,7 +7,7 @@ group.rxcloud vrml - 1.1.3 + 1.1.4 vrml-core diff --git a/vrml-data/README.md b/vrml-data/README.md index 2b97895..dd64edb 100644 --- a/vrml-data/README.md +++ b/vrml-data/README.md @@ -12,7 +12,7 @@ A common data structure extension API for [vrml](https://github.com/kevinten10/v group.rxcloud vrml-data - 1.1.3 + 1.1.4 ``` @@ -101,7 +101,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-data - 1.1.3 + 1.1.4 ``` diff --git a/vrml-data/pom.xml b/vrml-data/pom.xml index 13cf1a9..bc84707 100644 --- a/vrml-data/pom.xml +++ b/vrml-data/pom.xml @@ -7,7 +7,7 @@ group.rxcloud vrml - 1.1.3 + 1.1.4 vrml-data diff --git a/vrml-error/README.md b/vrml-error/README.md index cdb7ecc..9ed4f2a 100644 --- a/vrml-error/README.md +++ b/vrml-error/README.md @@ -12,7 +12,7 @@ A set of error code definition specifications for [vrml](https://github.com/kevi group.rxcloud vrml-error - 1.1.3 + 1.1.4 ``` @@ -136,7 +136,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-error - 1.1.3 + 1.1.4 ``` diff --git a/vrml-error/README_ZH.md b/vrml-error/README_ZH.md index f184953..7983471 100644 --- a/vrml-error/README_ZH.md +++ b/vrml-error/README_ZH.md @@ -12,7 +12,7 @@ group.rxcloud vrml-error - 1.1.3 + 1.1.4 ``` @@ -137,7 +137,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-error - 1.1.3 + 1.1.4 ``` diff --git a/vrml-error/WIKI.md b/vrml-error/WIKI.md index be58de0..6513aae 100644 --- a/vrml-error/WIKI.md +++ b/vrml-error/WIKI.md @@ -121,6 +121,6 @@ public enum ErrorCodes implements ErrorCodeContext { group.rxcloud vrml-error - 1.1.3 + 1.1.4 ``` \ No newline at end of file diff --git a/vrml-error/pom.xml b/vrml-error/pom.xml index 8909d6e..db2781c 100644 --- a/vrml-error/pom.xml +++ b/vrml-error/pom.xml @@ -7,7 +7,7 @@ group.rxcloud vrml - 1.1.3 + 1.1.4 vrml-error diff --git a/vrml-eventbus/README.md b/vrml-eventbus/README.md index 7a5b5c3..bb9a938 100644 --- a/vrml-eventbus/README.md +++ b/vrml-eventbus/README.md @@ -13,7 +13,7 @@ A publish event API for [vrml](https://github.com/kevinten10/vrml) library group.rxcloud vrml-eventbus - 1.1.3 + 1.1.4 ``` @@ -92,7 +92,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-eventbus - 1.1.3 + 1.1.4 ``` diff --git a/vrml-eventbus/pom.xml b/vrml-eventbus/pom.xml index 7b68856..8dfae60 100644 --- a/vrml-eventbus/pom.xml +++ b/vrml-eventbus/pom.xml @@ -7,7 +7,7 @@ group.rxcloud vrml - 1.1.3 + 1.1.4 vrml-eventbus diff --git a/vrml-external/pom.xml b/vrml-external/pom.xml index c38ff42..a24c764 100644 --- a/vrml-external/pom.xml +++ b/vrml-external/pom.xml @@ -7,7 +7,7 @@ vrml group.rxcloud - 1.1.3 + 1.1.4 vrml-external diff --git a/vrml-jmx/pom.xml b/vrml-jmx/pom.xml index 2fbe699..f14cbca 100644 --- a/vrml-jmx/pom.xml +++ b/vrml-jmx/pom.xml @@ -7,7 +7,7 @@ vrml group.rxcloud - 1.1.3 + 1.1.4 vrml-jmx diff --git a/vrml-log/README.md b/vrml-log/README.md index 2f38de7..d0bee40 100644 --- a/vrml-log/README.md +++ b/vrml-log/README.md @@ -12,7 +12,7 @@ A API to log by the key for [vrml](https://github.com/kevinten10/vrml) library group.rxcloud vrml-log - 1.1.3 + 1.1.4 ``` @@ -59,7 +59,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-logs - 1.1.3 + 1.1.4 ``` diff --git a/vrml-log/README_ZH.md b/vrml-log/README_ZH.md index 572ec69..5ed2808 100644 --- a/vrml-log/README_ZH.md +++ b/vrml-log/README_ZH.md @@ -12,7 +12,7 @@ group.rxcloud vrml-log - 1.1.3 + 1.1.4 ``` @@ -59,7 +59,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-logs - 1.1.3 + 1.1.4 ``` diff --git a/vrml-log/WIKI.md b/vrml-log/WIKI.md index 35a41a2..050e605 100644 --- a/vrml-log/WIKI.md +++ b/vrml-log/WIKI.md @@ -40,6 +40,6 @@ group.rxcloud vrml-log - 1.1.3 + 1.1.4 ``` \ No newline at end of file diff --git a/vrml-log/pom.xml b/vrml-log/pom.xml index 3142752..803e8c0 100644 --- a/vrml-log/pom.xml +++ b/vrml-log/pom.xml @@ -7,7 +7,7 @@ group.rxcloud vrml - 1.1.3 + 1.1.4 vrml-log diff --git a/vrml-maven/pom.xml b/vrml-maven/pom.xml index 185b439..b131eeb 100644 --- a/vrml-maven/pom.xml +++ b/vrml-maven/pom.xml @@ -7,7 +7,7 @@ group.rxcloud vrml - 1.1.3 + 1.1.4 vrml-maven diff --git a/vrml-metric/README.md b/vrml-metric/README.md index 71363b4..9858a0f 100644 --- a/vrml-metric/README.md +++ b/vrml-metric/README.md @@ -12,7 +12,7 @@ A API to record application's metrics data for [vrml](https://github.com/kevinte group.rxcloud vrml-metric - 1.1.3 + 1.1.4 ``` @@ -90,7 +90,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-metrics - 1.1.3 + 1.1.4 ``` diff --git a/vrml-metric/README_ZH.md b/vrml-metric/README_ZH.md index e48dcce..e8e9e8f 100644 --- a/vrml-metric/README_ZH.md +++ b/vrml-metric/README_ZH.md @@ -12,7 +12,7 @@ group.rxcloud vrml-metric - 1.1.3 + 1.1.4 ``` @@ -90,7 +90,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-metrics - 1.1.3 + 1.1.4 ``` diff --git a/vrml-metric/WIKI.md b/vrml-metric/WIKI.md index 1cd4671..d200111 100644 --- a/vrml-metric/WIKI.md +++ b/vrml-metric/WIKI.md @@ -87,6 +87,6 @@ private static void metrics(BiConsumer, Map> group.rxcloud vrml-metric - 1.1.3 + 1.1.4 ``` \ No newline at end of file diff --git a/vrml-metric/pom.xml b/vrml-metric/pom.xml index e2d34bd..a37d9f1 100644 --- a/vrml-metric/pom.xml +++ b/vrml-metric/pom.xml @@ -7,7 +7,7 @@ group.rxcloud vrml - 1.1.3 + 1.1.4 vrml-metric diff --git a/vrml-metric/src/main/java/group/rxcloud/vrml/metric/Metrics.java b/vrml-metric/src/main/java/group/rxcloud/vrml/metric/Metrics.java index 6b7de3f..11a13dc 100644 --- a/vrml-metric/src/main/java/group/rxcloud/vrml/metric/Metrics.java +++ b/vrml-metric/src/main/java/group/rxcloud/vrml/metric/Metrics.java @@ -735,7 +735,9 @@ public static void remove(String key) { */ public static Map showIndexs() { final Map index = INDEX_TAG.get(); - return new HashMap<>(index); + return index != null + ? new HashMap<>(index) + : new HashMap<>(); } /** @@ -746,7 +748,9 @@ public static Map showIndexs() { */ public static Map showIndexs(String key) { final Map index = KEY_INDEX_TAG.get().get(key); - return new HashMap<>(index); + return index != null + ? new HashMap<>(index) + : new HashMap<>(); } /** @@ -756,7 +760,9 @@ public static Map showIndexs(String key) { */ public static Map showStores() { final Map store = STORED_TAG.get(); - return new HashMap<>(store); + return store != null + ? new HashMap<>(store) + : new HashMap<>(); } /** @@ -767,6 +773,8 @@ public static Map showStores() { */ public static Map showStores(String key) { final Map store = KEY_STORED_TAG.get().get(key); - return new HashMap<>(store); + return store != null + ? new HashMap<>(store) + : new HashMap<>(); } } diff --git a/vrml-netty/README.md b/vrml-netty/README.md index da44f1d..4e50614 100644 --- a/vrml-netty/README.md +++ b/vrml-netty/README.md @@ -13,7 +13,7 @@ Netty拓展工具集。 group.rxcloud vrml-netty - 1.1.3 + 1.1.4 ``` @@ -42,7 +42,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-netty - 1.1.3 + 1.1.4 ``` diff --git a/vrml-netty/pom.xml b/vrml-netty/pom.xml index 1f57687..b3f217d 100644 --- a/vrml-netty/pom.xml +++ b/vrml-netty/pom.xml @@ -7,7 +7,7 @@ vrml group.rxcloud - 1.1.3 + 1.1.4 vrml-netty diff --git a/vrml-reactor/pom.xml b/vrml-reactor/pom.xml index c6b9f64..21d65a6 100644 --- a/vrml-reactor/pom.xml +++ b/vrml-reactor/pom.xml @@ -7,7 +7,7 @@ vrml group.rxcloud - 1.1.3 + 1.1.4 vrml-reactor diff --git a/vrml-reflect/pom.xml b/vrml-reflect/pom.xml index ea68bf9..c1b4dfe 100644 --- a/vrml-reflect/pom.xml +++ b/vrml-reflect/pom.xml @@ -7,7 +7,7 @@ vrml group.rxcloud - 1.1.3 + 1.1.4 vrml-reflect diff --git a/vrml-request/README.md b/vrml-request/README.md index 0db9ae3..37e3981 100644 --- a/vrml-request/README.md +++ b/vrml-request/README.md @@ -12,7 +12,7 @@ A proxy API to wrap remote request with log/record/check/... for [vrml](https:// group.rxcloud vrml-request - 1.1.3 + 1.1.4 ``` @@ -202,7 +202,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-request - 1.1.3 + 1.1.4 ``` diff --git a/vrml-request/README_ZH.md b/vrml-request/README_ZH.md index ff81cd7..019b546 100644 --- a/vrml-request/README_ZH.md +++ b/vrml-request/README_ZH.md @@ -12,7 +12,7 @@ group.rxcloud vrml-request - 1.1.3 + 1.1.4 ``` @@ -196,7 +196,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-request - 1.1.3 + 1.1.4 ``` diff --git a/vrml-request/WIKI.md b/vrml-request/WIKI.md index 785e001..f3ef7bc 100644 --- a/vrml-request/WIKI.md +++ b/vrml-request/WIKI.md @@ -204,6 +204,6 @@ public class HttpProxy extends AbstractHttpRequestProxy { group.rxcloud vrml-request - 1.1.3 + 1.1.4 ``` \ No newline at end of file diff --git a/vrml-request/pom.xml b/vrml-request/pom.xml index a579442..5bc907c 100644 --- a/vrml-request/pom.xml +++ b/vrml-request/pom.xml @@ -7,7 +7,7 @@ group.rxcloud vrml - 1.1.3 + 1.1.4 vrml-request diff --git a/vrml-request/src/main/java/group/rxcloud/vrml/request/proxy/AbstractRequestProxy.java b/vrml-request/src/main/java/group/rxcloud/vrml/request/proxy/AbstractRequestProxy.java index 9fb2253..e7c49cc 100644 --- a/vrml-request/src/main/java/group/rxcloud/vrml/request/proxy/AbstractRequestProxy.java +++ b/vrml-request/src/main/java/group/rxcloud/vrml/request/proxy/AbstractRequestProxy.java @@ -4,6 +4,10 @@ import group.rxcloud.vrml.error.code.ErrorCodeContext; import group.rxcloud.vrml.error.exception.ErrorCodeException; import group.rxcloud.vrml.log.Logs; +import io.vavr.control.Either; + +import java.util.ArrayList; +import java.util.List; /** * The abstract request proxy. @@ -71,6 +75,34 @@ public Response invoke(Request request) { } } + /** + * Invoke response with simple retry. + * + * @param request the request + * @param invokeMaxCount invoke max count + * @return the left is errors when all is failure; the right is response when success + */ + public Either, Response> invokeWithRetry(Request request, int invokeMaxCount) { + if (invokeMaxCount < 1) { + throw new IllegalArgumentException(String.format("[%s] invokeWithRetry invokeMaxCount[%s] is illegal.", + this.requestName(), invokeMaxCount)); + } + + List retryErrors = new ArrayList<>(); + for (int i = 0; i < invokeMaxCount; i++) { + try { + Response response = this.invoke(request); + return Either.right(response); + } catch (ErrorCodeException e) { + if (logs.isWarnEnabled()) { + logs.warn("[{}] invokeWithRetry count[{}] error: ", this.requestName(), i + 1, e); + } + retryErrors.add(this.throwsError(this.dependentErrorCode(), e)); + } + } + return Either.left(retryErrors); + } + /** * Logging request */ diff --git a/vrml-resource/README.md b/vrml-resource/README.md index d91dbd8..c1d5252 100644 --- a/vrml-resource/README.md +++ b/vrml-resource/README.md @@ -13,7 +13,7 @@ Java File工具集。 group.rxcloud vrml-resource - 1.1.3 + 1.1.4 ``` @@ -42,7 +42,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-resource - 1.1.3 + 1.1.4 ``` diff --git a/vrml-resource/pom.xml b/vrml-resource/pom.xml index 1108f19..f762ec5 100644 --- a/vrml-resource/pom.xml +++ b/vrml-resource/pom.xml @@ -7,7 +7,7 @@ vrml group.rxcloud - 1.1.3 + 1.1.4 vrml-resource diff --git a/vrml-shutdown/pom.xml b/vrml-shutdown/pom.xml index 992afb7..90e1092 100644 --- a/vrml-shutdown/pom.xml +++ b/vrml-shutdown/pom.xml @@ -7,7 +7,7 @@ vrml group.rxcloud - 1.1.3 + 1.1.4 vrml-shutdown diff --git a/vrml-spi/README.md b/vrml-spi/README.md index bc80124..8819bb3 100644 --- a/vrml-spi/README.md +++ b/vrml-spi/README.md @@ -13,7 +13,7 @@ Java SPI工具集。 group.rxcloud vrml-spi - 1.1.3 + 1.1.4 ``` @@ -42,7 +42,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-spi - 1.1.3 + 1.1.4 ``` diff --git a/vrml-spi/pom.xml b/vrml-spi/pom.xml index f86f16e..763fd73 100644 --- a/vrml-spi/pom.xml +++ b/vrml-spi/pom.xml @@ -7,7 +7,7 @@ vrml group.rxcloud - 1.1.3 + 1.1.4 vrml-spi diff --git a/vrml-stopwatch/pom.xml b/vrml-stopwatch/pom.xml index 53a1e95..6c7c058 100644 --- a/vrml-stopwatch/pom.xml +++ b/vrml-stopwatch/pom.xml @@ -7,7 +7,7 @@ vrml group.rxcloud - 1.1.3 + 1.1.4 vrml-stopwatch @@ -18,6 +18,10 @@ group.rxcloud vrml-spi + + group.rxcloud + vrml-metric + diff --git a/vrml-stopwatch/src/main/java/group/rxcloud/vrml/stopwatch/config/DefaultStopWatchLoggerMonitorConfiguration.java b/vrml-stopwatch/src/main/java/group/rxcloud/vrml/stopwatch/config/DefaultStopWatchLoggerMonitorConfiguration.java index d497cd8..a0bcda8 100644 --- a/vrml-stopwatch/src/main/java/group/rxcloud/vrml/stopwatch/config/DefaultStopWatchLoggerMonitorConfiguration.java +++ b/vrml-stopwatch/src/main/java/group/rxcloud/vrml/stopwatch/config/DefaultStopWatchLoggerMonitorConfiguration.java @@ -1,12 +1,14 @@ package group.rxcloud.vrml.stopwatch.config; +import group.rxcloud.vrml.metric.Metrics; import group.rxcloud.vrml.stopwatch.MonitorInfo; +import group.rxcloud.vrml.stopwatch.metric.StopWatchMetric; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.slf4j.MDC; import java.util.HashMap; import java.util.Map; +import java.util.stream.Collectors; /** * The Default monitor configuration. @@ -85,8 +87,25 @@ protected int getTimeout(MonitorInfo monitorInfo) { @Override public void doStopWatchMonitor(MonitorInfo monitorInfo) { + String id = monitorInfo.getId(); try { String record = this.getLogMessage(monitorInfo); + + Map indexes = Metrics.showIndexs(id); + if (!indexes.isEmpty()) { + StringBuilder builder = new StringBuilder(); + builder.append("[["); + String tags = indexes.entrySet().stream() + .map(entry -> entry.getKey() + "=" + entry.getValue()) + .collect(Collectors.joining(",")); + builder.append(tags); + builder.append("]]"); + + builder.append(record); + + record = builder.toString(); + } + String logLevel = this.getLogLevel(monitorInfo); switch (logLevel) { case "info": @@ -107,8 +126,7 @@ public void doStopWatchMonitor(MonitorInfo monitorInfo) { log.warn(record); } } finally { - // log with MDC - MDC.clear(); + Metrics.remove(id); } } @@ -120,8 +138,7 @@ protected String getLogMessage(MonitorInfo monitorInfo) { if (id != null) { builder.append("ID = [").append(id).append("], "); { - // mdc 1 - MDC.put("ID", id); + Metrics.index(id, StopWatchMetric.ID, id); } } @@ -129,8 +146,7 @@ protected String getLogMessage(MonitorInfo monitorInfo) { if (taskName != null) { builder.append("TaskName = [").append(taskName).append("], "); { - // mdc 2 - MDC.put("TaskName", taskName); + Metrics.index(id, StopWatchMetric.TaskName, taskName); } } @@ -138,8 +154,7 @@ protected String getLogMessage(MonitorInfo monitorInfo) { if (totalTimeMillis > 0) { builder.append("RunningTime = [").append(totalTimeMillis).append("]ms, "); { - // mdc 3 - MDC.put("RunningTime", String.valueOf(totalTimeMillis)); + Metrics.index(id, StopWatchMetric.RunningTime, String.valueOf(totalTimeMillis)); } } diff --git a/vrml-stopwatch/src/main/java/group/rxcloud/vrml/stopwatch/metric/StopWatchMetric.java b/vrml-stopwatch/src/main/java/group/rxcloud/vrml/stopwatch/metric/StopWatchMetric.java new file mode 100644 index 0000000..25ddabd --- /dev/null +++ b/vrml-stopwatch/src/main/java/group/rxcloud/vrml/stopwatch/metric/StopWatchMetric.java @@ -0,0 +1,13 @@ +package group.rxcloud.vrml.stopwatch.metric; + +import group.rxcloud.vrml.metric.index.MetricIndex; + +/** + * Basic metric for StopWatch + */ +public enum StopWatchMetric implements MetricIndex { + + ID, + TaskName, + RunningTime, +} diff --git a/vrml-switch/README.md b/vrml-switch/README.md index b39c39a..f4bf972 100644 --- a/vrml-switch/README.md +++ b/vrml-switch/README.md @@ -15,7 +15,7 @@ group.rxcloud vrml-switch - 1.1.3 + 1.1.4 ``` @@ -91,7 +91,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-switch - 1.1.3 + 1.1.4 ``` diff --git a/vrml-switch/WIKI.md b/vrml-switch/WIKI.md index 1cd6624..188ccb0 100644 --- a/vrml-switch/WIKI.md +++ b/vrml-switch/WIKI.md @@ -76,7 +76,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-switch - 1.1.3 + 1.1.4 ``` diff --git a/vrml-switch/pom.xml b/vrml-switch/pom.xml index 1b8e321..58767dc 100644 --- a/vrml-switch/pom.xml +++ b/vrml-switch/pom.xml @@ -7,7 +7,7 @@ group.rxcloud vrml - 1.1.3 + 1.1.4 vrml-switch diff --git a/vrml-switch/src/main/java/group/rxcloud/vrml/switches/Switches.java b/vrml-switch/src/main/java/group/rxcloud/vrml/switches/Switches.java index 2f351b9..af3573c 100644 --- a/vrml-switch/src/main/java/group/rxcloud/vrml/switches/Switches.java +++ b/vrml-switch/src/main/java/group/rxcloud/vrml/switches/Switches.java @@ -64,11 +64,9 @@ public boolean getSwitch(SwitchKey switchKey) { if (CollectionUtils.isEmpty(sortedKeys)) { return false; } - if (sortedKeys.size() > 1) { - throw new IllegalArgumentException("Switches only support 1 param now"); - } return getConfiguration() - .checkSwitches(sortedKeys); + .checkSwitches(sortedKeys) + .orElse(false); } @Override diff --git a/vrml-switch/src/main/java/group/rxcloud/vrml/switches/SwitchesConfiguration.java b/vrml-switch/src/main/java/group/rxcloud/vrml/switches/SwitchesConfiguration.java index 215c0ae..c6e2fe8 100644 --- a/vrml-switch/src/main/java/group/rxcloud/vrml/switches/SwitchesConfiguration.java +++ b/vrml-switch/src/main/java/group/rxcloud/vrml/switches/SwitchesConfiguration.java @@ -1,14 +1,39 @@ package group.rxcloud.vrml.switches; +import com.google.gson.Gson; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import group.rxcloud.vrml.core.serialization.Serialization; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; /** * The Switches configuration. */ public interface SwitchesConfiguration { + /** + * Logger + */ + Logger log = LoggerFactory.getLogger(SwitchesConfiguration.class); + + /** + * Static default GSON parser + */ + Gson GSON = new Gson(); + + /** + * Same string, return cache parsed json object + */ + Map STRING_JSON_OBJECT_MAP = new ConcurrentHashMap<>(); + /** * Gets params as {@code Json} obj. * @@ -16,11 +41,61 @@ public interface SwitchesConfiguration { */ JsonObject getParams(); + /** + * Convert JsonObject From string with cache + */ + default JsonObject convertToParamsFromString(String params) { + if (!StringUtils.hasLength(params)) { + return null; + } + return STRING_JSON_OBJECT_MAP.computeIfAbsent(params, + str -> GSON.fromJson(str, JsonObject.class)); + } + /** * Check switches. * * @param switchKeys the switch keys * @return the result */ - boolean checkSwitches(List switchKeys); + default Optional checkSwitches(List switchKeys) { + if (CollectionUtils.isEmpty(switchKeys)) { + return Optional.of(false); + } + + JsonObject currentObj = this.getParams(); + if (currentObj == null) { + return Optional.empty(); + } + + for (int i = 0; i < switchKeys.size(); i++) { + String key = switchKeys.get(i); + + // final key must be boolean + boolean finalKey = (i == switchKeys.size() - 1); + + if (currentObj.has(key)) { + JsonElement value = currentObj.get(key); + // iterator + if (value.isJsonObject()) { + currentObj = value.getAsJsonObject(); + } else { + // final key must be boolean + if (finalKey) { + try { + return Optional.of(value.getAsBoolean()); + } catch (Exception e) { + log.error("[SwitchesConfiguration.checkSwitches] get switchKeys[{}] from params[{}] error", + Serialization.toJsonSafe(switchKeys), Serialization.toJsonSafe(this.getParams()), e); + } + } + + return Optional.empty(); + } + } else { + return Optional.empty(); + } + } + return Optional.empty(); + } } diff --git a/vrml-switch/src/test/java/group/rxcloud/vrml/switches/SwitchesTest.java b/vrml-switch/src/test/java/group/rxcloud/vrml/switches/SwitchesTest.java index c2fcfd7..230a39e 100644 --- a/vrml-switch/src/test/java/group/rxcloud/vrml/switches/SwitchesTest.java +++ b/vrml-switch/src/test/java/group/rxcloud/vrml/switches/SwitchesTest.java @@ -1,17 +1,14 @@ package group.rxcloud.vrml.switches; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; import org.junit.Test; import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; import java.util.Collections; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * The Switches API test. @@ -56,14 +53,49 @@ public List getSortedKeys() { public void getSwitch_Obj() { Switches.configuration = new TestSwitchesConfiguration(); - Switches.SwitchKey switchKey = Switches.SwitchKeyBuilder.builder() - .next("test1") - .next("test2") - .next("test3") - .build(); - try { - Switches.INS.getSwitch(switchKey); - } catch (IllegalArgumentException e) { + { + Switches.SwitchKey switchKey1 = Switches.SwitchKeyBuilder.builder() + .next("test1") + .build(); + + boolean value1 = Switches.INS.getSwitch(switchKey1); + assertTrue(value1); + } + { + Switches.SwitchKey switchKey1 = Switches.SwitchKeyBuilder.builder() + .next("test2") + .next("test3") + .next("test4") + .build(); + + boolean value1 = Switches.INS.getSwitch(switchKey1); + assertTrue(value1); + } + { + Switches.SwitchKey switchKey1 = Switches.SwitchKeyBuilder.builder() + .next("test2") + .build(); + + boolean value1 = Switches.INS.getSwitch(switchKey1); + assertFalse(value1); + } + { + Switches.SwitchKey switchKey1 = Switches.SwitchKeyBuilder.builder() + .next("test2") + .next("test3") + .build(); + + boolean value1 = Switches.INS.getSwitch(switchKey1); + assertFalse(value1); + } + { + Switches.SwitchKey switchKey1 = Switches.SwitchKeyBuilder.builder() + .next("test5") + .next("test6") + .build(); + + boolean value1 = Switches.INS.getSwitch(switchKey1); + assertFalse(value1); } } @@ -78,22 +110,12 @@ public JsonObject getParams() { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("test1", true); jsonObject.addProperty("test", true); + JsonObject value3 = new JsonObject(); + value3.addProperty("test4", true); + JsonObject value2 = new JsonObject(); + value2.add("test3", value3); + jsonObject.add("test2", value2); return jsonObject; } - - @Override - public boolean checkSwitches(List switchKeys) { - if (CollectionUtils.isEmpty(switchKeys)) { - return false; - } - JsonObject params = getParams(); - for (String switchKey : switchKeys) { - JsonElement jsonElement = params.get(switchKey); - if (jsonElement != null) { - return jsonElement.getAsBoolean(); - } - } - return false; - } } } \ No newline at end of file diff --git a/vrml-time/README.md b/vrml-time/README.md index a476519..b36c3d7 100644 --- a/vrml-time/README.md +++ b/vrml-time/README.md @@ -12,7 +12,7 @@ A time API with timezone/cron for [vrml](https://github.com/kevinten10/vrml) lib group.rxcloud vrml-time - 1.1.3 + 1.1.4 ``` @@ -74,7 +74,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-time - 1.1.3 + 1.1.4 ``` diff --git a/vrml-time/README_ZH.md b/vrml-time/README_ZH.md index 9d64587..2749a7b 100644 --- a/vrml-time/README_ZH.md +++ b/vrml-time/README_ZH.md @@ -12,7 +12,7 @@ group.rxcloud vrml-time - 1.1.3 + 1.1.4 ``` @@ -78,7 +78,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-time - 1.1.3 + 1.1.4 ``` diff --git a/vrml-time/WIKI.md b/vrml-time/WIKI.md index 98421e9..4605369 100644 --- a/vrml-time/WIKI.md +++ b/vrml-time/WIKI.md @@ -62,6 +62,6 @@ TimeZone -12 ~ +12 based on UTC. group.rxcloud vrml-time - 1.1.3 + 1.1.4 ``` \ No newline at end of file diff --git a/vrml-time/pom.xml b/vrml-time/pom.xml index 5b8b915..a64cd21 100644 --- a/vrml-time/pom.xml +++ b/vrml-time/pom.xml @@ -7,7 +7,7 @@ group.rxcloud vrml - 1.1.3 + 1.1.4 vrml-time diff --git a/vrml-tomcat/pom.xml b/vrml-tomcat/pom.xml index 1e54acc..0866130 100644 --- a/vrml-tomcat/pom.xml +++ b/vrml-tomcat/pom.xml @@ -7,7 +7,7 @@ vrml group.rxcloud - 1.1.3 + 1.1.4 vrml-tomcat diff --git a/vrml-trace/README.md b/vrml-trace/README.md index 502b303..1c861b5 100644 --- a/vrml-trace/README.md +++ b/vrml-trace/README.md @@ -12,7 +12,7 @@ A tracing Api base on MDC for [vrml](https://github.com/kevinten10/vrml) library group.rxcloud vrml-trace - 1.1.3 + 1.1.4 ``` @@ -146,7 +146,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-trace - 1.1.3 + 1.1.4 ``` diff --git a/vrml-trace/README_ZH.md b/vrml-trace/README_ZH.md index 60dd03d..5179cc9 100644 --- a/vrml-trace/README_ZH.md +++ b/vrml-trace/README_ZH.md @@ -12,7 +12,7 @@ group.rxcloud vrml-trace - 1.1.3 + 1.1.4 ``` @@ -146,7 +146,7 @@ Developer repository can be found [here](https://github.com/kevinten10/vrml/tree group.rxcloud vrml-trace - 1.1.3 + 1.1.4 ``` diff --git a/vrml-trace/WIKI.md b/vrml-trace/WIKI.md index fb13f4f..8aef7fa 100644 --- a/vrml-trace/WIKI.md +++ b/vrml-trace/WIKI.md @@ -84,6 +84,6 @@ TraceAPI可以使用`MdcTraces`管理MDC,从而基于MDC进行日志的Tag管 group.rxcloud vrml-trace - 1.1.3 + 1.1.4 ``` \ No newline at end of file diff --git a/vrml-trace/pom.xml b/vrml-trace/pom.xml index 8bdb2a1..68e8386 100644 --- a/vrml-trace/pom.xml +++ b/vrml-trace/pom.xml @@ -7,7 +7,7 @@ group.rxcloud vrml - 1.1.3 + 1.1.4 vrml-trace