新增:zhub-cli 独立分支
This commit is contained in:
63
test/HelloService.java
Normal file
63
test/HelloService.java
Normal file
@@ -0,0 +1,63 @@
|
||||
import com.zdemo.IConsumer;
|
||||
import com.zdemo.zhub.RpcResult;
|
||||
import com.zdemo.zhub.ZHubClient;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
// @RestService(automapping = true)
|
||||
public class HelloService {
|
||||
|
||||
// @Resource(name = "zhub")
|
||||
private ZHubClient zhub;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
|
||||
zhub = new ZHubClient("127.0.0.1:1216", "g-dev", "DEV-LOCAL");
|
||||
//zhub.init(Map.of("host", "47.111.150.118", "port", "6066", "groupid", "g-dev", "appname", "DEV-LOCAL"));
|
||||
|
||||
// Function<Rpc<T>, RpcResult<R>> fun
|
||||
/*zhub.rpcSubscribe("x", new TypeToken<String>() {
|
||||
}, r -> {
|
||||
return r.buildResp(Map.of("v", r.getValue().toUpperCase() + ": Ok"));
|
||||
});
|
||||
|
||||
zhub.subscribe("sport:reqtime", x -> {
|
||||
//System.out.println(x);
|
||||
});
|
||||
zhub.subscribe("abx", x -> {
|
||||
System.out.println(x);
|
||||
});
|
||||
|
||||
try {
|
||||
Thread.sleep(010);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
zhub.delay("sport:reqtime", "别✈人家的✦女娃子❤🤞🏻", 0);
|
||||
zhub.delay("sport:reqtime", "别人家的女娃子➾🤞🏻", 0);
|
||||
zhub.delay("sport:reqtime", "❤别人家✉<E5AEB6>的女娃子❤🤞🏻", 0);*/
|
||||
/*zhub.delay("sport:reqtime", "中文特殊符号:『』 $ £ ♀ ‖ 「」\n" +
|
||||
"英文:# + = & ﹉ .. ^ \"\" ·{ } % – ' €\n" +
|
||||
"数学:+× = - ° ± < > ℃ ㎡ ∑ ≥ ∫ ㏄ ⊥ ≯ ∠ ∴ ∈ ∧ ∵ ≮ ∪ ㎝ ㏑ ≌ ㎞ № § ℉ ÷ % ‰ ㎎ ㎏ ㎜ ㏒ ⊙ ∮ ∝ ∞ º ¹ ² ³ ½ ¾ ¼ ≈ ≡ ≠ ≤ ≦ ≧ ∽ ∷ / ∨ ∏ ∩ ⌒ √Ψ ¤ ‖ ¶\n" +
|
||||
"特殊:♤ ♧ ♡ ♢ ♪ ♬ ♭ ✔ ✘ ♞ ♟ ↪ ↣ ♚ ♛ ♝ ☞ ☜ ⇔ ☆ ★ □ ■ ○ ● △ ▲ ▽ ▼ ◇ ◆ ♀ ♂ ※ ↓ ↑ ↔ ↖ ↙ ↗ ↘ ← → ♣ ♠ ♥ ◎ ◣ ◢ ◤ ◥ 卍 ℡ ⊙ ㊣ ® © ™ ㈱ 囍\n" +
|
||||
"序号:①②③④⑤⑥⑦⑧⑨⑩㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩⑴ ⑵ ⑶ ⑷ ⑸ ⑹ ⑺ ⑻ ⑼ ⑽ ⒈ ⒉ ⒊ ⒋ ⒌ ⒍ ⒎ ⒏ ⒐ ⒑ Ⅰ Ⅱ Ⅲ Ⅳ Ⅴ Ⅵ Ⅶ Ⅷ ⅨⅩ\n" +
|
||||
"日文:アイウエオァィゥェォカキクケコガギグゲゴサシスセソザジズゼゾタチツテトダヂヅデドッナニヌネノハヒフヘホバビブベボパピプペポマミムメモャヤュユョラリヨルレロワヰヱヲンヴヵヶヽヾ゛゜ー、。「「あいうえおぁぃぅぇぉかきくけこがぎぐげごさしすせそざじずぜぞたちつてでどっなにぬねのはひふへ」」ほばびぶべぼぱぴぷぺぽまみむめもやゆよゃゅょらりるれろわをんゎ゛゜ー、。「」\n" +
|
||||
"部首:犭 凵 巛 冖 氵 廴 讠 亻 钅 宀 亠 忄 辶 弋 饣 刂 阝 冫 卩 疒 艹 疋 豸 冂 匸 扌 丬 屮衤 礻 勹 彳 彡", 0);*/
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcTest() {
|
||||
//RpcResult<String> rpc = zhub.rpc("wx:users", Map.of("appId", "wxa554ec3ab3bf1fc7"), IConsumer.TYPE_TOKEN_STRING);
|
||||
RpcResult<String> rpc = zhub.rpc("a", "fa", IConsumer.TYPE_TOKEN_STRING);
|
||||
|
||||
System.out.println(rpc.getResult());
|
||||
}
|
||||
|
||||
/*RpcResult<FileToken> x = zhub.rpc("rpc:file:up-token", Map.of(), new TypeToken<>() {
|
||||
});*/
|
||||
|
||||
|
||||
}
|
@@ -1,450 +0,0 @@
|
||||
package com.zdemo.test;
|
||||
|
||||
import com.zdemo.Event;
|
||||
import com.zdemo.IProducer;
|
||||
import com.zdemo.zhub.Delays;
|
||||
import net.tccn.timer.Timers;
|
||||
import org.junit.Test;
|
||||
import org.redkale.boot.Application;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.DelayQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 消息发布订阅测试
|
||||
*/
|
||||
public class AppTest {
|
||||
Logger logger = Logger.getLogger("");
|
||||
|
||||
@Test
|
||||
public void runConsumer() {
|
||||
try {
|
||||
// String str = ", response = {\"success\":true,\"retcode\":0,\"result\":{\"age\":0,\"explevel\":1,\"face\":\"https://aimg.woaihaoyouxi.com/haogame/202106/pic/20210629095545FmGt-v9NYqyNZ_Q6_y3zM_RMrDgd.jpg\",\"followed\":0,\"gender\":0,\"idenstatus\":0,\"matchcatelist\":[{\"catename\":\"足球\",\"catepic\":\"https://aimg.woaihaoyouxi.com/haogame/202107/pic/20210714103556FoG5ICf_7BFx6Idyo3TYpJQ7tmfG.png\",\"matchcateid\":1},{\"catename\":\"篮球\",\"catepic\":\"https://aimg.woaihaoyouxi.com/haogame/202107/pic/20210714103636FklsXTn1f6Jlsam8Jk-yFB7Upo3C.png\",\"matchcateid\":2}],\"matchcates\":\"2,1\",\"mobile\":\"18515190967\",\"regtime\":1624931714781,\"sessionid\":\"d1fc447753bd4700ad29674a753030fa\",\"status\":10,\"userid\":100463,\"username\":\"绝尘\",\"userno\":100463}}";
|
||||
String str = "hello你好";
|
||||
|
||||
System.out.println(str.length());
|
||||
|
||||
//启动并开启消费监听
|
||||
MyConsumer consumer = Application.singleton(MyConsumer.class);
|
||||
|
||||
consumer.subscribe("a", strx -> {
|
||||
logger.info("我收到了消息 a 事件:" + str);
|
||||
});
|
||||
|
||||
/*consumer.timer("a", () -> {
|
||||
System.out.println(Utility.now() + " timer a 执行了");
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
consumer.timer("b", () -> {
|
||||
System.out.println(Utility.now() + " ----------------- timer b 执行了");
|
||||
});
|
||||
//consumer.delay("a", "1", 200);
|
||||
consumer.delay("a", "1", "2000");*/
|
||||
|
||||
/*Consumer<String> con = x -> {
|
||||
logger.info("--->开始申请锁:" + System.currentTimeMillis());
|
||||
Lock lock = consumer.tryLock("a", 20);
|
||||
logger.info("===>成功申请锁:" + System.currentTimeMillis());
|
||||
for (int i = 0; i < 20; i++) {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println(x + ":" + i);
|
||||
}
|
||||
lock.unLock();
|
||||
};
|
||||
|
||||
new Thread(() -> con.accept("x")).start();
|
||||
new Thread(() -> con.accept("y")).start();
|
||||
new Thread(() -> con.accept("z")).start();*/
|
||||
|
||||
|
||||
Thread.sleep(60_000 * 60);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void runProducer() {
|
||||
try {
|
||||
MyConsumer producer = Application.singleton(MyConsumer.class);
|
||||
for (int i = 0; i < 10_0000; i++) {
|
||||
producer.publish("a-1", i);
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(1_000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static LinkedBlockingQueue<String> queue = new LinkedBlockingQueue();
|
||||
|
||||
@Test
|
||||
public void t() {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.toArray(String[]::new);
|
||||
|
||||
new Thread(() -> {
|
||||
while (true) {
|
||||
System.out.println("accept:");
|
||||
String peek = null;
|
||||
try {
|
||||
System.out.println(!queue.isEmpty());
|
||||
peek = queue.poll(100, TimeUnit.MILLISECONDS);
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println(peek);
|
||||
}
|
||||
}).start();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
try {
|
||||
queue.put(i + "");
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
System.out.println("---");
|
||||
Thread.sleep(1000 * 5);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xx() {
|
||||
Function<String, String> fun = x -> {
|
||||
return x.toUpperCase();
|
||||
};
|
||||
|
||||
System.out.println(fun.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void yy() {
|
||||
IProducer producer = null;
|
||||
try {
|
||||
producer = Application.singleton(MyConsumer.class);
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
|
||||
producer.publish("x", "x");
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// (27+5*23)/(63-59)
|
||||
// [27+5*23] [/] [63-59]
|
||||
// [27] + [5*23] [/] [63-59]
|
||||
|
||||
|
||||
/**
|
||||
* 1. 按照优先级逐一拆解运算
|
||||
* 括号, 乘除,加减
|
||||
* 2. 逐一进行计算
|
||||
*/
|
||||
class C {
|
||||
C A;
|
||||
C B;
|
||||
|
||||
int c1; // 如果 A 只剩数字,将c1 转为整数存放到 c1
|
||||
int c2;
|
||||
String x; // + - * /
|
||||
}
|
||||
|
||||
@Test
|
||||
public void x() {
|
||||
// (27+5*23)/(63-59)
|
||||
|
||||
String str = "(27+5*23)/(63-59)";
|
||||
str = "27+5*23";
|
||||
str = "258/((35+17)/(5*3+18-29)+3)(138-134)*41-6+10+24";
|
||||
str = "5*3+18-29";
|
||||
|
||||
//System.out.println("258/((35+17)/(5*3+18-29)+3)(138-134)*41-6+10+24".replaceAll("\\)\\(", ")*("));
|
||||
List<String> parse = parse(str.replaceAll("\\)\\(", ")\\*("));
|
||||
|
||||
|
||||
System.out.println(c(str));
|
||||
}
|
||||
|
||||
// 因式分解:括号 -> 乘除 -> 加减
|
||||
public List<String> parse(String str) {
|
||||
// 找到一对
|
||||
/*
|
||||
|
||||
258/()()
|
||||
[258, /, (35+17)/(5*3+18-29)+3, 138-134, *, 41, -, 6, +, 10, +, 24]
|
||||
|
||||
*/
|
||||
// 258/((35+17)/(5*3+18-29)+3)(138-134)*41-6+10+24
|
||||
//str = "258 / (35+17)/(5*3+18-29)+3 138-134, * 41-6+10+24";
|
||||
String[] strArr = str.split("");
|
||||
|
||||
// 一级括号、加、减、乘、除分解
|
||||
List<String> arr = new ArrayList<>();
|
||||
String tmp = "";
|
||||
int n1 = 0; // 括号层级开始
|
||||
int m1 = 0; // 括号层级结尾
|
||||
for (String s : strArr) {
|
||||
if (n1 > 0) { // 一级括号分解
|
||||
if (")".equals(s) && (++m1) == n1) { // 一级括号结束
|
||||
arr.add(tmp);
|
||||
tmp = "";
|
||||
n1 = 0;
|
||||
m1 = 0;
|
||||
} else {
|
||||
if ("(".equals(s)) {
|
||||
n1++;
|
||||
}
|
||||
tmp += s;
|
||||
}
|
||||
} else { // 无括号
|
||||
if ("+".equals(s) || "-".equals(s) || "*".equals(s) || "/".equals(s)) {
|
||||
if (!"".equals(tmp)) {
|
||||
arr.add(tmp);
|
||||
}
|
||||
arr.add(s);
|
||||
tmp = "";
|
||||
} else if ("(".equals(s)) {
|
||||
n1 = 1;
|
||||
} else {
|
||||
tmp += s;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!"".equals(tmp)) {
|
||||
arr.add(tmp);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
public int c(String str) {
|
||||
List<String> arr = parse(str); // 预期 length >= 3 基数的基数,如:[27+5*23, /, 63-59], [60, /, 2, *, 164-23*7]
|
||||
System.out.println(arr);
|
||||
if (arr == null || arr.size() < 3) {
|
||||
return -1; // 错误码-1:错误的计算式
|
||||
}
|
||||
|
||||
List<String> _arr = new ArrayList<>();
|
||||
// 按照优先级做合并计算 乘除优先
|
||||
|
||||
// 乘除
|
||||
for (int i = 1; i < arr.size() - 1; i += 2) {
|
||||
/*if ("*".equals(arr.get(i)) || "/".equals(arr.get(i))) {
|
||||
if (_arr.size() > 0) {
|
||||
_arr.remove(_arr.size() - 1);
|
||||
}
|
||||
int c = c(arr.get(i - 1), arr.get(i + 1), arr.get(i));
|
||||
if (c < 0) {
|
||||
return -1;
|
||||
}
|
||||
_arr.add(c + "");
|
||||
} else {
|
||||
_arr.add(arr.get(i - 1));
|
||||
_arr.add(arr.get(i));
|
||||
_arr.add(arr.get(i + 1));
|
||||
}*/
|
||||
|
||||
if ("*".equals(arr.get(i)) || "/".equals(arr.get(i))) {
|
||||
int c = c(arr.get(i - 1), arr.get(i + 1), arr.get(i));
|
||||
if (c < 0) {
|
||||
return c;
|
||||
}
|
||||
_arr.add(c + "");
|
||||
} else {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (_arr.size() == 1) { // 通过第一轮的 乘除计算,完成结果合并
|
||||
return Integer.parseInt(_arr.get(0));
|
||||
}
|
||||
int c = 0;
|
||||
for (int i = 1; i < _arr.size(); i += 2) {
|
||||
int _c = c(_arr.get(i - 1), _arr.get(i + 1), _arr.get(i));
|
||||
if (_c < 0) {
|
||||
return _c;
|
||||
}
|
||||
c += _c;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
public int c(String a, String b, String x) {
|
||||
int _a = 0;
|
||||
if (a.contains("(") || a.contains("+") || a.contains("-") || a.contains("*") || a.contains("/")) {
|
||||
_a = c(a);
|
||||
} else { // 预期 无 ( + - * / 的结果为标准数字
|
||||
_a = Integer.parseInt(a);
|
||||
}
|
||||
int _b = 0;
|
||||
if (b.contains("(") || b.contains("+") || b.contains("-") || b.contains("*") || b.contains("/")) {
|
||||
_b = c(b);
|
||||
} else { // 预期 无 ( + - * / 的结果为标准数字
|
||||
_b = Integer.parseInt(b);
|
||||
}
|
||||
|
||||
// 如果出现负数(错误码)直接返回对应的负数
|
||||
if (_a < 0) {
|
||||
return _a;
|
||||
}
|
||||
if (_b < 0) {
|
||||
return _b;
|
||||
}
|
||||
|
||||
// 定义错误标识: -1错误的计算式,-2除不尽,-3除数为0,-4大于200,
|
||||
if ("+".equals(x)) {
|
||||
return _a + _b;
|
||||
} else if ("-".equals(x)) {
|
||||
return _a - _b;
|
||||
} else if ("*".equals(x)) {
|
||||
return _a * _b;
|
||||
} else if ("/".equals(x)) {
|
||||
return _a % _b > 0 ? -2 : _a / _b; // 除不尽
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testxx() {
|
||||
Event of = Event.of("A", Map.of("b", 1));
|
||||
|
||||
System.out.println(JsonConvert.root().convertTo(of));
|
||||
|
||||
String str = "❦别人家的女娃子🤞🏻ꚢ";
|
||||
|
||||
/*
|
||||
System.out.println("别人家的女娃子🤞🏻".length());*/
|
||||
System.out.println(strLength(str));
|
||||
System.out.println(getWordCount(str));
|
||||
/*try {
|
||||
System.out.println("别人家的女娃子🤞🏻".getBytes("UTF-8").length);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("系统默认编码方式:" + System.getProperty("file.encoding"));*/
|
||||
}
|
||||
|
||||
|
||||
public static int strLength(String value) {
|
||||
int valueLength = 0;
|
||||
String chinese = "[\u4e00-\u9fa5]";
|
||||
for (int i = 0; i < value.length(); i++) {
|
||||
String temp = value.substring(i, i + 1);
|
||||
if (temp.matches(chinese)) {
|
||||
valueLength += 2;
|
||||
} else {
|
||||
valueLength += 1;
|
||||
}
|
||||
}
|
||||
return valueLength;
|
||||
}
|
||||
|
||||
public int getWordCount(String str) {
|
||||
str = str.replaceAll("[^\\x00-\\xff]", "*");
|
||||
return str.length();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delay() {
|
||||
DelayQueue<Delays> delayQueue = new DelayQueue<>();
|
||||
|
||||
logger.info("加入延时任务1");
|
||||
delayQueue.add(new Delays(5000, () -> {
|
||||
logger.info("任务1 延时任务执行了!");
|
||||
}));
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
logger.info("加入延时任务2");
|
||||
delayQueue.add(new Delays(5000, () -> {
|
||||
logger.info("任务2 延时任务执行了!");
|
||||
}));
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
Delays delay = delayQueue.take();
|
||||
|
||||
delay.run();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void regTest() {
|
||||
// 按指定模式在字符串查找
|
||||
String line = "This order was placed for QT3000! OK?";
|
||||
String pattern = "(\\D*)(\\d+)(.*)";
|
||||
|
||||
// 创建 Pattern 对象
|
||||
Pattern r = Pattern.compile(pattern);
|
||||
|
||||
// 现在创建 matcher 对象
|
||||
Matcher m = r.matcher(line);
|
||||
if (m.find()) {
|
||||
System.out.println("Found value: " + m.group(0));
|
||||
System.out.println("Found value: " + m.group(1));
|
||||
System.out.println("Found value: " + m.group(2));
|
||||
System.out.println("Found value: " + m.group(3));
|
||||
} else {
|
||||
System.out.println("NO MATCH");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timersTest() {
|
||||
Timers.tryDelay(() -> {
|
||||
logger.info("xx:" + System.currentTimeMillis());
|
||||
return true;
|
||||
}, 1000, 5);
|
||||
|
||||
Timers.delay(() -> {
|
||||
System.out.println("11");
|
||||
}, 3000);
|
||||
|
||||
try {
|
||||
Thread.sleep(100000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
package com.zdemo.zhub;
|
||||
|
||||
import java.util.concurrent.DelayQueue;
|
||||
import java.util.concurrent.Delayed;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Delays implements Delayed, Runnable {
|
||||
public Logger logger = Logger.getLogger(Delays.class.getSimpleName());
|
||||
|
||||
private long time; // 执行时间
|
||||
private Runnable runnable; // 任务到时间执行 runnable
|
||||
|
||||
public Delays(long timeout, Runnable runnable) {
|
||||
this.time = System.currentTimeMillis() + timeout;
|
||||
this.runnable = runnable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDelay(TimeUnit unit) {
|
||||
return unit.convert(time - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Delayed other) {
|
||||
if (other == this) { // compare zero ONLY if same object
|
||||
return 0;
|
||||
}
|
||||
if (other instanceof Delays) {
|
||||
Delays x = (Delays) other;
|
||||
long diff = time - x.time;
|
||||
if (diff < 0) {
|
||||
return -1;
|
||||
} else if (diff > 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
long d = (getDelay(TimeUnit.NANOSECONDS) -
|
||||
other.getDelay(TimeUnit.NANOSECONDS));
|
||||
return (d == 0) ? 0 : ((d < 0) ? -1 : 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
// ===========
|
||||
public static DelayQueue<Delays> delayQueue = new DelayQueue<>();
|
||||
|
||||
public static void addDelay(long timeout, Runnable runnable) {
|
||||
delayQueue.add(new Delays(timeout, runnable));
|
||||
}
|
||||
|
||||
public static void tryDelay(Supplier<Boolean> supplier, long delayMillis, int maxCount) {
|
||||
|
||||
}
|
||||
|
||||
static {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
while (true) {
|
||||
Delays delay = delayQueue.take();
|
||||
delay.run(); //异常会导致延时队列失败
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
@@ -1,232 +0,0 @@
|
||||
package com.zdemo.test;
|
||||
|
||||
import com.zdemo.IType;
|
||||
import com.zdemo.zhub.RpcResult;
|
||||
import com.zdemo.zhub.ZHubClient;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.net.http.RestService;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.TypeToken;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@RestService(automapping = true)
|
||||
public class HelloService implements Service {
|
||||
|
||||
@Resource(name = "zhub")
|
||||
private ZHubClient zhub;
|
||||
|
||||
private net.tccn.zhub.ZHubClient zhubx = null;
|
||||
|
||||
|
||||
@Override
|
||||
public void init(AnyValue config) {
|
||||
|
||||
CompletableFuture.runAsync(() -> {
|
||||
zhubx = new net.tccn.zhub.ZHubClient("127.0.0.1", 1216, "g-dev", "DEV-LOCAL");
|
||||
//zhubx = new net.tccn.zhub.ZHubClient("47.111.150.118", 6066, "g-dev", "DEV-LOCAL");
|
||||
});
|
||||
|
||||
// Function<Rpc<T>, RpcResult<R>> fun
|
||||
/*zhub.rpcSubscribe("x", new TypeToken<String>() {
|
||||
}, r -> {
|
||||
|
||||
return r.buildResp(Map.of("v", r.getValue().toUpperCase() + ": Ok"));
|
||||
});*/
|
||||
zhub.rpcSubscribe("y", new TypeToken<String>() {
|
||||
}, r -> {
|
||||
|
||||
return r.buildResp(Map.of("v", r.getValue().toUpperCase() + ": Ok"));
|
||||
});
|
||||
|
||||
zhub.subscribe("sport:reqtime", x -> {
|
||||
System.out.println(x);
|
||||
});
|
||||
zhub.subscribe("abx", x -> {
|
||||
System.out.println(x);
|
||||
});
|
||||
|
||||
try {
|
||||
Thread.sleep(010);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
/*zhub.delay("sport:reqtime", "别✈人家的✦女娃子❤🤞🏻", 0);
|
||||
zhub.delay("sport:reqtime", "别人家的女娃子➾🤞🏻", 0);
|
||||
zhub.delay("sport:reqtime", "❤别人家✉<E5AEB6>的女娃子❤🤞🏻", 0);
|
||||
zhub.delay("sport:reqtime", "中文特殊符号:『』 $ £ ♀ ‖ 「」\n" +
|
||||
"英文:# + = & ﹉ .. ^ \"\" ·{ } % – ' €\n" +
|
||||
"数学:+× = - ° ± < > ℃ ㎡ ∑ ≥ ∫ ㏄ ⊥ ≯ ∠ ∴ ∈ ∧ ∵ ≮ ∪ ㎝ ㏑ ≌ ㎞ № § ℉ ÷ % ‰ ㎎ ㎏ ㎜ ㏒ ⊙ ∮ ∝ ∞ º ¹ ² ³ ½ ¾ ¼ ≈ ≡ ≠ ≤ ≦ ≧ ∽ ∷ / ∨ ∏ ∩ ⌒ √Ψ ¤ ‖ ¶\n" +
|
||||
"特殊:♤ ♧ ♡ ♢ ♪ ♬ ♭ ✔ ✘ ♞ ♟ ↪ ↣ ♚ ♛ ♝ ☞ ☜ ⇔ ☆ ★ □ ■ ○ ● △ ▲ ▽ ▼ ◇ ◆ ♀ ♂ ※ ↓ ↑ ↔ ↖ ↙ ↗ ↘ ← → ♣ ♠ ♥ ◎ ◣ ◢ ◤ ◥ 卍 ℡ ⊙ ㊣ ® © ™ ㈱ 囍\n" +
|
||||
"序号:①②③④⑤⑥⑦⑧⑨⑩㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩⑴ ⑵ ⑶ ⑷ ⑸ ⑹ ⑺ ⑻ ⑼ ⑽ ⒈ ⒉ ⒊ ⒋ ⒌ ⒍ ⒎ ⒏ ⒐ ⒑ Ⅰ Ⅱ Ⅲ Ⅳ Ⅴ Ⅵ Ⅶ Ⅷ ⅨⅩ\n" +
|
||||
"日文:アイウエオァィゥェォカキクケコガギグゲゴサシスセソザジズゼゾタチツテトダヂヅデドッナニヌネノハヒフヘホバビブベボパピプペポマミムメモャヤュユョラリヨルレロワヰヱヲンヴヵヶヽヾ゛゜ー、。「「あいうえおぁぃぅぇぉかきくけこがぎぐげごさしすせそざじずぜぞたちつてでどっなにぬねのはひふへ」」ほばびぶべぼぱぴぷぺぽまみむめもやゆよゃゅょらりるれろわをんゎ゛゜ー、。「」\n" +
|
||||
"部首:犭 凵 巛 冖 氵 廴 讠 亻 钅 宀 亠 忄 辶 弋 饣 刂 阝 冫 卩 疒 艹 疋 豸 冂 匸 扌 丬 屮衤 礻 勹 彳 彡", 0);
|
||||
*/
|
||||
}
|
||||
|
||||
@RestMapping
|
||||
public RpcResult x(String v) {
|
||||
if (v == null) {
|
||||
v = "";
|
||||
}
|
||||
|
||||
List<CompletableFuture> list = new ArrayList();
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
long start = System.currentTimeMillis();
|
||||
/*RpcResult<FileToken> x = zhub.rpc("rpc:file:up-token", Map.of(), new TypeToken<>() {
|
||||
});*/
|
||||
|
||||
/*list.add(zhub.rpcAsync("x", v + i, new TypeToken<>() {
|
||||
}));*/
|
||||
zhub.publish("x", v + i);
|
||||
|
||||
System.out.println("time: " + (System.currentTimeMillis() - start) + " ms");
|
||||
//System.out.println(x.getResult().get("v"));
|
||||
}
|
||||
|
||||
return zhub.rpc("x", v, IType.STRING);
|
||||
}
|
||||
|
||||
@RestMapping
|
||||
public RpcResult<String> d(String v) {
|
||||
RpcResult<String> rpc = zhub.rpc("x", v, IType.STRING);
|
||||
return rpc;
|
||||
}
|
||||
|
||||
@RestMapping
|
||||
public String y(String v) {
|
||||
if (v == null) {
|
||||
v = "";
|
||||
}
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
long start = System.currentTimeMillis();
|
||||
/*RpcResult<FileToken> x = zhub.rpc("rpc:file:up-token", Map.of(), new TypeToken<>() {
|
||||
});*/
|
||||
|
||||
net.tccn.zhub.RpcResult<Object> x = zhubx.rpc("y", v + i, new com.google.gson.reflect.TypeToken<>() {
|
||||
});
|
||||
|
||||
System.out.println("time: " + (System.currentTimeMillis() - start) + " ms");
|
||||
|
||||
//System.out.println(x.getResult());
|
||||
}
|
||||
|
||||
return "ok";
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
// "\"别人家的女娃子\uD83E\uDD1E\uD83C\uDFFB\""
|
||||
/*String s = "别人家的女娃子\uD83E\uDD1E\uD83C\uDFFB";
|
||||
System.out.println("别人家的女娃子🤞🏻".length());
|
||||
|
||||
byte[] bytes = "别人家的女娃子🤞🏻".getBytes();
|
||||
System.out.println(bytes.length);
|
||||
|
||||
System.out.println(unicodeToUtf8(s));
|
||||
System.out.println(utf8ToUnicode("别人家的女娃子🤞🏻"));
|
||||
*/
|
||||
|
||||
//ExecutorService pool = Executors.newFixedThreadPool(5);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String utf8ToUnicode(String inStr) {
|
||||
char[] myBuffer = inStr.toCharArray();
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < inStr.length(); i++) {
|
||||
Character.UnicodeBlock ub = Character.UnicodeBlock.of(myBuffer[i]);
|
||||
if (ub == Character.UnicodeBlock.BASIC_LATIN) {
|
||||
//英文及数字等
|
||||
sb.append(myBuffer[i]);
|
||||
} else if (ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
|
||||
//全角半角字符
|
||||
int j = (int) myBuffer[i] - 65248;
|
||||
sb.append((char) j);
|
||||
} else {
|
||||
//汉字
|
||||
short s = (short) myBuffer[i];
|
||||
String hexS = Integer.toHexString(s);
|
||||
String unicode = "\\u" + hexS;
|
||||
sb.append(unicode.toLowerCase());
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String unicodeToUtf8(String theString) {
|
||||
char aChar;
|
||||
int len = theString.length();
|
||||
StringBuffer outBuffer = new StringBuffer(len);
|
||||
for (int x = 0; x < len; ) {
|
||||
aChar = theString.charAt(x++);
|
||||
if (aChar == '\\') {
|
||||
aChar = theString.charAt(x++);
|
||||
if (aChar == 'u') {
|
||||
// Read the xxxx
|
||||
int value = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
aChar = theString.charAt(x++);
|
||||
switch (aChar) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
value = (value << 4) + aChar - '0';
|
||||
break;
|
||||
case 'a':
|
||||
case 'b':
|
||||
case 'c':
|
||||
case 'd':
|
||||
case 'e':
|
||||
case 'f':
|
||||
value = (value << 4) + 10 + aChar - 'a';
|
||||
break;
|
||||
case 'A':
|
||||
case 'B':
|
||||
case 'C':
|
||||
case 'D':
|
||||
case 'E':
|
||||
case 'F':
|
||||
value = (value << 4) + 10 + aChar - 'A';
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
"Malformed \\uxxxx encoding.");
|
||||
}
|
||||
}
|
||||
outBuffer.append((char) value);
|
||||
} else {
|
||||
if (aChar == 't')
|
||||
aChar = '\t';
|
||||
else if (aChar == 'r')
|
||||
aChar = '\r';
|
||||
else if (aChar == 'n')
|
||||
aChar = '\n';
|
||||
else if (aChar == 'f')
|
||||
aChar = '\f';
|
||||
outBuffer.append(aChar);
|
||||
}
|
||||
} else
|
||||
outBuffer.append(aChar);
|
||||
}
|
||||
return outBuffer.toString();
|
||||
}
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
package com.zdemo.test;
|
||||
|
||||
import com.zdemo.zhub.ZHubClient;
|
||||
|
||||
public class MyConsumer extends ZHubClient {
|
||||
|
||||
public String getGroupid() {
|
||||
return "group-test"; //消费组名称
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean preInit() {
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user