From 21c04e53719eb99e268214c6ed89a6c29252e882 Mon Sep 17 00:00:00 2001 From: wanggq Date: Wed, 9 Nov 2022 16:37:55 +0800 Subject: [PATCH 1/3] fix #365 support async execute api. --- .../register/AbstractComponentExecutor.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/cola-components/cola-component-extension-starter/src/main/java/com/alibaba/cola/extension/register/AbstractComponentExecutor.java b/cola-components/cola-component-extension-starter/src/main/java/com/alibaba/cola/extension/register/AbstractComponentExecutor.java index a766a3f93..c43262d73 100644 --- a/cola-components/cola-component-extension-starter/src/main/java/com/alibaba/cola/extension/register/AbstractComponentExecutor.java +++ b/cola-components/cola-component-extension-starter/src/main/java/com/alibaba/cola/extension/register/AbstractComponentExecutor.java @@ -3,6 +3,10 @@ import com.alibaba.cola.extension.BizScenario; import com.alibaba.cola.extension.ExtensionCoordinate; +import java.util.Objects; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; +import java.util.concurrent.ForkJoinPool; import java.util.function.Consumer; import java.util.function.Function; @@ -31,6 +35,26 @@ public R execute(ExtensionCoordinate extensionCoordinate, Function return execute((Class) extensionCoordinate.getExtensionPointClass(), extensionCoordinate.getBizScenario(), exeFunction); } + public CompletableFuture executeAsync(Class targetClz, BizScenario bizScenario, Function exeFunction) { + return executeAsync(targetClz, bizScenario, exeFunction, null); + } + + /** + * the async execute api. if the param {executor} is null, will use forkJoin pool + * other similar. + */ + public CompletableFuture executeAsync(Class targetClz, BizScenario bizScenario, Function exeFunction, Executor executor) { + return CompletableFuture.supplyAsync(() -> execute(targetClz, bizScenario, exeFunction), Objects.nonNull(executor) ? executor : ForkJoinPool.commonPool()); + } + + public CompletableFuture executeAsync(ExtensionCoordinate extensionCoordinate, Function exeFunction) { + return executeAsync(extensionCoordinate, exeFunction, null); + } + + public CompletableFuture executeAsync(ExtensionCoordinate extensionCoordinate, Function exeFunction, Executor executor) { + return CompletableFuture.supplyAsync(() -> execute(extensionCoordinate, exeFunction), Objects.nonNull(executor) ? executor : ForkJoinPool.commonPool()); + } + /** * Execute extension without Response * @@ -48,5 +72,21 @@ public void executeVoid(ExtensionCoordinate extensionCoordinate, Consumer executeVoid(extensionCoordinate.getExtensionPointClass(), extensionCoordinate.getBizScenario(), exeFunction); } + public void executeVoidAsync(Class targetClz, BizScenario context, Consumer exeFunction) { + executeVoidAsync(targetClz, context, exeFunction, null); + } + + public void executeVoidAsync(Class targetClz, BizScenario context, Consumer exeFunction, Executor executor) { + CompletableFuture.runAsync(() -> executeVoid(targetClz, context, exeFunction), Objects.nonNull(executor) ? executor : ForkJoinPool.commonPool()); + } + + public void executeVoidAsync(ExtensionCoordinate extensionCoordinate, Consumer exeFunction) { + executeVoidAsync(extensionCoordinate, exeFunction, null); + } + + public void executeVoidAsync(ExtensionCoordinate extensionCoordinate, Consumer exeFunction, Executor executor) { + CompletableFuture.runAsync(() -> executeVoid(extensionCoordinate, exeFunction), Objects.nonNull(executor) ? executor : ForkJoinPool.commonPool()); + } + protected abstract C locateComponent(Class targetClz, BizScenario context); } From 874272f1da1798f1d81dfb86516fdb477f173c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E4=B9=9F?= Date: Thu, 15 Sep 2022 13:52:03 +0800 Subject: [PATCH 2/3] =?UTF-8?q?[FEATURE]:[=E7=BB=99=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=9C=BA=E6=8F=90=E4=BE=9B=E4=B8=80=E4=BA=9B=E6=96=B0=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=8E=A5=E5=8F=A3]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 增加com.alibaba.cola.statemachine.StateMachine#verify方法 用来判断当前状态能否响应某个事件 2. 增加com.alibaba.cola.statemachine.builder.StateMachineBuilder#setFailoverCallback 用来增加在状态流转没有命中当前配置的规则时执行的回调 接口定义 com.alibaba.cola.statemachine.builder.FailoverCallback 默认为NumbFailoverCallbackImpl,与当前行为一样,什么都不做。 另外内置AlertFailoverCallbackImpl,用于抛出异常TransitionFailoverException --- cola-components/cola-component-statemachine/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/cola-components/cola-component-statemachine/pom.xml b/cola-components/cola-component-statemachine/pom.xml index 80ab78521..0a174b47d 100644 --- a/cola-components/cola-component-statemachine/pom.xml +++ b/cola-components/cola-component-statemachine/pom.xml @@ -8,6 +8,7 @@ cola-component-statemachine + 4.4.1-SNAPSHOT jar ${project.artifactId} ${project.artifactId} From aa6f5c0133c92c0bc4fc916a81f882441288352e Mon Sep 17 00:00:00 2001 From: wanggq Date: Mon, 6 May 2024 18:31:40 +0800 Subject: [PATCH 3/3] bugfix: #490 --- .../register/ExtensionBootstrap.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/cola-components/cola-component-extension-starter/src/main/java/com/alibaba/cola/extension/register/ExtensionBootstrap.java b/cola-components/cola-component-extension-starter/src/main/java/com/alibaba/cola/extension/register/ExtensionBootstrap.java index d82083eb2..56735ceae 100644 --- a/cola-components/cola-component-extension-starter/src/main/java/com/alibaba/cola/extension/register/ExtensionBootstrap.java +++ b/cola-components/cola-component-extension-starter/src/main/java/com/alibaba/cola/extension/register/ExtensionBootstrap.java @@ -3,6 +3,7 @@ import com.alibaba.cola.extension.Extension; import com.alibaba.cola.extension.ExtensionPointI; import com.alibaba.cola.extension.Extensions; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; @@ -18,6 +19,7 @@ * @author Frank Zhang * @date 2020-06-18 7:55 PM */ +@Slf4j @Component public class ExtensionBootstrap implements ApplicationContextAware { @@ -28,14 +30,16 @@ public class ExtensionBootstrap implements ApplicationContextAware { @PostConstruct public void init(){ - Map extensionBeans = applicationContext.getBeansWithAnnotation(Extension.class); - extensionBeans.values().forEach( - extension -> extensionRegister.doRegistration((ExtensionPointI) extension) - ); - - // handle @Extensions annotation - Map extensionsBeans = applicationContext.getBeansWithAnnotation(Extensions.class); - extensionsBeans.values().forEach( extension -> extensionRegister.doRegistrationExtensions((ExtensionPointI) extension)); + Map extMap = applicationContext.getBeansOfType(ExtensionPointI.class); + for (ExtensionPointI ext : extMap.values()) { + if (ext.getClass().isAnnotationPresent(Extension.class)) { + extensionRegister.doRegistration(ext); + }else if (ext.getClass().isAnnotationPresent(Extensions.class)){ + extensionRegister.doRegistrationExtensions(ext); + }else { + log.error("There is no annotation for @Extension or @Extension on this extension class:{}" , ext.getClass()); + } + } } @Override