Skip to content

Commit

Permalink
Merge pull request #29 from lunasaw/2.5.9
Browse files Browse the repository at this point in the history
2.5.9 增加流程引擎
  • Loading branch information
lunasaw authored May 29, 2024
2 parents 67fc336 + d7d95a4 commit 50da3f9
Show file tree
Hide file tree
Showing 17 changed files with 809 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

更新日志

- 2024-05-29 流程引擎
- 2023-09-24 断点续传


Expand Down
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>io.github.lunasaw</groupId>
<artifactId>luna-common</artifactId>
<name>luna-common</name>
<version>2.5.8</version>
<version>2.5.9</version>
<description>common is project which contains common utils</description>
<url>https://github.com/lunasaw/luna-common</url>

Expand Down Expand Up @@ -121,6 +121,11 @@
<artifactId>jaxb-runtime</artifactId>
<version>4.0.5</version> <!-- 最新版本 -->
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>6.1.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/luna/common/engine/model/EngineContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.luna.common.engine.model;

import com.google.common.collect.Maps;
import lombok.Data;

import java.util.Map;

@Data
public class EngineContext {

/**
* adaptor的结果缓存
*/
private Map<String/** ResultKey **/
, Object> adaptorMap = Maps.newConcurrentMap();

/**
* engin是否继续执行
*/
private boolean isStop;

}
15 changes: 15 additions & 0 deletions src/main/java/com/luna/common/engine/model/EngineRunData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.luna.common.engine.model;

import lombok.Data;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* @author luna
*/
@Data
public class EngineRunData {

private Map<String, Object> runData = new ConcurrentHashMap<>();
}
88 changes: 88 additions & 0 deletions src/main/java/com/luna/common/engine/model/NodeChain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.luna.common.engine.model;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;

import com.google.common.collect.Maps;

import lombok.Getter;
import lombok.Setter;

/**
* <p>
* detailNode的存储类
*/
@Getter
@Setter
public class NodeChain {

private Map<NodeName, NodeConf> nodeMap = Maps.newLinkedHashMap();

private static NodeName getNodeName(String groupName, Class nodeClass) {
NodeName nodeName;
if (StringUtils.isNotBlank(groupName)) {
nodeName = new NodeName(groupName, nodeClass.getName());
} else {
nodeName = new NodeName(null, nodeClass.getName());
}
return nodeName;
}

public void add(String groupName, Class nodeClass, NodeConf nodeConf) {
NodeName nodeName = getNodeName(groupName, nodeClass);
add(nodeName, nodeConf);
}

public void add(Class nodeName, NodeConf nodeConf) {
add(nodeName.getName(), nodeName, nodeConf);
}

public void add(NodeName nodeName, NodeConf nodeConf) {
if (nodeMap.containsKey(nodeName)) {
return;
}
nodeMap.put(nodeName, nodeConf);
}

public void replace(String groupName, Class nodeClass, NodeConf nodeConf) {
NodeName nodeName = getNodeName(groupName, nodeClass);

nodeMap.put(nodeName, nodeConf);
}

public void replace(NodeName nodeName, NodeConf nodeConf) {
nodeMap.put(nodeName, nodeConf);
}

public void replace(Class nodeName, NodeConf nodeConf) {
replace(nodeName.getName(), nodeName, nodeConf);
}

public void remove(Class nodeName) {
remove(nodeName.getName(), nodeName);
}

public void remove(String groupName, Class nodeClass) {
NodeName nodeName = getNodeName(groupName, nodeClass);
nodeMap.remove(nodeName);
}

public Set<String> getNodeNameList() {
return getNodeList().stream().map(NodeName::getNodeName).collect(Collectors.toSet());
}

public Set<NodeName> getNodeList() {
return nodeMap.keySet();
}

public NodeChain deepClone() {
LinkedHashMap<NodeName, NodeConf> cloneMap = new LinkedHashMap<>(nodeMap);
NodeChain nodeChain = new NodeChain();
nodeChain.setNodeMap(cloneMap);
return nodeChain;
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/luna/common/engine/model/NodeConf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.luna.common.engine.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* 节点配置
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
public class NodeConf {

/**
* 是否是强依赖
*/
private boolean isStrongRely = true;
/**
* 并行执行超时时间
* 默认200ms
*/
private int timeout = 200;
}
55 changes: 55 additions & 0 deletions src/main/java/com/luna/common/engine/model/NodeName.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.luna.common.engine.model;

import com.luna.common.check.Assert;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Objects;

/**
* 节点Key
*/
@NoArgsConstructor
@Data
public class NodeName {

/**
* 节点组
*/
private String groupName;
/**
* 节点名称
*/
private String nodeName;

public NodeName(String groupName, String nodeName) {
Assert.notNull(nodeName, "节点名称不能为空");
this.groupName = groupName;
this.nodeName = nodeName;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
NodeName nodeName1 = (NodeName)o;
return Objects.equals(groupName, nodeName1.groupName) && Objects.equals(nodeName, nodeName1.nodeName);
}

@Override
public int hashCode() {
return Objects.hash(groupName, nodeName);
}

@Override
public String toString() {
final StringBuffer sb = new StringBuffer("NodeName{");
sb.append("groupName='").append(groupName).append('\'');
sb.append(", nodeName='").append(nodeName).append('\'');
sb.append('}');
return sb.toString();
}
}
Loading

0 comments on commit 50da3f9

Please sign in to comment.