From 68ab187c668b58c2eea4b99666bc25e926481480 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Tue, 23 Apr 2024 16:36:46 +0800 Subject: [PATCH] WIP --- README.md | 4 ++-- cffu-core/src/main/java/io/foldright/cffu/Cffu.java | 10 +++++----- .../src/test/java/io/foldright/cffu/CffuTest.java | 8 ++++---- .../src/test/java/io/foldright/test_utils/TestUtils.kt | 4 ++-- .../cffu/kotlin/CompletableFutureExtensions.kt | 2 +- .../cffu/test/CompletableFutureExtensionsTest.kt | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index a247dba1..50e5e1c6 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ - `anyOfSuccess`方法:返回首个成功的`CF`结果,而不是首个完成(但可能失败)的`CF`(`anyOf`) - 更安全的使用方式,如 - 支持设置缺省的业务线程池(`CffuFactoryBuilder#newCffuFactoryBuilder(executor)`方法) - - `cffuJoin(timeout, unit)`方法:支持超时的`join`的方法 + - `join(timeout, unit)`方法:支持超时的`join`的方法 - 支持禁止强制篡改(`CffuFactoryBuilder#forbidObtrudeMethods`方法) - 在类方法附加完善的代码质量注解(如`@NonNull`、`@Nullable`、`@CheckReturnValue`、`@Contract`等),在编码时`IDE`能尽早提示出问题 - 💪 **已有功能的增强**,如 @@ -498,7 +498,7 @@ public class ConcurrencyStrategyDemo { - 主业务逻辑阻塞,没有机会做相应的处理,以及时响应用户 - 会费掉一个线程,线程是很有限的资源(一般几百个),耗尽线程意味着服务瘫痪故障 -`cffuJoin(timeout, unit)`方法即支持超时的`join`的方法;就像`cf.get(timeout, unit)` 之于 `cf.get()`。 +`join(timeout, unit)`方法即支持超时的`join`的方法;就像`cf.get(timeout, unit)` 之于 `cf.get()`。 这个新方法使用简单类似,不附代码示例。 diff --git a/cffu-core/src/main/java/io/foldright/cffu/Cffu.java b/cffu-core/src/main/java/io/foldright/cffu/Cffu.java index d5a8bca7..00327d67 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/Cffu.java +++ b/cffu-core/src/main/java/io/foldright/cffu/Cffu.java @@ -1261,7 +1261,7 @@ public Cffu handleAsync( * @throws ExecutionException if the computation threw an exception * @throws InterruptedException if the current thread was interrupted while waiting * @see #join() - * @see #cffuJoin(long, TimeUnit) + * @see #join(long, TimeUnit) * @see #getNow(Object) * @see #resultNow() * @see #get(long, TimeUnit) @@ -1286,7 +1286,7 @@ public T get() throws InterruptedException, ExecutionException { * @throws ExecutionException if the computation threw an exception * @throws InterruptedException if the current thread was interrupted while waiting * @throws TimeoutException if the wait timed out - * @see #cffuJoin(long, TimeUnit) + * @see #join(long, TimeUnit) * @see #getNow(Object) * @see #resultNow() * @see #join() @@ -1312,7 +1312,7 @@ public T get(long timeout, TimeUnit unit) throws InterruptedException, Execution * @throws CancellationException if the computation was cancelled * @throws CompletionException if this future completed exceptionally * or a completion computation threw an exception - * @see #cffuJoin(long, TimeUnit) + * @see #join(long, TimeUnit) * @see #getNow(Object) * @see #resultNow() * @see #get(long, TimeUnit) @@ -1363,7 +1363,7 @@ public T join() { */ @Blocking @Nullable - public T cffuJoin(long timeout, TimeUnit unit) { + public T join(long timeout, TimeUnit unit) { checkMinimalStage(); return CompletableFutureUtils.join(cf, timeout, unit); @@ -1379,7 +1379,7 @@ public T cffuJoin(long timeout, TimeUnit unit) { * @throws CompletionException if this future completed exceptionally * or a completion computation threw an exception * @see #resultNow() - * @see #cffuJoin(long, TimeUnit) + * @see #join(long, TimeUnit) * @see #join() * @see #get(long, TimeUnit) * @see #get() diff --git a/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java b/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java index 26514942..3ebdf56a 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java @@ -51,12 +51,12 @@ class CffuTest { @Test void test_cffuJoin() { // Completed Future - assertEquals(n, cffuFactory.completedFuture(n).cffuJoin(1, TimeUnit.MILLISECONDS)); + assertEquals(n, cffuFactory.completedFuture(n).join(1, TimeUnit.MILLISECONDS)); // Incomplete Future -> CompletionException with TimeoutException Cffu incomplete = cffuFactory.newIncompleteCffu(); try { - incomplete.cffuJoin(1, TimeUnit.MILLISECONDS); + incomplete.join(1, TimeUnit.MILLISECONDS); fail(); } catch (CompletionException expected) { assertEquals(TimeoutException.class, expected.getCause().getClass()); @@ -65,7 +65,7 @@ void test_cffuJoin() { // Failed Future -> CompletionException Cffu failed = cffuFactory.failedFuture(rte); try { - failed.cffuJoin(1, TimeUnit.MILLISECONDS); + failed.join(1, TimeUnit.MILLISECONDS); fail(); } catch (CompletionException expected) { assertSame(rte, expected.getCause()); @@ -77,7 +77,7 @@ void test_cffuJoin() { sleep(300); return 42; }); - assertEquals(42, cffu.cffuJoin(3, TimeUnit.SECONDS)); + assertEquals(42, cffu.join(3, TimeUnit.SECONDS)); } @Test diff --git a/cffu-core/src/test/java/io/foldright/test_utils/TestUtils.kt b/cffu-core/src/test/java/io/foldright/test_utils/TestUtils.kt index 83c1ca27..48fc340e 100644 --- a/cffu-core/src/test/java/io/foldright/test_utils/TestUtils.kt +++ b/cffu-core/src/test/java/io/foldright/test_utils/TestUtils.kt @@ -405,7 +405,7 @@ private fun Cffu.shouldMinCffu(recursive: Boolean = false) { //////////////////////////////////////////////////////////// shouldThrow { - cffuJoin(1, TimeUnit.MILLISECONDS) + join(1, TimeUnit.MILLISECONDS) }.message shouldBe "unsupported because this is a minimal stage" shouldThrow { cffuState() @@ -504,7 +504,7 @@ private fun Cffu.shouldNotMinCffu(recursive: Boolean = false) { // Cffu specified methods //////////////////////////////////////////////////////////// - cffuJoin(1, TimeUnit.MILLISECONDS) + join(1, TimeUnit.MILLISECONDS) cffuState() //# Cffu Re-Config methods diff --git a/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CompletableFutureExtensions.kt b/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CompletableFutureExtensions.kt index a98b303b..bdd565ad 100644 --- a/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CompletableFutureExtensions.kt +++ b/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CompletableFutureExtensions.kt @@ -587,7 +587,7 @@ fun CompletableFuture.cffuExceptionallyComposeAsync( * @see CompletableFuture.join */ @Suppress("UNCHECKED_CAST") -fun CompletableFuture.cffuJoin(timeout: Long, unit: TimeUnit): T = +fun CompletableFuture.join(timeout: Long, unit: TimeUnit): T = CompletableFutureUtils.join(this, timeout, unit) as T /** diff --git a/cffu-kotlin/src/test/java/io/foldright/cffu/test/CompletableFutureExtensionsTest.kt b/cffu-kotlin/src/test/java/io/foldright/cffu/test/CompletableFutureExtensionsTest.kt index 56e11f7c..1af93fbf 100644 --- a/cffu-kotlin/src/test/java/io/foldright/cffu/test/CompletableFutureExtensionsTest.kt +++ b/cffu-kotlin/src/test/java/io/foldright/cffu/test/CompletableFutureExtensionsTest.kt @@ -296,7 +296,7 @@ class CompletableFutureExtensionsTest : FunSpec({ val cf = CompletableFuture.completedFuture(n) val ff = CompletableFutureUtils.failedFuture(rte) - cf.cffuJoin(1, TimeUnit.MILLISECONDS) shouldBe n + cf.join(1, TimeUnit.MILLISECONDS) shouldBe n cf.cffuResultNow() shouldBe n ff.cffuExceptionNow() shouldBeSameInstanceAs rte