diff --git a/README.md b/README.md index 71dcbe99..4440de8c 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ - `allOfFastFail`方法:有`CF`失败时快速返回,而不再等待所有`CF`运行完成(`allOf`) - `anyOfSuccess`方法:返回首个成功的`CF`结果,而不是首个完成(但可能失败)的`CF`(`anyOf`) - 更安全的使用方式,如 - - 支持设置缺省的业务线程池(`CffuFactoryBuilder#newCffuFactoryBuilder(executor)`方法) + - 支持设置缺省的业务线程池(`CffuFactory#builder(executor)`方法) - `join(timeout, unit)`方法:支持超时的`join`的方法 - 支持禁止强制篡改(`CffuFactoryBuilder#forbidObtrudeMethods`方法) - 在类方法附加完善的代码质量注解(如`@NonNull`、`@Nullable`、`@CheckReturnValue`、`@Contract`等),在编码时`IDE`能尽早提示出问题 @@ -148,7 +148,7 @@ public class CffuDemo { private static final ExecutorService myBizThreadPool = Executors.newCachedThreadPool(); // Create a CffuFactory with configuration of the customized thread pool - private static final CffuFactory cffuFactory = newCffuFactoryBuilder(myBizThreadPool).build(); + private static final CffuFactory cffuFactory = CffuFactory.builder(myBizThreadPool).build(); public static void main(String[] args) throws Exception { final Cffu cf42 = cffuFactory @@ -232,7 +232,7 @@ public class CompletableFutureUtilsDemo { private val myBizThreadPool: ExecutorService = Executors.newCachedThreadPool() // Create a CffuFactory with configuration of the customized thread pool -private val cffuFactory: CffuFactory = newCffuFactoryBuilder(myBizThreadPool).build() +private val cffuFactory: CffuFactory = CffuFactory.builder(myBizThreadPool).build() fun main() { val cf42 = cffuFactory @@ -282,7 +282,7 @@ fun main() { ```java public class AllResultsOfDemo { public static final Executor myBizExecutor = Executors.newCachedThreadPool(); - public static final CffuFactory cffuFactory = newCffuFactoryBuilder(myBizExecutor).build(); + public static final CffuFactory cffuFactory = CffuFactory.builder(myBizExecutor).build(); public static void main(String[] args) throws Exception { ////////////////////////////////////////////////// @@ -324,7 +324,7 @@ public class AllResultsOfDemo { ```java public class AllTupleOfDemo { public static final Executor myBizExecutor = Executors.newCachedThreadPool(); - public static final CffuFactory cffuFactory = newCffuFactoryBuilder(myBizExecutor).build(); + public static final CffuFactory cffuFactory = CffuFactory.builder(myBizExecutor).build(); public static void main(String[] args) throws Exception { ////////////////////////////////////////////////// @@ -393,7 +393,7 @@ public class NoDefaultExecutorSettingForCompletableFuture { ```java public class DefaultExecutorSettingForCffu { public static final Executor myBizExecutor = Executors.newCachedThreadPool(); - public static final CffuFactory cffuFactory = newCffuFactoryBuilder(myBizExecutor).build(); + public static final CffuFactory cffuFactory = CffuFactory.builder(myBizExecutor).build(); public static void main(String[] args) { Cffu cf1 = cffuFactory.runAsync(() -> System.out.println("doing a long time work!")); @@ -439,7 +439,7 @@ public class DefaultExecutorSettingForCffu { ```java public class ConcurrencyStrategyDemo { public static final Executor myBizExecutor = Executors.newCachedThreadPool(); - public static final CffuFactory cffuFactory = newCffuFactoryBuilder(myBizExecutor).build(); + public static final CffuFactory cffuFactory = CffuFactory.builder(myBizExecutor).build(); public static void main(String[] args) throws Exception { //////////////////////////////////////////////////////////////////////// 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 6371311e..c74220aa 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/Cffu.java +++ b/cffu-core/src/main/java/io/foldright/cffu/Cffu.java @@ -1924,7 +1924,7 @@ public Cffu copy() { * * @return the default executor * @see CffuFactory#defaultExecutor() - * @see CffuFactoryBuilder#newCffuFactoryBuilder(Executor) + * @see CffuFactory#builder(Executor) * @see #cffuFactory() */ @Contract(pure = true) diff --git a/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java b/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java index 72ace5f5..fec9c41b 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CffuFactory.java @@ -28,7 +28,7 @@ *

* The methods that equivalent to the instance methods of {@link CompletableFuture} is in {@link Cffu} class. *

- * Use {@link CffuFactoryBuilder} to config and build {@link CffuFactory}. + * Use {@link #builder(Executor)} to config and build {@link CffuFactory}. *

* About factory methods conventions of {@link CffuFactory}: *

    @@ -39,7 +39,6 @@ *
* * @author Jerry Lee (oldratlee at gmail dot com) - * @see CffuFactoryBuilder * @see Cffu * @see CompletableFuture */ @@ -67,6 +66,18 @@ private Cffu newMin(CompletableFuture cf) { return new Cffu<>(this, true, cf); } + /** + * Returns a {@link CffuFactoryBuilder} with {@code defaultExecutor} setting. + * + * @see Cffu#defaultExecutor() + * @see CffuFactory#defaultExecutor() + */ + @Contract(pure = true) + public static CffuFactoryBuilder builder(Executor defaultExecutor) { + Executor executor = CffuFactoryBuilder.wrapExecutor(requireNonNull(defaultExecutor, "defaultExecutor is null")); + return new CffuFactoryBuilder(executor); + } + //////////////////////////////////////////////////////////////////////////////// //# Factory Methods, equivalent to same name static methods of CompletableFuture // @@ -250,7 +261,7 @@ public Cffu newIncompleteCffu() { * NOTE, keep input stage unchanged if possible when wrap:
*
    *
  1. if input stage is a {@link Cffu}, re-wrapped with the config of - * this {@link CffuFactory} from {@link CffuFactoryBuilder} by {@link Cffu#resetCffuFactory(CffuFactory)}. + * this {@link CffuFactory} by {@link Cffu#resetCffuFactory(CffuFactory)}. *
  2. if input stage is a CompletableFuture, wrap it by setting it as the underlying cf of returned cffu. *
  3. otherwise use input {@code stage.toCompletableFuture} as the underlying cf of returned cffu. *
@@ -621,7 +632,7 @@ public Executor delayedExecutor(long delay, TimeUnit unit, Executor executor) { } //////////////////////////////////////////////////////////////////////////////// - //# Conversion (Static) Methods + //# Conversion Methods // // - cffuListToArray: List -> Cffu[] // - completableFutureListToArray: List -> CF[] @@ -659,11 +670,11 @@ public static Cffu[] cffuListToArray(List> cffuList) { /** * Returns the default Executor used for async methods that do not specify an Executor. - * Configured by {@link CffuFactoryBuilder#newCffuFactoryBuilder(Executor)}. + * Configured by {@link CffuFactory#builder(Executor)}. * * @return the default executor * @see Cffu#defaultExecutor() - * @see CffuFactoryBuilder#newCffuFactoryBuilder(Executor) + * @see CffuFactory#builder(Executor) */ @Contract(pure = true) public Executor defaultExecutor() { diff --git a/cffu-core/src/main/java/io/foldright/cffu/CffuFactoryBuilder.java b/cffu-core/src/main/java/io/foldright/cffu/CffuFactoryBuilder.java index f9216325..bef92e14 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CffuFactoryBuilder.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CffuFactoryBuilder.java @@ -18,7 +18,7 @@ /** - * {@link CffuFactoryBuilder} is the builder of {@link CffuFactory}. + * {@link CffuFactoryBuilder} is the builder of {@link CffuFactory}, creates by {@link CffuFactory#builder(Executor)}. * * @author Jerry Lee (oldratlee at gmail dot com) * @see CffuFactory @@ -33,7 +33,7 @@ public final class CffuFactoryBuilder { private volatile boolean forbidObtrudeMethods = false; - private CffuFactoryBuilder(Executor defaultExecutor) { + CffuFactoryBuilder(Executor defaultExecutor) { this.defaultExecutor = defaultExecutor; } @@ -41,18 +41,6 @@ private CffuFactoryBuilder(Executor defaultExecutor) { // Builder Methods //////////////////////////////////////////////////////////////////////////////// - /** - * Returns a {@link CffuFactoryBuilder} with {@code defaultExecutor} setting. - * - * @see CffuFactory#defaultExecutor() - * @see Cffu#defaultExecutor() - */ - @Contract(pure = true) - public static CffuFactoryBuilder newCffuFactoryBuilder(Executor defaultExecutor) { - Executor executor = wrapExecutor(requireNonNull(defaultExecutor, "defaultExecutor is null")); - return new CffuFactoryBuilder(executor); - } - /** * Sets {@code forbidObtrudeMethods} or not. * @@ -75,7 +63,7 @@ public CffuFactory build() { return new CffuFactory(defaultExecutor, forbidObtrudeMethods); } - private static Executor wrapExecutor(Executor executor) { + static Executor wrapExecutor(Executor executor) { for (ExecutorWrapperProvider provider : EXECUTOR_WRAPPER_PROVIDERS) { Supplier msg = () -> provider + "(class: " + provider.getClass().getName() + ") return null"; executor = requireNonNull(provider.wrap(executor), msg); diff --git a/cffu-core/src/main/java/io/foldright/cffu/spi/ExecutorWrapperProvider.java b/cffu-core/src/main/java/io/foldright/cffu/spi/ExecutorWrapperProvider.java index 17675855..67d9e95d 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/spi/ExecutorWrapperProvider.java +++ b/cffu-core/src/main/java/io/foldright/cffu/spi/ExecutorWrapperProvider.java @@ -11,7 +11,7 @@ * An SPI for wrapping the executor when {@link CffuFactoryBuilder} * {@link CffuFactoryBuilder#build() build} {@link CffuFactory}. * - * @see CffuFactoryBuilder#newCffuFactoryBuilder(Executor) + * @see CffuFactory#builder(Executor) * @see CffuFactoryBuilder#build() */ @FunctionalInterface diff --git a/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java b/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java index 5e765860..fcd484a3 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CffuFactoryTest.java @@ -15,7 +15,6 @@ import java.util.Collections; import java.util.concurrent.*; -import static io.foldright.cffu.CffuFactoryBuilder.newCffuFactoryBuilder; import static io.foldright.cffu.CompletableFutureUtils.failedFuture; import static io.foldright.cffu.CompletableFutureUtils.toCompletableFutureArray; import static io.foldright.test_utils.TestUtils.*; @@ -123,7 +122,7 @@ void test_toCffu() throws Exception { assertEquals(n, cf.get()); shouldNotBeMinimalStage(cf); - CffuFactory fac = newCffuFactoryBuilder(anotherExecutorService).forbidObtrudeMethods(true).build(); + CffuFactory fac = CffuFactory.builder(anotherExecutorService).forbidObtrudeMethods(true).build(); Cffu cffu = fac.toCffu(cffuFactory.completedFuture(42)); assertSame(anotherExecutorService, cffu.defaultExecutor()); assertSame(fac, cffu.cffuFactory()); @@ -787,14 +786,14 @@ void test_getter() { assertSame(executorService, cffuFactory.defaultExecutor()); assertFalse(cffuFactory.forbidObtrudeMethods()); - CffuFactory fac = newCffuFactoryBuilder(anotherExecutorService).forbidObtrudeMethods(true).build(); + CffuFactory fac = CffuFactory.builder(anotherExecutorService).forbidObtrudeMethods(true).build(); assertSame(anotherExecutorService, fac.defaultExecutor()); assertTrue(fac.forbidObtrudeMethods()); } @Test void test_forbidObtrudeMethods_property() { - CffuFactory fac2 = newCffuFactoryBuilder(executorService).forbidObtrudeMethods(true).build(); + CffuFactory fac2 = CffuFactory.builder(executorService).forbidObtrudeMethods(true).build(); Cffu cf = fac2.newIncompleteCffu(); try { @@ -813,9 +812,9 @@ void test_forbidObtrudeMethods_property() { @Test void test_executorSetting_MayBe_ThreadPerTaskExecutor() throws Exception { - final boolean USE_COMMON_POOL = (ForkJoinPool.getCommonPoolParallelism() > 1); + final boolean USE_COMMON_POOL = ForkJoinPool.getCommonPoolParallelism() > 1; - CffuFactory fac = newCffuFactoryBuilder(commonPool()).build(); + CffuFactory fac = CffuFactory.builder(commonPool()).build(); if (USE_COMMON_POOL) { assertSame(commonPool(), fac.defaultExecutor()); } else { @@ -841,7 +840,7 @@ static void beforeAll() { executorService = TestThreadPoolManager.createThreadPool("CffuFactoryTest"); anotherExecutorService = TestThreadPoolManager.createThreadPool("CffuFactoryTest-Another", true); - cffuFactory = newCffuFactoryBuilder(executorService).build(); + cffuFactory = CffuFactory.builder(executorService).build(); } @AfterAll 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 9caeb511..bdd6211f 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java +++ b/cffu-core/src/test/java/io/foldright/cffu/CffuTest.java @@ -11,7 +11,6 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; -import static io.foldright.cffu.CffuFactoryBuilder.newCffuFactoryBuilder; import static io.foldright.test_utils.TestUtils.*; import static java.util.function.Function.identity; import static org.junit.jupiter.api.Assertions.*; @@ -310,9 +309,8 @@ void test_toString() { static void beforeAll() { executorService = TestThreadPoolManager.createThreadPool("CffuTest"); - cffuFactory = newCffuFactoryBuilder(executorService).build(); - forbidObtrudeMethodsCffuFactory = newCffuFactoryBuilder(executorService) - .forbidObtrudeMethods(true).build(); + cffuFactory = CffuFactory.builder(executorService).build(); + forbidObtrudeMethodsCffuFactory = CffuFactory.builder(executorService).forbidObtrudeMethods(true).build(); } @AfterAll diff --git a/cffu-core/src/test/java/io/foldright/cffu/spi/ExecutorWrapperProviderTest.kt b/cffu-core/src/test/java/io/foldright/cffu/spi/ExecutorWrapperProviderTest.kt index 599982c5..92ca5379 100644 --- a/cffu-core/src/test/java/io/foldright/cffu/spi/ExecutorWrapperProviderTest.kt +++ b/cffu-core/src/test/java/io/foldright/cffu/spi/ExecutorWrapperProviderTest.kt @@ -1,6 +1,6 @@ package io.foldright.cffu.spi -import io.foldright.cffu.CffuFactoryBuilder +import io.foldright.cffu.CffuFactory import io.foldright.test_utils.testThreadPoolExecutor import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.types.shouldBeSameInstanceAs @@ -8,7 +8,7 @@ import io.kotest.matchers.types.shouldNotBeSameInstanceAs class ExecutorWrapperProviderTest : FunSpec({ test("disable TestExecutorWrapper") { - val factory = CffuFactoryBuilder.newCffuFactoryBuilder(testThreadPoolExecutor).build() + val factory = CffuFactory.builder(testThreadPoolExecutor).build() val cffu = factory.runAsync {} cffu.defaultExecutor().shouldBeSameInstanceAs(testThreadPoolExecutor) } @@ -16,7 +16,7 @@ class ExecutorWrapperProviderTest : FunSpec({ test("enable TestExecutorWrapper") { enableTestExecutorWrapper() - val factory = CffuFactoryBuilder.newCffuFactoryBuilder(testThreadPoolExecutor).build() + val factory = CffuFactory.builder(testThreadPoolExecutor).build() val cffu = factory.runAsync {} cffu.defaultExecutor().shouldNotBeSameInstanceAs(testThreadPoolExecutor) } diff --git a/cffu-core/src/test/java/io/foldright/compatibility_test/CffuApiCompatibilityTest.java b/cffu-core/src/test/java/io/foldright/compatibility_test/CffuApiCompatibilityTest.java index 2b7802aa..ce59fa23 100644 --- a/cffu-core/src/test/java/io/foldright/compatibility_test/CffuApiCompatibilityTest.java +++ b/cffu-core/src/test/java/io/foldright/compatibility_test/CffuApiCompatibilityTest.java @@ -11,7 +11,6 @@ import io.foldright.cffu.Cffu; import io.foldright.cffu.CffuFactory; -import io.foldright.cffu.CffuFactoryBuilder; import io.foldright.test_utils.TestThreadPoolManager; import io.foldright.test_utils.TestUtils; import org.junit.jupiter.api.AfterAll; @@ -881,7 +880,7 @@ private void check1MoreLevelForExecutionException(Cffu cf) throws Excepti @BeforeAll static void beforeAll() { executorService = TestThreadPoolManager.createThreadPool(hello); - cffuFactory = CffuFactoryBuilder.newCffuFactoryBuilder(executorService).build(); + cffuFactory = CffuFactory.builder(executorService).build(); anotherExecutorService = TestThreadPoolManager.createThreadPool(hello, true); } diff --git a/cffu-core/src/test/java/io/foldright/demo/AllResultsOfDemo.java b/cffu-core/src/test/java/io/foldright/demo/AllResultsOfDemo.java index 98cbd781..c5432546 100644 --- a/cffu-core/src/test/java/io/foldright/demo/AllResultsOfDemo.java +++ b/cffu-core/src/test/java/io/foldright/demo/AllResultsOfDemo.java @@ -9,12 +9,10 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import static io.foldright.cffu.CffuFactoryBuilder.newCffuFactoryBuilder; - public class AllResultsOfDemo { public static final ExecutorService myBizExecutor = Executors.newCachedThreadPool(); - public static final CffuFactory cffuFactory = newCffuFactoryBuilder(myBizExecutor).build(); + public static final CffuFactory cffuFactory = CffuFactory.builder(myBizExecutor).build(); public static void main(String[] args) throws Exception { ////////////////////////////////////////////////// diff --git a/cffu-core/src/test/java/io/foldright/demo/AllTupleOfDemo.java b/cffu-core/src/test/java/io/foldright/demo/AllTupleOfDemo.java index 852b7657..1dfa5db8 100644 --- a/cffu-core/src/test/java/io/foldright/demo/AllTupleOfDemo.java +++ b/cffu-core/src/test/java/io/foldright/demo/AllTupleOfDemo.java @@ -9,12 +9,10 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import static io.foldright.cffu.CffuFactoryBuilder.newCffuFactoryBuilder; - public class AllTupleOfDemo { public static final ExecutorService myBizExecutor = Executors.newCachedThreadPool(); - public static final CffuFactory cffuFactory = newCffuFactoryBuilder(myBizExecutor).build(); + public static final CffuFactory cffuFactory = CffuFactory.builder(myBizExecutor).build(); public static void main(String[] args) throws Exception { ////////////////////////////////////////////////// diff --git a/cffu-core/src/test/java/io/foldright/demo/ConcurrencyStrategyDemo.java b/cffu-core/src/test/java/io/foldright/demo/ConcurrencyStrategyDemo.java index 604f87a5..859de757 100644 --- a/cffu-core/src/test/java/io/foldright/demo/ConcurrencyStrategyDemo.java +++ b/cffu-core/src/test/java/io/foldright/demo/ConcurrencyStrategyDemo.java @@ -9,12 +9,10 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import static io.foldright.cffu.CffuFactoryBuilder.newCffuFactoryBuilder; - public class ConcurrencyStrategyDemo { public static final ExecutorService myBizExecutor = Executors.newCachedThreadPool(); - public static final CffuFactory cffuFactory = newCffuFactoryBuilder(myBizExecutor).build(); + public static final CffuFactory cffuFactory = CffuFactory.builder(myBizExecutor).build(); public static void main(String[] args) throws Exception { //////////////////////////////////////////////////////////////////////// diff --git a/cffu-core/src/test/java/io/foldright/demo/DefaultExecutorSettingForCffu.java b/cffu-core/src/test/java/io/foldright/demo/DefaultExecutorSettingForCffu.java index b7f652ae..73de7bfd 100644 --- a/cffu-core/src/test/java/io/foldright/demo/DefaultExecutorSettingForCffu.java +++ b/cffu-core/src/test/java/io/foldright/demo/DefaultExecutorSettingForCffu.java @@ -6,12 +6,10 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import static io.foldright.cffu.CffuFactoryBuilder.newCffuFactoryBuilder; - public class DefaultExecutorSettingForCffu { public static final ExecutorService myBizExecutor = Executors.newCachedThreadPool(); - public static final CffuFactory cffuFactory = newCffuFactoryBuilder(myBizExecutor).build(); + public static final CffuFactory cffuFactory = CffuFactory.builder(myBizExecutor).build(); public static void main(String[] args) { Cffu cf1 = cffuFactory.runAsync(() -> System.out.println("doing a long time work!")); diff --git a/cffu-core/src/test/java/io/foldright/test_utils/TestThreadPoolManager.kt b/cffu-core/src/test/java/io/foldright/test_utils/TestThreadPoolManager.kt index 4b2383ad..af3eb632 100644 --- a/cffu-core/src/test/java/io/foldright/test_utils/TestThreadPoolManager.kt +++ b/cffu-core/src/test/java/io/foldright/test_utils/TestThreadPoolManager.kt @@ -3,7 +3,6 @@ package io.foldright.test_utils import io.foldright.cffu.CffuFactory -import io.foldright.cffu.CffuFactoryBuilder.newCffuFactoryBuilder import io.kotest.core.annotation.AutoScan import io.kotest.core.listeners.AfterProjectListener import io.kotest.core.listeners.BeforeProjectListener @@ -93,7 +92,7 @@ fun shutdownExecutorService(vararg executors: ExecutorService) { val testThreadPoolExecutor: ExecutorService = createThreadPool("CompletableFutureUseTest_ThreadPool") -val testCffuFactory: CffuFactory = newCffuFactoryBuilder(testThreadPoolExecutor).build() +val testCffuFactory: CffuFactory = CffuFactory.builder(testThreadPoolExecutor).build() val testForkJoinPoolExecutor: ExecutorService = createThreadPool("CompletableFutureUseTest_ForkJoinPool", true) 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 181b2e93..7166d652 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 @@ -3,7 +3,7 @@ package io.foldright.test_utils import io.foldright.cffu.Cffu -import io.foldright.cffu.CffuFactoryBuilder.newCffuFactoryBuilder +import io.foldright.cffu.CffuFactory import io.kotest.assertions.throwables.shouldNotThrow import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.test.TestCase @@ -75,7 +75,7 @@ fun safeNewFailedCompletableFuture(executorService: ExecutorService, t: Thro * safe means works under java 8 */ fun safeNewFailedCffu(executorService: ExecutorService, t: Throwable): Cffu { - return newCffuFactoryBuilder(executorService).build().failedFuture(t) + return CffuFactory.builder(executorService).build().failedFuture(t) } @Suppress("UNUSED_PARAMETER") @@ -413,7 +413,7 @@ private fun Cffu.shouldMinCffu(recursive: Boolean = false) { //# Cffu Re-Config methods if (recursive) - resetCffuFactory(newCffuFactoryBuilder(blackHoleExecutor).build()).shouldMinCffu() + resetCffuFactory(CffuFactory.builder(blackHoleExecutor).build()).shouldMinCffu() //# Getter methods of properties cffuFactory() @@ -508,7 +508,7 @@ private fun Cffu.shouldNotMinCffu(recursive: Boolean = false) { //# Cffu Re-Config methods if (recursive) - resetCffuFactory(newCffuFactoryBuilder(blackHoleExecutor).build()).shouldNotMinCffu() + resetCffuFactory(CffuFactory.builder(blackHoleExecutor).build()).shouldNotMinCffu() //# Getter methods of properties cffuFactory() diff --git a/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CffuExtensions.kt b/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CffuExtensions.kt index acc41499..c7b0a734 100644 --- a/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CffuExtensions.kt +++ b/cffu-kotlin/src/main/java/io/foldright/cffu/kotlin/CffuExtensions.kt @@ -2,7 +2,6 @@ package io.foldright.cffu.kotlin import io.foldright.cffu.Cffu import io.foldright.cffu.CffuFactory -import io.foldright.cffu.CffuFactoryBuilder.newCffuFactoryBuilder import io.foldright.cffu.CompletableFutureUtils import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletionStage @@ -62,7 +61,7 @@ fun Array>.toCffu(cffuFactory: CffuFactory): Array) { cffu.cffuFactory() shouldBeSameInstanceAs cffuFactoryForOptional } diff --git a/cffu-ttl-executor-wrapper/src/test/java/io/foldright/cffu/ttl/CffuTtlExecutorWrapperTest.kt b/cffu-ttl-executor-wrapper/src/test/java/io/foldright/cffu/ttl/CffuTtlExecutorWrapperTest.kt index 6fa3f217..1e261bed 100644 --- a/cffu-ttl-executor-wrapper/src/test/java/io/foldright/cffu/ttl/CffuTtlExecutorWrapperTest.kt +++ b/cffu-ttl-executor-wrapper/src/test/java/io/foldright/cffu/ttl/CffuTtlExecutorWrapperTest.kt @@ -1,7 +1,7 @@ package io.foldright.cffu.ttl import com.alibaba.ttl.TransmittableThreadLocal -import io.foldright.cffu.CffuFactoryBuilder +import io.foldright.cffu.CffuFactory import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.booleans.shouldBeTrue import io.kotest.matchers.shouldBe @@ -19,7 +19,7 @@ class CffuTtlExecutorWrapperTest : FunSpec({ val ttl = TransmittableThreadLocal() test("CffuTtlExecutorWrapper") { - val factory = CffuFactoryBuilder.newCffuFactoryBuilder(executorService).build() + val factory = CffuFactory.builder(executorService).build() val v1 = "v1: ${Random.nextULong()}" ttl.set(v1) diff --git a/demos/cffu-demo/src/main/java/io/foldright/demo/cffu/CffuDemo.java b/demos/cffu-demo/src/main/java/io/foldright/demo/cffu/CffuDemo.java index 98330985..e7478e08 100644 --- a/demos/cffu-demo/src/main/java/io/foldright/demo/cffu/CffuDemo.java +++ b/demos/cffu-demo/src/main/java/io/foldright/demo/cffu/CffuDemo.java @@ -7,13 +7,11 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import static io.foldright.cffu.CffuFactoryBuilder.newCffuFactoryBuilder; - public class CffuDemo { private static final ExecutorService myBizThreadPool = Executors.newCachedThreadPool(); // Create a CffuFactory with configuration of the customized thread pool - private static final CffuFactory cffuFactory = newCffuFactoryBuilder(myBizThreadPool).build(); + private static final CffuFactory cffuFactory = CffuFactory.builder(myBizThreadPool).build(); public static void main(String[] args) throws Exception { final Cffu cf42 = cffuFactory diff --git a/demos/cffu-kotlin-demo/src/main/java/io/foldright/demo/cffu/kotlin/CffuDemo.kt b/demos/cffu-kotlin-demo/src/main/java/io/foldright/demo/cffu/kotlin/CffuDemo.kt index 863f9bf3..05af50e3 100644 --- a/demos/cffu-kotlin-demo/src/main/java/io/foldright/demo/cffu/kotlin/CffuDemo.kt +++ b/demos/cffu-kotlin-demo/src/main/java/io/foldright/demo/cffu/kotlin/CffuDemo.kt @@ -2,7 +2,6 @@ package io.foldright.demo.cffu.kotlin import io.foldright.cffu.Cffu import io.foldright.cffu.CffuFactory -import io.foldright.cffu.CffuFactoryBuilder.newCffuFactoryBuilder import io.foldright.cffu.kotlin.anyOfSuccessCffu import java.lang.Thread.sleep import java.util.concurrent.ExecutorService @@ -13,7 +12,7 @@ import java.util.concurrent.TimeUnit private val myBizThreadPool: ExecutorService = Executors.newCachedThreadPool() // Create a CffuFactory with configuration of the customized thread pool -private val cffuFactory: CffuFactory = newCffuFactoryBuilder(myBizThreadPool).build() +private val cffuFactory: CffuFactory = CffuFactory.builder(myBizThreadPool).build() fun main() { val cf42 = cffuFactory diff --git a/scripts/gen_CffuApiCompatibilityTest.sh b/scripts/gen_CffuApiCompatibilityTest.sh index 60f376ea..50ef8f6a 100755 --- a/scripts/gen_CffuApiCompatibilityTest.sh +++ b/scripts/gen_CffuApiCompatibilityTest.sh @@ -14,7 +14,7 @@ sed -r '/^import /,${ /\bGEN_MARK_KEEP\b/b # adjust imports - s/import io\.foldright\.test_utils\.TestThreadPoolManager;/import io.foldright.cffu.Cffu;\nimport io.foldright.cffu.CffuFactory;\nimport io.foldright.cffu.CffuFactoryBuilder;\nimport io.foldright.test_utils.TestThreadPoolManager;/ + s/import io\.foldright\.test_utils\.TestThreadPoolManager;/import io.foldright.cffu.Cffu;\nimport io.foldright.cffu.CffuFactory;\nimport io.foldright.test_utils.TestThreadPoolManager;/ /import java.util.concurrent.CompletableFuture;/d # replace JUnit test class name @@ -36,6 +36,6 @@ sed -r '/^import /,${ # generate new contents s/^(\s*).*\bGEN_MARK_FACTORY_FIELD\b.*$/\1private static CffuFactory cffuFactory;/ - s/^(\s*).*\bGEN_MARK_FACTORY_INIT\b.*$/\1cffuFactory = CffuFactoryBuilder.newCffuFactoryBuilder\(executorService\).build\(\);/ + s/^(\s*).*\bGEN_MARK_FACTORY_INIT\b.*$/\1cffuFactory = CffuFactory.builder\(executorService\).build\(\);/ }' "$source_file" >"$target_file"