From 711f633376eb7c70977f312268abda80f7cff052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=84=9E?= Date: Mon, 22 Apr 2024 10:07:06 +0800 Subject: [PATCH 1/4] [maven-release-plugin] prepare release rx-2.20.1 --- pom.xml | 4 ++-- rxlib-x/pom.xml | 5 ++--- rxlib/pom.xml | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 1bd39f69..b47c46b2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.github.rockylomo rx - 2.20.1-SNAPSHOT + 2.20.1 pom @@ -32,7 +32,7 @@ https://github.com/RockyLOMO/rxlib scm:git:https://github.com/RockyLOMO/rxlib.git scm:git:https://github.com/RockyLOMO/rxlib.git - HEAD + rx-2.20.1 com.github.rockylomo diff --git a/rxlib-x/pom.xml b/rxlib-x/pom.xml index 42ac9cd4..524a0211 100644 --- a/rxlib-x/pom.xml +++ b/rxlib-x/pom.xml @@ -1,11 +1,10 @@ - + 4.0.0 com.github.rockylomo rx - 2.20.1-SNAPSHOT + 2.20.1 rxlib-x jar diff --git a/rxlib/pom.xml b/rxlib/pom.xml index 5c95a05d..ba856e7a 100644 --- a/rxlib/pom.xml +++ b/rxlib/pom.xml @@ -1,11 +1,10 @@ - + 4.0.0 com.github.rockylomo rx - 2.20.1-SNAPSHOT + 2.20.1 rxlib From a73f6825d9acfd03f057c7f5657d4bad48fbb4f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=84=9E?= Date: Mon, 22 Apr 2024 10:07:13 +0800 Subject: [PATCH 2/4] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- rxlib-x/pom.xml | 2 +- rxlib/pom.xml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index b47c46b2..44bfa2ad 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.github.rockylomo rx - 2.20.1 + 2.20.2-SNAPSHOT pom @@ -32,7 +32,7 @@ https://github.com/RockyLOMO/rxlib scm:git:https://github.com/RockyLOMO/rxlib.git scm:git:https://github.com/RockyLOMO/rxlib.git - rx-2.20.1 + HEAD com.github.rockylomo diff --git a/rxlib-x/pom.xml b/rxlib-x/pom.xml index 524a0211..0cda9e9b 100644 --- a/rxlib-x/pom.xml +++ b/rxlib-x/pom.xml @@ -4,7 +4,7 @@ com.github.rockylomo rx - 2.20.1 + 2.20.2-SNAPSHOT rxlib-x jar diff --git a/rxlib/pom.xml b/rxlib/pom.xml index ba856e7a..e2e99eff 100644 --- a/rxlib/pom.xml +++ b/rxlib/pom.xml @@ -4,7 +4,7 @@ com.github.rockylomo rx - 2.20.1 + 2.20.2-SNAPSHOT rxlib From ea09a699a24cf5350c90100d4e2db2a07bd024e9 Mon Sep 17 00:00:00 2001 From: wxm <115806199+youfanx@users.noreply.github.com> Date: Mon, 22 Apr 2024 14:00:30 +0800 Subject: [PATCH 3/4] up --- .../src/main/java/org/rx/redis/RedisUtil.java | 19 +++++++-- rxlib/src/main/java/org/rx/core/Sys.java | 42 ++++++++++++------- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/rxlib-x/src/main/java/org/rx/redis/RedisUtil.java b/rxlib-x/src/main/java/org/rx/redis/RedisUtil.java index 810f07be..6484adc4 100644 --- a/rxlib-x/src/main/java/org/rx/redis/RedisUtil.java +++ b/rxlib-x/src/main/java/org/rx/redis/RedisUtil.java @@ -1,8 +1,10 @@ package org.rx.redis; import com.google.common.util.concurrent.RateLimiter; +import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; import org.rx.core.Cache; import org.rx.core.Strings; import org.rx.core.Sys; @@ -14,6 +16,15 @@ @Slf4j public class RedisUtil { + public static Lock wrapLock(@NonNull RedissonClient redissonClient, @NonNull String lockName) { + return Sys.fallbackProxy(Lock.class, new Lazy<>(() -> redissonClient.getLock(lockName)), new Lazy<>(ReentrantLock::new), e -> { + if (Strings.hashEquals(e.getMethod().getName(), "unlock")) { + return null; + } + throw e; + }); + } + public static Lock wrapLock(RLock rLock) { return Sys.fallbackProxy(Lock.class, rLock, new Lazy<>(ReentrantLock::new), e -> { if (Strings.hashEquals(e.getMethod().getName(), "unlock")) { @@ -24,14 +35,14 @@ public static Lock wrapLock(RLock rLock) { }); } - public static Cache wrapCache(RedisCache rCache) { - return Sys.fallbackProxy(Cache.class, rCache, new Lazy<>(() -> Cache.getInstance(MemoryCache.class))); - } - public static RateLimiterAdapter wrapRateLimiter(RedisRateLimiter rRateLimiter) { return Sys.fallbackProxy(RateLimiterAdapter.class, rRateLimiter, new Lazy<>(() -> { RateLimiter limiter = RateLimiter.create(rRateLimiter.getPermitsPerSecond()); return () -> limiter.tryAcquire(); })); } + + public static Cache wrapCache(RedisCache rCache) { + return Sys.fallbackProxy(Cache.class, rCache, new Lazy<>(() -> Cache.getInstance(MemoryCache.class))); + } } diff --git a/rxlib/src/main/java/org/rx/core/Sys.java b/rxlib/src/main/java/org/rx/core/Sys.java index 44dbd047..9f41e97b 100644 --- a/rxlib/src/main/java/org/rx/core/Sys.java +++ b/rxlib/src/main/java/org/rx/core/Sys.java @@ -273,29 +273,39 @@ public static File getJarFile(Class klass) { return new File(path); } + public static T fallbackProxy(Class targetType, Lazy target, Lazy fallbackTarget) { + return fallbackProxy(targetType, target, fallbackTarget, null); + } + + public static T fallbackProxy(@NonNull Class targetType, Lazy target, Lazy fallbackTarget, BiFunc onError) { + return proxy(targetType, (m, p) -> innerFallbackProxy(m, p, target.getValue(), fallbackTarget, onError)); + } + public static T fallbackProxy(Class targetType, T target, Lazy fallbackTarget) { return fallbackProxy(targetType, target, fallbackTarget, null); } - public static T fallbackProxy(@NonNull Class targetType, @NonNull T target, @NonNull Lazy fallbackTarget, BiFunc onError) { - return proxy(targetType, (m, p) -> { + public static T fallbackProxy(@NonNull Class targetType, T target, Lazy fallbackTarget, BiFunc onError) { + return proxy(targetType, (m, p) -> innerFallbackProxy(m, p, target, fallbackTarget, onError)); + } + + static Object innerFallbackProxy(Method m, DynamicProxyBean p, @NonNull T target, @NonNull Lazy fallbackTarget, BiFunc onError) { + try { + return p.fastInvoke(target); + } catch (Throwable e) { + T fallbackTargetValue = fallbackTarget.getValue(); try { - return p.fastInvoke(target); - } catch (Throwable e) { - T value = fallbackTarget.getValue(); - try { - Object r = p.fastInvoke(value); - log.warn("fallbackProxy", e); - return r; - } catch (Throwable fe) { - FallbackException fb = new FallbackException(m, p, target, value, e, fe); - if (onError == null) { - throw fb; - } - return onError.invoke(fb); + Object r = p.fastInvoke(fallbackTargetValue); + log.warn("fallbackProxy", e); + return r; + } catch (Throwable fe) { + FallbackException fb = new FallbackException(m, p, target, fallbackTargetValue, e, fe); + if (onError == null) { + throw fb; } + return onError.apply(fb); } - }); + } } public static T targetObject(Object proxyObject) { From 2050778dad91c96a091da926a3a1bfffd94415e6 Mon Sep 17 00:00:00 2001 From: wxm <115806199+youfanx@users.noreply.github.com> Date: Mon, 22 Apr 2024 14:06:37 +0800 Subject: [PATCH 4/4] Update Helper.java --- rxlib-x/src/main/java/org/rx/util/Helper.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rxlib-x/src/main/java/org/rx/util/Helper.java b/rxlib-x/src/main/java/org/rx/util/Helper.java index df958d4e..dab47860 100644 --- a/rxlib-x/src/main/java/org/rx/util/Helper.java +++ b/rxlib-x/src/main/java/org/rx/util/Helper.java @@ -144,14 +144,14 @@ public static Map> readExcel(InputStream in, boolean is20 return data; } - public static void writeExcel(OutputStream out, boolean is2003File, Map> data) { - writeExcel(out, is2003File, data, null); + public static void writeExcel(OutputStream out, boolean is2003File, Iterable sheetRows) { + writeExcel(out, is2003File, Collections.singletonMap("sheet1", sheetRows), null); } @SneakyThrows - public static void writeExcel(OutputStream out, boolean is2003File, Map> data, Function onRow) { + public static void writeExcel(OutputStream out, boolean is2003File, Map> sheets, Function onRow) { try (Workbook workbook = is2003File ? new HSSFWorkbook() : new XSSFWorkbook()) { - for (Map.Entry> entry : data.entrySet()) { + for (Map.Entry> entry : sheets.entrySet()) { Sheet sheet = workbook.getSheet(entry.getKey()); if (sheet == null) { sheet = workbook.createSheet(entry.getKey());