mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 04:02:09 +08:00
改造和优化SLOT的扩展结构
This commit is contained in:
@@ -25,6 +25,7 @@ import com.thebeastshop.liteflow.entity.config.ThenCondition;
|
||||
import com.thebeastshop.liteflow.entity.config.WhenCondition;
|
||||
import com.thebeastshop.liteflow.entity.data.DataBus;
|
||||
import com.thebeastshop.liteflow.entity.data.DefaultSlot;
|
||||
import com.thebeastshop.liteflow.entity.data.AbsSlot;
|
||||
import com.thebeastshop.liteflow.entity.data.Slot;
|
||||
import com.thebeastshop.liteflow.exception.ChainNotFoundException;
|
||||
import com.thebeastshop.liteflow.exception.ComponentNotAccessException;
|
||||
|
||||
100
src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java
Normal file
100
src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* <p>Title: liteFlow</p>
|
||||
* <p>Description: 轻量级的组件式流程框架</p>
|
||||
* <p>Copyright: Copyright (c) 2017</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2017-8-3
|
||||
* @version 1.0
|
||||
*/
|
||||
package com.thebeastshop.liteflow.entity.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public abstract class AbsSlot implements Slot{
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Slot.class);
|
||||
|
||||
private final String REQUEST = "request";
|
||||
|
||||
private final String RESPONSE = "response";
|
||||
|
||||
private final String COND_NODE_PREFIX = "cond_";
|
||||
|
||||
private final String NODE_INPUT_PREFIX = "input_";
|
||||
|
||||
private final String NODE_OUTPUT_PREFIX = "output_";
|
||||
|
||||
private List<String> executeSteps = new ArrayList<String>();
|
||||
|
||||
protected ConcurrentHashMap<String, Object> dataMap = new ConcurrentHashMap<String, Object>();
|
||||
|
||||
public <T> T getInput(String nodeId){
|
||||
return (T)dataMap.get(NODE_INPUT_PREFIX + nodeId);
|
||||
}
|
||||
|
||||
public <T> T getOutput(String nodeId){
|
||||
return (T)dataMap.get(NODE_OUTPUT_PREFIX + nodeId);
|
||||
}
|
||||
|
||||
public <T> void setInput(String nodeId,T t){
|
||||
dataMap.put(NODE_INPUT_PREFIX + nodeId, t);
|
||||
}
|
||||
|
||||
public <T> void setOutput(String nodeId,T t){
|
||||
dataMap.put(NODE_OUTPUT_PREFIX + nodeId, t);
|
||||
}
|
||||
|
||||
public <T> T getRequestData(){
|
||||
return (T)dataMap.get(REQUEST);
|
||||
}
|
||||
|
||||
public <T> void setRequestData(T t){
|
||||
dataMap.put(REQUEST, t);
|
||||
}
|
||||
|
||||
public <T> T getResponseData(){
|
||||
return (T)dataMap.get(RESPONSE);
|
||||
}
|
||||
|
||||
public <T> void setResponseData(T t){
|
||||
dataMap.put(RESPONSE, t);
|
||||
}
|
||||
|
||||
public <T> T getData(String key){
|
||||
return (T)dataMap.get(key);
|
||||
}
|
||||
|
||||
public <T> void setData(String key, T t){
|
||||
dataMap.put(key, t);
|
||||
}
|
||||
|
||||
public <T> void setCondResult(String key, T t){
|
||||
dataMap.put(COND_NODE_PREFIX + key, t);
|
||||
}
|
||||
|
||||
public <T> T getCondResult(String key){
|
||||
return (T)dataMap.get(COND_NODE_PREFIX + key);
|
||||
}
|
||||
|
||||
public void addStep(String nodeId){
|
||||
this.executeSteps.add(nodeId);
|
||||
}
|
||||
|
||||
public void printStep(){
|
||||
StringBuffer str = new StringBuffer();
|
||||
for(int i = 0; i < this.executeSteps.size(); i++){
|
||||
str.append(executeSteps.get(i));
|
||||
if(i < this.executeSteps.size()-1){
|
||||
str.append("==>");
|
||||
}
|
||||
}
|
||||
LOG.info(str.toString());
|
||||
}
|
||||
}
|
||||
@@ -4,97 +4,11 @@
|
||||
* <p>Copyright: Copyright (c) 2017</p>
|
||||
* @author Bryan.Zhang
|
||||
* @email weenyc31@163.com
|
||||
* @Date 2017-8-3
|
||||
* @Date 2017-12-4
|
||||
* @version 1.0
|
||||
*/
|
||||
package com.thebeastshop.liteflow.entity.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
public class DefaultSlot extends AbsSlot {
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class DefaultSlot implements Slot{
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Slot.class);
|
||||
|
||||
private final String REQUEST = "request";
|
||||
|
||||
private final String RESPONSE = "response";
|
||||
|
||||
private final String COND_NODE_PREFIX = "cond_";
|
||||
|
||||
private final String NODE_INPUT_PREFIX = "input_";
|
||||
|
||||
private final String NODE_OUTPUT_PREFIX = "output_";
|
||||
|
||||
private List<String> executeSteps = new ArrayList<String>();
|
||||
|
||||
protected ConcurrentHashMap<String, Object> dataMap = new ConcurrentHashMap<String, Object>();
|
||||
|
||||
public <T> T getInput(String nodeId){
|
||||
return (T)dataMap.get(NODE_INPUT_PREFIX + nodeId);
|
||||
}
|
||||
|
||||
public <T> T getOutput(String nodeId){
|
||||
return (T)dataMap.get(NODE_OUTPUT_PREFIX + nodeId);
|
||||
}
|
||||
|
||||
public <T> void setInput(String nodeId,T t){
|
||||
dataMap.put(NODE_INPUT_PREFIX + nodeId, t);
|
||||
}
|
||||
|
||||
public <T> void setOutput(String nodeId,T t){
|
||||
dataMap.put(NODE_OUTPUT_PREFIX + nodeId, t);
|
||||
}
|
||||
|
||||
public <T> T getRequestData(){
|
||||
return (T)dataMap.get(REQUEST);
|
||||
}
|
||||
|
||||
public <T> void setRequestData(T t){
|
||||
dataMap.put(REQUEST, t);
|
||||
}
|
||||
|
||||
public <T> T getResponseData(){
|
||||
return (T)dataMap.get(RESPONSE);
|
||||
}
|
||||
|
||||
public <T> void setResponseData(T t){
|
||||
dataMap.put(RESPONSE, t);
|
||||
}
|
||||
|
||||
public <T> T getData(String key){
|
||||
return (T)dataMap.get(key);
|
||||
}
|
||||
|
||||
public <T> void setData(String key, T t){
|
||||
dataMap.put(key, t);
|
||||
}
|
||||
|
||||
public <T> void setCondResult(String key, T t){
|
||||
dataMap.put(COND_NODE_PREFIX + key, t);
|
||||
}
|
||||
|
||||
public <T> T getCondResult(String key){
|
||||
return (T)dataMap.get(COND_NODE_PREFIX + key);
|
||||
}
|
||||
|
||||
public void addStep(String nodeId){
|
||||
this.executeSteps.add(nodeId);
|
||||
}
|
||||
|
||||
public void printStep(){
|
||||
StringBuffer str = new StringBuffer();
|
||||
for(int i = 0; i < this.executeSteps.size(); i++){
|
||||
str.append(executeSteps.get(i));
|
||||
if(i < this.executeSteps.size()-1){
|
||||
str.append("==>");
|
||||
}
|
||||
}
|
||||
LOG.info(str.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user