mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
litefolw-solon-plugin 调整适配,节点组件改为收集后,再由 ContextCmpInit 统一调用 addManagedNode 进行登记。。这样可以确保 LifeCycleHolder 先收集完,再初始化节点组件
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package com.yomahub.liteflow.process.holder;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.noear.solon.core.AppContext;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 节点持有人(用于收集 Node 后统一注册)
|
||||
*
|
||||
* @author noear 2024/10/12 created
|
||||
*/
|
||||
public class SolonNodeHolder {
|
||||
/**
|
||||
* 作为 AppContext 附件(避免静态化)
|
||||
* */
|
||||
public static SolonNodeHolder of(AppContext context) {
|
||||
return context.attachOf(SolonNodeHolder.class, SolonNodeHolder::new);
|
||||
}
|
||||
|
||||
private SolonNodeHolder() {
|
||||
|
||||
}
|
||||
|
||||
private Map<String, NodeComponent> nodeMap = new HashMap<>();
|
||||
|
||||
public void put(String nodeId, NodeComponent nodeComponent) {
|
||||
this.nodeMap.put(nodeId, nodeComponent);
|
||||
}
|
||||
|
||||
public Map<String, NodeComponent> getNodeMap() {
|
||||
return nodeMap;
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,9 @@ import com.yomahub.liteflow.annotation.LiteflowMethod;
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import com.yomahub.liteflow.core.proxy.DeclWarpBean;
|
||||
import com.yomahub.liteflow.core.proxy.LiteFlowProxyUtil;
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.lifecycle.LifeCycle;
|
||||
import com.yomahub.liteflow.lifecycle.LifeCycleHolder;
|
||||
import com.yomahub.liteflow.process.holder.SolonNodeHolder;
|
||||
import com.yomahub.liteflow.solon.config.LiteflowAutoConfiguration;
|
||||
import com.yomahub.liteflow.solon.config.LiteflowMainAutoConfiguration;
|
||||
import com.yomahub.liteflow.solon.config.LiteflowMonitorProperty;
|
||||
@@ -42,6 +42,8 @@ public class XPluginImpl implements Plugin {
|
||||
return;
|
||||
}
|
||||
|
||||
SolonNodeHolder solonNodeHolder = SolonNodeHolder.of(context);
|
||||
|
||||
// 放到前面
|
||||
context.beanMake(LiteflowProperty.class);
|
||||
context.beanMake(LiteflowMonitorProperty.class);
|
||||
@@ -49,22 +51,26 @@ public class XPluginImpl implements Plugin {
|
||||
context.beanMake(LiteflowMainAutoConfiguration.class);
|
||||
|
||||
// 订阅生命周期实现类
|
||||
context.subWrapsOfType(LifeCycle.class, bw -> {
|
||||
LifeCycle lifeCycle = bw.raw();
|
||||
LifeCycleHolder.addLifeCycle(lifeCycle);
|
||||
context.subBeansOfType(LifeCycle.class, bean -> {
|
||||
LifeCycleHolder.addLifeCycle(bean);
|
||||
});
|
||||
|
||||
// 订阅 NodeComponent 组件
|
||||
context.subWrapsOfType(NodeComponent.class, bw -> {
|
||||
NodeComponent node1 = bw.raw();
|
||||
node1.setNodeId(bw.name());
|
||||
FlowBus.addManagedNode(bw.name(), bw.raw());
|
||||
// 订阅 @Component 或别的方式产生的 NodeComponent
|
||||
context.subWrapsOfType(NodeComponent.class, bw->{
|
||||
if (Utils.isNotEmpty(bw.name())) {
|
||||
NodeComponent node1 = bw.raw();
|
||||
node1.setNodeId(bw.name());
|
||||
|
||||
solonNodeHolder.put(node1.getNodeId(), node1);
|
||||
}
|
||||
});
|
||||
|
||||
Set<Class<?>> liteflowMethodClassSet = new HashSet<>();
|
||||
|
||||
//添加 @LiteflowMethod 注解处理
|
||||
context.beanExtractorAdd(LiteflowMethod.class, (bw, method, anno) -> {
|
||||
if (liteflowMethodClassSet.contains(bw.clz())) {
|
||||
//避免重复处理类
|
||||
return;
|
||||
} else {
|
||||
liteflowMethodClassSet.add(bw.clz());
|
||||
@@ -76,22 +82,26 @@ public class XPluginImpl implements Plugin {
|
||||
|
||||
for (DeclWarpBean declWarpBean : declWarpBeanList) {
|
||||
NodeComponent node1 = LiteFlowProxyUtil.proxy2NodeComponent(declWarpBean);
|
||||
FlowBus.addManagedNode(node1.getNodeId(), node1);
|
||||
|
||||
solonNodeHolder.put(node1.getNodeId(), node1);
|
||||
}
|
||||
});
|
||||
|
||||
//添加 @LiteflowComponent 注解处理
|
||||
context.beanBuilderAdd(LiteflowComponent.class, (clz, bw, anno) -> {
|
||||
if (NodeComponent.class.isAssignableFrom(clz)) {
|
||||
NodeComponent node1 = bw.raw();
|
||||
if(NodeComponent.class.isAssignableFrom(clz)) {
|
||||
String nodeId = Utils.annoAlias(anno.id(), anno.value());
|
||||
if (Utils.isNotEmpty(nodeId)) {
|
||||
NodeComponent node1 = bw.raw();
|
||||
node1.setNodeId(nodeId);
|
||||
node1.setName(anno.name());
|
||||
|
||||
node1.setNodeId(nodeId);
|
||||
node1.setName(anno.name());
|
||||
|
||||
FlowBus.addManagedNode(nodeId, node1);
|
||||
} else {
|
||||
context.beanExtractOrProxy(bw); // 尝试提取 LiteflowMethod 函数,并支持自动代理
|
||||
solonNodeHolder.put(nodeId, node1);
|
||||
}
|
||||
}
|
||||
|
||||
// 支持动态代理与函数提取
|
||||
context.beanExtractOrProxy(bw);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.yomahub.liteflow.spi.solon;
|
||||
|
||||
import com.yomahub.liteflow.flow.FlowBus;
|
||||
import com.yomahub.liteflow.process.holder.SolonNodeHolder;
|
||||
import com.yomahub.liteflow.spi.ContextCmpInit;
|
||||
import org.noear.solon.Solon;
|
||||
|
||||
/**
|
||||
* Solon 环境容器上下文组件初始化实现(在 solon 里没有用上;机制不同)
|
||||
@@ -12,7 +15,9 @@ public class SolonContextCmpInit implements ContextCmpInit {
|
||||
|
||||
@Override
|
||||
public void initCmp() {
|
||||
// 已在 XPluginImpl 添加组件
|
||||
SolonNodeHolder solonNodeHolder = SolonNodeHolder.of(Solon.context());
|
||||
|
||||
solonNodeHolder.getNodeMap().forEach(FlowBus::addManagedNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.yomahub.liteflow.flow.LiteflowResponse;
|
||||
import com.yomahub.liteflow.test.BaseTest;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.test.SolonTest;
|
||||
|
||||
|
||||
32
pom.xml
32
pom.xml
@@ -64,7 +64,7 @@
|
||||
<bytebuddy.version>1.14.10</bytebuddy.version>
|
||||
<aspectjweaver.version>1.8.13</aspectjweaver.version>
|
||||
<logback-classic.version>1.2.3</logback-classic.version>
|
||||
<solon.version>2.9.2</solon.version>
|
||||
<solon.version>3.0.1</solon.version>
|
||||
<netty.version>4.1.84.Final</netty.version>
|
||||
<httpclient.version>4.5.13</httpclient.version>
|
||||
<commons-beanutils.version>1.9.4</commons-beanutils.version>
|
||||
@@ -374,35 +374,7 @@
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.7.1</version>
|
||||
</plugin>
|
||||
<!-- Javadoc -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Gpg Signature -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- version number -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
|
||||
Reference in New Issue
Block a user