整理项目结构

This commit is contained in:
bryan.zhang
2019-03-12 19:46:09 +08:00
parent 674bf39ae7
commit efb5719ba5
7 changed files with 20 additions and 318 deletions

View File

@@ -9,9 +9,8 @@
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.thebeastshop</groupId>
<artifactId>flowtest</artifactId>
<artifactId>liteflow-test</artifactId>
<version>1.0.0</version>
<name>flowtest</name>
<description>Demo project for Spring Boot</description>
<properties>

View File

@@ -1,13 +0,0 @@
package com.thebeastshop.liteflow.test;
import com.thebeastshop.liteflow.parser.ClassXmlFlowParser;
public class TestCustomParser extends ClassXmlFlowParser {
@Override
public String parseCustom() {
System.out.println("进入自定义parser,这里只做进入作用不返回具体xml");
return null;
}
}

View File

@@ -14,16 +14,17 @@ import java.util.Arrays;
import com.thebeastshop.liteflow.core.FlowExecutor;
import com.thebeastshop.liteflow.entity.data.Slot;
/**
* 这是编程式引用liteflow
*/
public class TestMain {
public static void main(String[] args) throws Exception {
final FlowExecutor executor = new FlowExecutor();
executor.setRulePath(Arrays.asList(new String[]{"config/flow.xml"}));
executor.init();
for(int i=0;i<1;i++){
Slot slot = executor.execute("chain1", "it's a request");
System.out.println(slot);
}
Slot slot = executor.execute("chain1", "it's a request");
System.out.println(slot);
}
}

View File

@@ -14,31 +14,25 @@ import com.thebeastshop.liteflow.core.FlowExecutor;
import com.thebeastshop.liteflow.entity.data.Slot;
/**
* 此示例演示了如何在spring中用liteflow
* 如果是springboot请参考flowtest
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:spring-test.xml" })
public class TestWithSpringMain {
@Resource(name="flowExecutor")
private FlowExecutor flowExecutor;
@Test
public void test1() throws Exception {
ExecutorService executorService = Executors.newFixedThreadPool(10);
for(int i=0;i<1;i++){
executorService.submit(new Thread(){
@Override
public void run() {
Slot slot = flowExecutor.execute("chain1", "it's a request");
System.out.println(slot);
}
});
}
Slot slot = flowExecutor.execute("chain1", "it's a request");
System.out.println(slot);
System.out.println("done!");
System.in.read();
}
@Test
public void test2() throws Exception {
try {
@@ -48,9 +42,9 @@ public class TestWithSpringMain {
}catch(Exception e) {
e.printStackTrace();
}
}
@Test
public void test3() throws Exception {
try {
@@ -61,6 +55,6 @@ public class TestWithSpringMain {
}catch(Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -1,135 +0,0 @@
package com.thebeastshop.liteflow.test.curator;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.cache.NodeCache;
import org.apache.curator.framework.recipes.cache.NodeCacheListener;
import org.apache.curator.framework.recipes.cache.PathChildrenCache;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener;
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

@@ -1,121 +0,0 @@
package com.thebeastshop.liteflow.test.curator;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.recipes.cache.NodeCache;
import org.apache.curator.framework.recipes.cache.NodeCacheListener;
import org.apache.curator.framework.recipes.cache.PathChildrenCache;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener;
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

@@ -1,23 +0,0 @@
package com.thebeastshop.liteflow.test.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);
}
}