支持springboot2.x版本,项目路径调整

This commit is contained in:
bryan.zhang 2019-03-12 19:28:10 +08:00
parent 4e13507b03
commit 674bf39ae7
88 changed files with 979 additions and 29 deletions

View File

@ -1 +0,0 @@
theme: jekyll-theme-cayman

View File

@ -1 +0,0 @@
mvn clean install deploy

49
liteflow-test/pom.xml Normal file
View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.thebeastshop</groupId>
<artifactId>flowtest</artifactId>
<version>1.0.0</version>
<name>flowtest</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.thebeastshop</groupId>
<artifactId>liteflow</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,16 @@
package com.thebeastshop.flowtest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class FlowtestApplication {
public static void main(String[] args) {
try{
SpringApplication.run(FlowtestApplication.class, args);
}catch (Throwable t){
t.printStackTrace();
}
}
}

View File

@ -0,0 +1,21 @@
package com.thebeastshop.flowtest;
import com.thebeastshop.liteflow.core.FlowExecutor;
import com.thebeastshop.liteflow.entity.data.Slot;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component
public class TestFlow implements CommandLineRunner {
@Resource
private FlowExecutor flowExecutor;
@Override
public void run(String... args) throws Exception {
Slot slot = flowExecutor.execute("chain1", "it's a request");
System.out.println(slot);
}
}

View File

@ -0,0 +1,27 @@
/**
* <p>Title: liteFlow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* <p>Copyright: Copyright (c) 2017</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2017-8-1
* @version 1.0
*/
package com.thebeastshop.flowtest.components;
import com.thebeastshop.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("a")
public class AComponent extends NodeComponent {
@Override
public void process() {
String str = this.getSlot().getRequestData();
System.out.println(str);
System.out.println("Acomponent executed!");
this.getSlot().setOutput(this.getNodeId(), "A component output");
}
}

View File

@ -0,0 +1,30 @@
/**
* <p>Title: liteFlow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* <p>Copyright: Copyright (c) 2017</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2017-8-1
* @version 1.0
*/
package com.thebeastshop.flowtest.components;
import com.thebeastshop.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("b")
public class BComponent extends NodeComponent {
@Override
public void process() {
try {
Thread.sleep(400L);
String[] temp = new String[1000];
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Bcomponent executed!");
}
}

View File

@ -0,0 +1,30 @@
/**
* <p>Title: liteFlow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* <p>Copyright: Copyright (c) 2017</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2017-8-1
* @version 1.0
*/
package com.thebeastshop.flowtest.components;
import com.thebeastshop.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("c")
public class CComponent extends NodeComponent {
@Override
public void process() {
try {
String[] temp = new String[4000];
Thread.sleep(300L);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Ccomponent executed!");
}
}

View File

@ -0,0 +1,22 @@
/**
* <p>Title: litis</p>
* <p>Description: redis的全方位开发运维平台</p>
* <p>Copyright: Copyright (c) 2017</p>
* @author Bryan.Zhang
* @email 47483522@qq.com
* @Date 2017-11-28
*/
package com.thebeastshop.flowtest.components;
import com.thebeastshop.liteflow.core.NodeComponent;
import com.thebeastshop.liteflow.core.NodeCondComponent;
import org.springframework.stereotype.Component;
@Component("cond")
public class CondComponent extends NodeCondComponent {
@Override
protected Class<? extends NodeComponent> processCond() throws Exception {
return BComponent.class;
}
}

View File

@ -0,0 +1,38 @@
/**
* <p>Title: liteFlow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* <p>Copyright: Copyright (c) 2017</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2017-8-1
* @version 1.0
*/
package com.thebeastshop.flowtest.components;
import com.thebeastshop.liteflow.core.NodeComponent;
import com.thebeastshop.liteflow.entity.data.Slot;
import org.springframework.stereotype.Component;
@Component("d")
public class DComponent extends NodeComponent {
@Override
public void process() {
try {
Slot slot = this.getSlot();
String e = slot.getOutput("e");
if(e == null){
System.out.println(slot);
}
System.out.println("D:" + slot.getOutput("e"));
String[] temp = new String[1400];
Thread.sleep(450L);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Dcomponent executed!");
}
}

View File

@ -0,0 +1,31 @@
/**
* <p>Title: liteFlow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* <p>Copyright: Copyright (c) 2017</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2017-8-1
* @version 1.0
*/
package com.thebeastshop.flowtest.components;
import com.thebeastshop.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("e")
public class EComponent extends NodeComponent {
@Override
public void process() {
try {
Thread.sleep(120L);
System.out.println("E:" + this.getSlot().getOutput("a"));
this.getSlot().setOutput(this.getNodeId(), "E component output");
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Eomponent executed!");
}
}

View File

@ -0,0 +1,30 @@
/**
* <p>Title: liteFlow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* <p>Copyright: Copyright (c) 2017</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2017-8-1
* @version 1.0
*/
package com.thebeastshop.flowtest.components;
import com.thebeastshop.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("f")
public class FComponent extends NodeComponent {
@Override
public void process() {
try {
String[] temp = new String[400];
Thread.sleep(40L);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Fcomponent executed!");
}
}

View File

@ -0,0 +1,24 @@
/**
* <p>Title: liteFlow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* <p>Copyright: Copyright (c) 2017</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2017-8-1
* @version 1.0
*/
package com.thebeastshop.flowtest.components;
import com.thebeastshop.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
@Component("g")
public class GComponent extends NodeComponent {
@Override
public void process() {
System.out.println("Gcomponent executed!");
this.getSlot().setResponseData("i am a response");
}
}

View File

@ -0,0 +1,31 @@
/**
* <p>Title: liteFlow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* <p>Copyright: Copyright (c) 2017</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2017-8-1
* @version 1.0
*/
package com.thebeastshop.flowtest.components;
import com.thebeastshop.liteflow.core.FlowExecutor;
import com.thebeastshop.liteflow.core.NodeComponent;
import com.thebeastshop.liteflow.entity.data.DefaultSlot;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component("h")
public class HComponent extends NodeComponent {
@Resource
private FlowExecutor flowExecutor;
@Override
public void process() {
System.out.println("Hcomponent executed!");
flowExecutor.invoke("strategy1",3, DefaultSlot.class, this.getSlotIndex());
}
}

View File

@ -0,0 +1,29 @@
/**
* <p>Title: liteFlow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* <p>Copyright: Copyright (c) 2017</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2017-8-1
* @version 1.0
*/
package com.thebeastshop.flowtest.components;
import com.thebeastshop.liteflow.core.FlowExecutor;
import com.thebeastshop.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component("m1")
public class M1Component extends NodeComponent {
@Resource
private FlowExecutor flowExecutor;
@Override
public void process() {
System.out.println("m1 component executed!");
}
}

View File

@ -0,0 +1,29 @@
/**
* <p>Title: liteFlow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* <p>Copyright: Copyright (c) 2017</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2017-8-1
* @version 1.0
*/
package com.thebeastshop.flowtest.components;
import com.thebeastshop.liteflow.core.FlowExecutor;
import com.thebeastshop.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component("m2")
public class M2Component extends NodeComponent {
@Resource
private FlowExecutor flowExecutor;
@Override
public void process() {
System.out.println("m2 component executed!");
}
}

View File

@ -0,0 +1,31 @@
/**
* <p>Title: liteFlow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* <p>Copyright: Copyright (c) 2017</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2017-8-1
* @version 1.0
*/
package com.thebeastshop.flowtest.components;
import com.thebeastshop.liteflow.core.FlowExecutor;
import com.thebeastshop.liteflow.core.NodeComponent;
import com.thebeastshop.liteflow.entity.data.DefaultSlot;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component("m3")
public class M3Component extends NodeComponent {
@Resource
private FlowExecutor flowExecutor;
@Override
public void process() {
System.out.println("m3 component executed!");
flowExecutor.invoke("strategy2",10, DefaultSlot.class, this.getSlotIndex());
}
}

View File

@ -0,0 +1,39 @@
/**
* <p>Title: liteFlow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* <p>Copyright: Copyright (c) 2017</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2017-8-1
* @version 1.0
*/
package com.thebeastshop.flowtest.components;
import com.thebeastshop.liteflow.core.FlowExecutor;
import com.thebeastshop.liteflow.core.NodeComponent;
import com.thebeastshop.liteflow.core.NodeCondComponent;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component("m")
public class MComponent extends NodeCondComponent {
@Resource
private FlowExecutor flowExecutor;
@Override
protected Class<? extends NodeComponent> processCond() throws Exception {
System.out.println("m conponent executed");
Integer flag = this.getSlot().getChainReqData("strategy1");
if(flag == 1) {
return M1Component.class;
}else if(flag == 2){
return M2Component.class;
}else {
return M3Component.class;
}
}
}

View File

@ -0,0 +1,29 @@
/**
* <p>Title: liteFlow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* <p>Copyright: Copyright (c) 2017</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2017-8-1
* @version 1.0
*/
package com.thebeastshop.flowtest.components;
import com.thebeastshop.liteflow.core.FlowExecutor;
import com.thebeastshop.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component("p1")
public class P1Component extends NodeComponent {
@Resource
private FlowExecutor flowExecutor;
@Override
public void process() {
System.out.println("p1 component executed!");
}
}

View File

@ -0,0 +1,29 @@
/**
* <p>Title: liteFlow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* <p>Copyright: Copyright (c) 2017</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2017-8-1
* @version 1.0
*/
package com.thebeastshop.flowtest.components;
import com.thebeastshop.liteflow.core.FlowExecutor;
import com.thebeastshop.liteflow.core.NodeComponent;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component("p2")
public class P2Component extends NodeComponent {
@Resource
private FlowExecutor flowExecutor;
@Override
public void process() {
System.out.println("p2 component executed!");
}
}

View File

@ -0,0 +1,37 @@
/**
* <p>Title: liteFlow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* <p>Copyright: Copyright (c) 2017</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2017-8-1
* @version 1.0
*/
package com.thebeastshop.flowtest.components;
import com.thebeastshop.liteflow.core.FlowExecutor;
import com.thebeastshop.liteflow.core.NodeComponent;
import com.thebeastshop.liteflow.core.NodeCondComponent;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component("p")
public class PComponent extends NodeCondComponent {
@Resource
private FlowExecutor flowExecutor;
@Override
protected Class<? extends NodeComponent> processCond() throws Exception {
System.out.println("p conponent executed");
Integer flag = this.getSlot().getChainReqData("strategy2");
if(flag == 10) {
return P1Component.class;
}else {
return P2Component.class;
}
}
}

View File

@ -0,0 +1,131 @@
package com.thebeastshop.flowtest.curator;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.cache.*;
import org.apache.curator.retry.RetryNTimes;
public class CuratorTest {
/** Zookeeper info */
private static final String ZK_ADDRESS = "123.206.92.144:2181,123.206.92.144:2182,123.206.92.144:2183";
private static final String ZK_PATH = "/zktest/a1/aa1";
public static void main(String[] args) throws Exception {
// 1.Connect to zk
CuratorFramework client = CuratorFrameworkFactory.newClient(
ZK_ADDRESS,
new RetryNTimes(10, 5000)
);
client.start();
checkNode(client);
// childNodeListen(client);
// removeNodeData(client);
// createNode(client);
// nodeListen(client);
//
// modifyNodeData(client);
System.in.read();
// getNodeData(client);
//
//
}
private static void checkNode(CuratorFramework client) throws Exception {
System.out.println(client.checkExists().forPath("/test"));
}
private static void createNode(CuratorFramework client) throws Exception {
String data1 = "nice to meet you";
print("create", ZK_PATH, data1);
client.create().
creatingParentsIfNeeded().
forPath(ZK_PATH, data1.getBytes());
}
private static void getNodeData(CuratorFramework client) throws Exception {
print("ls", "/");
print(client.getChildren().forPath("/"));
print("get", ZK_PATH);
print(client.getData().forPath(ZK_PATH));
}
private static void modifyNodeData(CuratorFramework client) throws Exception {
String data2 = "world for u";
print("set", ZK_PATH, data2);
client.setData().forPath(ZK_PATH, data2.getBytes());
print("get", ZK_PATH);
print(client.getData().forPath(ZK_PATH));
}
private static void removeNodeData(CuratorFramework client) throws Exception {
print("delete", "/zktest/dddd");
client.delete().forPath("/zktest/dddd");
print("ls", "/");
print(client.getChildren().forPath("/"));
}
private static void nodeListen(CuratorFramework client) throws Exception {
final NodeCache cache = new NodeCache(client,ZK_PATH);
cache.start();
cache.getListenable().addListener(new NodeCacheListener() {
@Override
public void nodeChanged() throws Exception {
byte[] res = cache.getCurrentData().getData();
System.out.println("data: " + new String(res));
}
});
}
private static void childNodeListen(CuratorFramework client) throws Exception {
final PathChildrenCache cache = new PathChildrenCache(client,"/zktest",true);
cache.start();
cache.getListenable().addListener(new PathChildrenCacheListener() {
@Override
public void childEvent(CuratorFramework curator, PathChildrenCacheEvent event) throws Exception {
switch (event.getType()) {
case CHILD_ADDED:
System.out.println("add:" + event.getData().getPath() + ":" + new String(event.getData().getData()));
break;
case CHILD_UPDATED:
System.out.println("update:" + event.getData().getPath() + ":" + new String(event.getData().getData()));
break;
case CHILD_REMOVED:
System.out.println("remove:" + event.getData().getPath() + ":" + new String(event.getData().getData()));
break;
default:
break;
}
}
});
}
private static void print(String... cmds) {
StringBuilder text = new StringBuilder("$ ");
for (String cmd : cmds) {
text.append(cmd).append(" ");
}
System.out.println(text.toString());
}
private static void print(Object result) {
System.out.println(
result instanceof byte[]
? new String((byte[]) result)
: result);
}
}

View File

@ -0,0 +1,117 @@
package com.thebeastshop.flowtest.curator;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.cache.*;
import org.apache.curator.retry.RetryNTimes;
public class CuratorTest2 {
/** Zookeeper info */
private static final String ZK_ADDRESS = "114.55.174.189:2181";
private static final String ZK_PATH = "/zktest/ffff";
public static void main(String[] args) throws Exception {
// 1.Connect to zk
CuratorFramework client = CuratorFrameworkFactory.newClient(
ZK_ADDRESS,
new RetryNTimes(10, 5000)
);
client.start();
// removeNodeData(client);
// createNode(client);
// nodeListen(client);
//
modifyNodeData(client);
}
private static void createNode(CuratorFramework client) throws Exception {
String data1 = "hello";
print("create", ZK_PATH, data1);
client.create().
creatingParentsIfNeeded().
forPath(ZK_PATH, data1.getBytes());
}
private static void getNodeData(CuratorFramework client) throws Exception {
print("ls", "/");
print(client.getChildren().forPath("/"));
print("get", ZK_PATH);
print(client.getData().forPath(ZK_PATH));
}
private static void modifyNodeData(CuratorFramework client) throws Exception {
String data2 = "world for u";
print("set", ZK_PATH, data2);
client.setData().forPath(ZK_PATH, data2.getBytes());
print("get", ZK_PATH);
print(client.getData().forPath(ZK_PATH));
}
private static void removeNodeData(CuratorFramework client) throws Exception {
print("delete", "/zktest/dddd");
client.delete().forPath("/zktest/dddd");
print("ls", "/");
print(client.getChildren().forPath("/"));
}
private static void nodeListen(CuratorFramework client) throws Exception {
final NodeCache cache = new NodeCache(client,ZK_PATH);
cache.start();
cache.getListenable().addListener(new NodeCacheListener() {
@Override
public void nodeChanged() throws Exception {
byte[] res = cache.getCurrentData().getData();
System.out.println("data: " + new String(res));
}
});
}
private static void childNodeListen(CuratorFramework client) throws Exception {
final PathChildrenCache cache = new PathChildrenCache(client,"/zktest",true);
cache.start();
cache.getListenable().addListener(new PathChildrenCacheListener() {
@Override
public void childEvent(CuratorFramework curator, PathChildrenCacheEvent event) throws Exception {
switch (event.getType()) {
case CHILD_ADDED:
System.out.println("add:" + event.getData().getPath() + ":" + new String(event.getData().getData()));
break;
case CHILD_UPDATED:
System.out.println("update:" + event.getData().getPath() + ":" + new String(event.getData().getData()));
break;
case CHILD_REMOVED:
System.out.println("remove:" + event.getData().getPath() + ":" + new String(event.getData().getData()));
break;
default:
break;
}
}
});
}
private static void print(String... cmds) {
StringBuilder text = new StringBuilder("$ ");
for (String cmd : cmds) {
text.append(cmd).append(" ");
}
System.out.println(text.toString());
}
private static void print(Object result) {
System.out.println(
result instanceof byte[]
? new String((byte[]) result)
: result);
}
}

View File

@ -0,0 +1,23 @@
package com.thebeastshop.flowtest.regex;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTest {
public static void main(String[] args) {
String str = "192.168.1.1:2181,192.168.1.2:2182,192.168.1.3:2183";
List<String> list = new ArrayList<String>();
Pattern p = Pattern.compile("[\\w\\d][\\w\\d\\.]+\\:(\\d)+(\\,[\\w\\d][\\w\\d\\.]+\\:(\\d)+)*");
Matcher m = p.matcher(str);
while(m.find()){
list.add(m.group());
}
System.out.println(list.size());
System.out.println(list);
}
}

View File

@ -0,0 +1 @@
liteFlow.ruleSource=config/flow.xml

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<!-- 如果和spring集成以下<nodes>配置可以不要
<nodes>
<node id="a" class="com.thebeastshop.flowtest.components.AComponent"/>
<node id="b" class="com.thebeastshop.flowtest.components.BComponent"/>
<node id="c" class="com.thebeastshop.flowtest.components.CComponent"/>
<node id="d" class="com.thebeastshop.flowtest.components.DComponent"/>
<node id="e" class="com.thebeastshop.flowtest.components.EComponent"/>
<node id="f" class="com.thebeastshop.flowtest.components.FComponent"/>
<node id="g" class="com.thebeastshop.flowtest.components.GComponent"/>
<node id="cond" class="com.thebeastshop.liteflow.test.component.CondComponent"/>
</nodes>
-->
<chain name="chain1">
<then value="a,cond(b|d)"/> <!-- cond是条件节点根据cond里的逻辑决定路由到b节点还是d节点,可以配置多个 -->
<then value="e,f,g"/>
</chain>
<chain name="chain2">
<then value="a,c"/> <!-- then表示串行 -->
<when value="b,d"/> <!-- when表示串行 -->
<then value="e,f,g"/>
</chain>
<chain name="chain3">
<then value="a,c,h,g"/>
</chain>
<chain name="strategy1">
<then value="m(m1|m2|m3)"/>
</chain>
<chain name="strategy2">
<then value="p(p1|p2)"/>
</chain>
</flow>

View File

@ -0,0 +1,16 @@
package com.thebeastshop.flowtest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class FlowtestApplicationTests {
@Test
public void contextLoads() {
}
}

View File

@ -1,20 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>com.thebeastshop.liteflow</groupId>
<groupId>com.thebeastshop</groupId>
<artifactId>liteflow</artifactId>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<version>2.0.2</version>
<version>2.1.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
<java.version>1.8</java.version>
<commons.lang3.version>3.4</commons.lang3.version>
<commons-collections.version>4.1</commons-collections.version>
<commons-io.version>2.4</commons-io.version>
<commons-logging.version>1.2</commons-logging.version>
<spring.version>4.2.6.RELEASE</spring.version>
<spring.version>5.0.9.RELEASE</spring.version>
<org.slf4j.version>1.7.21</org.slf4j.version>
<log4j.version>1.2.17</log4j.version>
<log4j-slf4j.version>1.7.5</log4j-slf4j.version>
@ -124,14 +124,27 @@
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>nexus-releases</name>
<url>http://118.178.236.200:8087/nexus/content/repositories/thirdparty</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>nexus-snapshots</name>
<url>http://118.178.236.200:8087/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>

View File

@ -18,36 +18,36 @@ import com.thebeastshop.liteflow.entity.config.Chain;
import com.thebeastshop.liteflow.entity.config.Node;
public class FlowBus {
private static Map<String, Chain> chainMap;
private static Map<String, Node> nodeMap;
public static Chain getChain(String id) throws Exception{
if(chainMap == null || chainMap.isEmpty()){
throw new Exception("please config the rule first");
}
return chainMap.get(id);
}
public static void addChain(String name,Chain chain){
if(chainMap == null){
chainMap = new HashMap<String, Chain>();
chainMap = new HashMap<>();
}
chainMap.put(name, chain);
}
public static boolean needInit() {
return MapUtils.isEmpty(chainMap);
}
public static void addNode(String nodeId, Node node) {
if(nodeMap == null) {
nodeMap = new HashMap<String, Node>();
nodeMap = new HashMap<>();
}
nodeMap.put(nodeId, node);
}
public static Node getNode(String nodeId) {
return nodeMap.get(nodeId);
}

View File

@ -24,11 +24,11 @@ import com.thebeastshop.liteflow.spring.ComponentScaner;
import com.thebeastshop.liteflow.util.Dom4JReader;
public abstract class XmlFlowParser {
private final Logger LOG = LoggerFactory.getLogger(XmlFlowParser.class);
public abstract void parseMain(String path) throws Exception;
public void parse(String content) throws Exception {
Document document = Dom4JReader.getFormatDocument(content);
parse(document);
@ -77,14 +77,14 @@ public abstract class XmlFlowParser {
List<Element> chainList = rootElement.elements("chain");
for (Element e : chainList) {
chainName = e.attributeValue("name");
conditionList = new ArrayList<Condition>();
conditionList = new ArrayList<>();
for (Iterator<Element> it = e.elementIterator(); it.hasNext();) {
Element condE = it.next();
condArrayStr = condE.attributeValue("value");
if (StringUtils.isBlank(condArrayStr)) {
continue;
}
chainNodeList = new ArrayList<Node>();
chainNodeList = new ArrayList<>();
condArray = condArrayStr.split(",");
RegexEntity regexEntity = null;
Node node = null;
@ -114,7 +114,7 @@ public abstract class XmlFlowParser {
}
}
public static RegexEntity parseNodeStr(String str) {
List<String> list = new ArrayList<String>();
Pattern p = Pattern.compile("[^\\)\\(]+");

View File

@ -0,0 +1,39 @@
package com.thebeastshop.liteflow.spring;
import com.thebeastshop.liteflow.core.FlowExecutor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertySource;
import java.util.Arrays;
import java.util.Iterator;
public class FlowContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
private final static String LITEFLOW_PROPERTY = "liteFlow.ruleSource";
@Override
public void initialize(ConfigurableApplicationContext context) {
ConfigurableEnvironment environment = context.getEnvironment();
Iterator<PropertySource<?>> it = environment.getPropertySources().iterator();
while (it.hasNext()){
PropertySource propertySource = it.next();
if(propertySource.containsProperty(LITEFLOW_PROPERTY)){
//注册scaner
DefaultListableBeanFactory factory = (DefaultListableBeanFactory)context.getBeanFactory();
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(ComponentScaner.class);
factory.registerBeanDefinition("componentScaner", beanDefinitionBuilder.getRawBeanDefinition());
//注册flowExecutor
String rulePath = (String)propertySource.getProperty(LITEFLOW_PROPERTY);
beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(FlowExecutor.class);
beanDefinitionBuilder.addPropertyValue("rulePath",Arrays.asList(rulePath.split(",")));
factory.registerBeanDefinition("flowExecutor", beanDefinitionBuilder.getRawBeanDefinition());
}
}
}
}

View File

@ -0,0 +1,2 @@
org.springframework.context.ApplicationContextInitializer=\
com.thebeastshop.liteflow.spring.FlowContextInitializer