初步完成 liteflow-solon-plugin 适配

This commit is contained in:
noear
2022-12-19 11:05:12 +08:00
parent fea977730e
commit ce3600ded7
8 changed files with 48 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
package com.yomahub.liteflow.solon.integration;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.solon.LiteflowProperty;
@@ -8,6 +9,8 @@ import org.noear.solon.Utils;
import org.noear.solon.core.AopContext;
import org.noear.solon.core.Plugin;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
@@ -15,6 +18,9 @@ import java.util.Properties;
* @since 2.9
*/
public class XPluginImpl implements Plugin {
public static Map<String, NodeComponent> nodeComponentMap = new HashMap<>();
@Override
public void start(AopContext context) {
//加载默认配置
@@ -34,17 +40,33 @@ public class XPluginImpl implements Plugin {
//订阅 NodeComponent 组件
context.subWrapsOfType(NodeComponent.class, bw -> {
NodeComponent node1 = bw.raw();
// NodeComponent node1 = bw.raw();
//
// if (Utils.isNotEmpty(bw.name())) {
// node1.setName(bw.name());
// node1.setNodeId(bw.name());
// }
if (Utils.isNotEmpty(bw.name())) {
node1.setName(bw.name());
node1.setNodeId(bw.name());
}
FlowBus.addSpringScanNode(node1.getNodeId(), node1);
nodeComponentMap.put(bw.name(), bw.raw());
//FlowBus.addSpringScanNode(bw.name(), bw.raw());
});
//扫描内部相关组件
context.beanScan(LiteflowProperty.class);
context.beanBuilderAdd(LiteflowComponent.class, (clz, bw, anno) -> {
if(NodeComponent.class.isAssignableFrom(clz)) {
NodeComponent node1 = bw.raw();
String id1 = Utils.annoAlias(anno.id(), anno.value());
String name1 =Utils.annoAlias(anno.name(), id1);
node1.setNodeId(id1);
node1.setName(name1);
FlowBus.addSpringScanNode(node1.getNodeId(), node1);
}
});
//扫描相关组件
context.beanOnloaded((ctx)->{
context.beanScan(LiteflowProperty.class);
});
}
}

View File

@@ -15,7 +15,7 @@ public class SolonCmpAroundAspect implements CmpAroundAspect {
public static ICmpAroundAspect cmpAroundAspect;
static {
Solon.context().getBeanAsyn(ICmpAroundAspect.class, bean -> {
Solon.context().getBeanAsync(ICmpAroundAspect.class, bean -> {
cmpAroundAspect = bean;
});
}

View File

@@ -9,7 +9,7 @@ import org.noear.solon.core.BeanWrap;
* 基于代码形式的 Solon 上下文工具类
* @author Bryan.Zhang
*/
public class SolonAware implements ContextAware {
public class SolonContextAware implements ContextAware {
@Override
public <T> T getBean(String name) {

View File

@@ -1,7 +1,12 @@
package com.yomahub.liteflow.spi.solon;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.flow.FlowBus;
import com.yomahub.liteflow.solon.integration.XPluginImpl;
import com.yomahub.liteflow.spi.ContextCmpInit;
import java.util.Map;
/**
* Solon 环境容器上下文组件初始化实现
@@ -11,7 +16,11 @@ import com.yomahub.liteflow.spi.ContextCmpInit;
public class SolonContextCmpInit implements ContextCmpInit {
@Override
public void initCmp() {
//todo: 转到 FlowBus.addSpringScanNode 不需要了
for (Map.Entry<String, NodeComponent> componentEntry : XPluginImpl.nodeComponentMap.entrySet()) {
if (!FlowBus.containNode(componentEntry.getKey())) {
FlowBus.addSpringScanNode(componentEntry.getKey(), componentEntry.getValue());
}
}
}
@Override

View File

@@ -19,7 +19,7 @@ public class SolonLiteflowComponentSupport implements LiteflowComponentSupport {
if (ObjectUtil.isNotNull(liteflowComponent)) {
return liteflowComponent.name();
}else{
return null;
return nodeComponent.getNodeId();
}
}

View File

@@ -1,2 +1,2 @@
# Spring 的实现
com.yomahub.liteflow.spi.solon.SolonAware
com.yomahub.liteflow.spi.solon.SolonContextAware

View File

@@ -24,5 +24,7 @@ public class TestApp {
public void test() throws Exception{
LiteflowResponse response = flowExecutor.execute2Resp("chain1", "arg");
System.out.println(ONode.stringify(response));
assert response.isSuccess();
}
}

View File

@@ -62,7 +62,7 @@
<bytebuddy.version>1.11.13</bytebuddy.version>
<aspectjweaver.version>1.8.13</aspectjweaver.version>
<logback-classic.version>1.2.3</logback-classic.version>
<solon.version>1.10.6</solon.version>
<solon.version>1.11.5</solon.version>
</properties>
<dependencyManagement>