Compare commits
4 Commits
ff3d877a37
...
dev/redkal
Author | SHA1 | Date | |
---|---|---|---|
efdf42c4f2 | |||
4d125f8e46 | |||
8a5f1c10e1 | |||
9d23c84cba |
4
pom.xml
4
pom.xml
@@ -4,9 +4,9 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>net.tccn</groupId>
|
<groupId>dev.zhub</groupId>
|
||||||
<artifactId>zhub-client-redkale</artifactId>
|
<artifactId>zhub-client-redkale</artifactId>
|
||||||
<version>0.1.1-dev</version>
|
<version>x.1.1.dev</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
package net.tccn;
|
package dev.zhub;
|
||||||
|
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
import org.redkale.util.Resourcable;
|
import org.redkale.util.Resourcable;
|
@@ -1,4 +1,4 @@
|
|||||||
package net.tccn;
|
package dev.zhub;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发布订阅 事件
|
* 发布订阅 事件
|
@@ -1,4 +1,4 @@
|
|||||||
package net.tccn;
|
package dev.zhub;
|
||||||
|
|
||||||
import org.redkale.util.TypeToken;
|
import org.redkale.util.TypeToken;
|
||||||
|
|
@@ -1,4 +1,4 @@
|
|||||||
package net.tccn;
|
package dev.zhub;
|
||||||
|
|
||||||
import org.redkale.util.TypeToken;
|
import org.redkale.util.TypeToken;
|
||||||
|
|
@@ -1,4 +1,4 @@
|
|||||||
package net.tccn;
|
package dev.zhub;
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
@@ -1,4 +1,4 @@
|
|||||||
package net.tccn;
|
package dev.zhub;
|
||||||
|
|
||||||
import org.redkale.util.TypeToken;
|
import org.redkale.util.TypeToken;
|
||||||
|
|
@@ -1,4 +1,4 @@
|
|||||||
package net.tccn;
|
package dev.zhub;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.redkale.net.AsyncIOGroup;
|
import org.redkale.net.AsyncIOGroup;
|
@@ -1,4 +1,4 @@
|
|||||||
package net.tccn;
|
package dev.zhub;
|
||||||
|
|
||||||
import org.redkale.boot.Application;
|
import org.redkale.boot.Application;
|
||||||
import org.redkale.boot.NodeServer;
|
import org.redkale.boot.NodeServer;
|
||||||
@@ -8,7 +8,6 @@ import org.redkale.service.Service;
|
|||||||
import org.redkale.util.ResourceEvent;
|
import org.redkale.util.ResourceEvent;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
@@ -1,6 +1,6 @@
|
|||||||
package net.tccn;
|
package dev.zhub;
|
||||||
|
|
||||||
import net.tccn.zhub.ZHubClient;
|
import dev.zhub.client.ZHubClient;
|
||||||
import org.redkale.annotation.Priority;
|
import org.redkale.annotation.Priority;
|
||||||
import org.redkale.cluster.ClusterAgent;
|
import org.redkale.cluster.ClusterAgent;
|
||||||
import org.redkale.cluster.ClusterAgentProvider;
|
import org.redkale.cluster.ClusterAgentProvider;
|
@@ -1,4 +1,4 @@
|
|||||||
package net.tccn.zhub;
|
package dev.zhub.client;
|
||||||
|
|
||||||
// ================================================== lock ==================================================
|
// ================================================== lock ==================================================
|
||||||
public class Lock {
|
public class Lock {
|
@@ -1,7 +1,9 @@
|
|||||||
package net.tccn.zhub;
|
package dev.zhub.client;
|
||||||
|
|
||||||
import org.redkale.convert.ConvertColumn;
|
import org.redkale.convert.ConvertColumn;
|
||||||
import org.redkale.service.RetResult;
|
import org.redkale.service.RetResult;
|
||||||
|
import org.redkale.util.TypeToken;
|
||||||
|
import org.redkale.util.Utility;
|
||||||
|
|
||||||
public class Rpc<T> {
|
public class Rpc<T> {
|
||||||
private String ruk; // request unique key:
|
private String ruk; // request unique key:
|
||||||
@@ -10,11 +12,13 @@ public class Rpc<T> {
|
|||||||
|
|
||||||
private RpcResult rpcResult;
|
private RpcResult rpcResult;
|
||||||
|
|
||||||
|
private TypeToken typeToken;
|
||||||
|
|
||||||
public Rpc() {
|
public Rpc() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Rpc(String appname, String ruk, String topic, T value) {
|
protected Rpc(String appname, String topic, T value) {
|
||||||
this.ruk = appname + "::" + ruk;
|
this.ruk = appname + "::" + Utility.uuid();
|
||||||
this.topic = topic;
|
this.topic = topic;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
@@ -52,6 +56,16 @@ public class Rpc<T> {
|
|||||||
this.rpcResult = rpcResult;
|
this.rpcResult = rpcResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConvertColumn(ignore = true)
|
||||||
|
public TypeToken getTypeToken() {
|
||||||
|
return typeToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConvertColumn(ignore = true)
|
||||||
|
public void setTypeToken(TypeToken typeToken) {
|
||||||
|
this.typeToken = typeToken;
|
||||||
|
}
|
||||||
|
|
||||||
@ConvertColumn(ignore = true)
|
@ConvertColumn(ignore = true)
|
||||||
public String getBackTopic() {
|
public String getBackTopic() {
|
||||||
return ruk.split("::")[0];
|
return ruk.split("::")[0];
|
@@ -1,4 +1,4 @@
|
|||||||
package net.tccn.zhub;
|
package dev.zhub.client;
|
||||||
|
|
||||||
public class RpcResult<R> {
|
public class RpcResult<R> {
|
||||||
private String ruk;
|
private String ruk;
|
@@ -1,7 +1,7 @@
|
|||||||
package net.tccn.zhub;
|
package dev.zhub.client;
|
||||||
|
|
||||||
import net.tccn.*;
|
import dev.zhub.*;
|
||||||
import net.tccn.timer.Timers;
|
import dev.zhub.timer.Timers;
|
||||||
import org.redkale.annotation.AutoLoad;
|
import org.redkale.annotation.AutoLoad;
|
||||||
import org.redkale.annotation.ResourceType;
|
import org.redkale.annotation.ResourceType;
|
||||||
import org.redkale.service.Local;
|
import org.redkale.service.Local;
|
||||||
@@ -9,7 +9,6 @@ import org.redkale.service.Service;
|
|||||||
import org.redkale.util.AnyValue;
|
import org.redkale.util.AnyValue;
|
||||||
import org.redkale.util.Comment;
|
import org.redkale.util.Comment;
|
||||||
import org.redkale.util.TypeToken;
|
import org.redkale.util.TypeToken;
|
||||||
import org.redkale.util.Utility;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -100,12 +99,11 @@ public class ZHubClient extends AbstractConsumer implements IConsumer, IProducer
|
|||||||
}
|
}
|
||||||
|
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
|
if (!initSocket(0)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 消息 事件接收
|
// 消息 事件接收
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
if (!initSocket(0)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
String readLine = reader.readLine();
|
String readLine = reader.readLine();
|
||||||
@@ -410,7 +408,7 @@ public class ZHubClient extends AbstractConsumer implements IConsumer, IProducer
|
|||||||
send("auth", auth);
|
send("auth", auth);
|
||||||
send("groupid " + groupid);
|
send("groupid " + groupid);
|
||||||
|
|
||||||
StringBuffer buf = new StringBuffer("subscribe lock trylock");
|
StringBuilder buf = new StringBuilder("subscribe lock trylock");
|
||||||
if (mainHub.containsValue(this)) {
|
if (mainHub.containsValue(this)) {
|
||||||
buf.append(" " + APP_NAME);
|
buf.append(" " + APP_NAME);
|
||||||
}
|
}
|
||||||
@@ -424,9 +422,9 @@ public class ZHubClient extends AbstractConsumer implements IConsumer, IProducer
|
|||||||
send("timer", name);
|
send("timer", name);
|
||||||
});
|
});
|
||||||
if (retry > 0) {
|
if (retry > 0) {
|
||||||
logger.warning(String.format("ZHubClient[%s][%s] %s Succeed!", getGroupid(), i + 1, retry > 0 ? "reconnection" : "init"));
|
logger.warning(String.format("ZHubClient[%s][%s] %s Succeed!", getGroupid(), i + 1, "reconnection"));
|
||||||
} else {
|
} else {
|
||||||
logger.fine(String.format("ZHubClient[%s] %s Succeed!", getGroupid(), retry > 0 ? "reconnection" : "init"));
|
logger.fine(String.format("ZHubClient[%s] %s Succeed!", getGroupid(), "init"));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -594,7 +592,6 @@ public class ZHubClient extends AbstractConsumer implements IConsumer, IProducer
|
|||||||
// ================================================== rpc ==================================================
|
// ================================================== rpc ==================================================
|
||||||
// -- 调用端 --
|
// -- 调用端 --
|
||||||
private static Map<String, Rpc> rpcMap = new ConcurrentHashMap<>();
|
private static Map<String, Rpc> rpcMap = new ConcurrentHashMap<>();
|
||||||
private static Map<String, TypeToken> rpcRetType = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
@Comment("rpc call")
|
@Comment("rpc call")
|
||||||
public RpcResult<Void> rpc(String topic, Object v) {
|
public RpcResult<Void> rpc(String topic, Object v) {
|
||||||
@@ -608,12 +605,11 @@ public class ZHubClient extends AbstractConsumer implements IConsumer, IProducer
|
|||||||
|
|
||||||
@Comment("rpc call")
|
@Comment("rpc call")
|
||||||
public <T, R> RpcResult<R> rpc(String topic, T v, TypeToken<R> typeToken, long timeout) {
|
public <T, R> RpcResult<R> rpc(String topic, T v, TypeToken<R> typeToken, long timeout) {
|
||||||
Rpc rpc = new Rpc<>(APP_NAME, Utility.uuid(), topic, v);
|
Rpc rpc = new Rpc<>(APP_NAME, topic, v);
|
||||||
|
rpc.setTypeToken(typeToken);
|
||||||
|
|
||||||
String ruk = rpc.getRuk();
|
String ruk = rpc.getRuk();
|
||||||
rpcMap.put(ruk, rpc);
|
rpcMap.put(ruk, rpc);
|
||||||
if (typeToken != null) {
|
|
||||||
rpcRetType.put(ruk, typeToken);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
if (eventMap.containsKey(topic)) { // 本地调用
|
if (eventMap.containsKey(topic)) { // 本地调用
|
||||||
rpcCallQueue.add(Event.of(topic, rpc));
|
rpcCallQueue.add(Event.of(topic, rpc));
|
||||||
@@ -671,10 +667,21 @@ public class ZHubClient extends AbstractConsumer implements IConsumer, IProducer
|
|||||||
// RpcResult: {ruk:xxx-xxxx, retcode:0}
|
// RpcResult: {ruk:xxx-xxxx, retcode:0}
|
||||||
@Comment("rpc call back consumer")
|
@Comment("rpc call back consumer")
|
||||||
private <T> void rpcAccept(T value) {
|
private <T> void rpcAccept(T value) {
|
||||||
// 接收到 本地调用返回的 RpcResult TODO, 本地模式下返回的数据对象类型需要和处理端一致,不然会出现类型转换异常 - 解决办法,当出现不一致的情况取数据做转换
|
// 接收到 本地调用返回的 RpcResult
|
||||||
if (value instanceof RpcResult) {
|
if (value instanceof RpcResult) {
|
||||||
String ruk = ((RpcResult) value).getRuk();
|
String ruk = ((RpcResult) value).getRuk();
|
||||||
Rpc rpc = rpcMap.remove(ruk);
|
Rpc rpc = rpcMap.remove(ruk);
|
||||||
|
if (rpc == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 本地模式下返回的数据对象类型需要和处理端一致,不然会出现类型转换异常 - 解决办法,当出现不一致的情况取数据做转换
|
||||||
|
TypeToken typeToken = rpc.getTypeToken();
|
||||||
|
if (typeToken.getType() != ((RpcResult<?>) value).getResult().getClass()) {
|
||||||
|
Object result = convert.convertFrom(typeToken.getType(), toStr(((RpcResult<?>) value).getResult()));
|
||||||
|
((RpcResult<Object>) value).setResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
rpc.setRpcResult((RpcResult) value);
|
rpc.setRpcResult((RpcResult) value);
|
||||||
synchronized (rpc) {
|
synchronized (rpc) {
|
||||||
rpc.notify();
|
rpc.notify();
|
||||||
@@ -690,7 +697,7 @@ public class ZHubClient extends AbstractConsumer implements IConsumer, IProducer
|
|||||||
if (rpc == null) {
|
if (rpc == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TypeToken typeToken = rpcRetType.get(ruk);
|
TypeToken typeToken = rpc.getTypeToken();
|
||||||
|
|
||||||
Object result = resp.getResult();
|
Object result = resp.getResult();
|
||||||
if (result != null && typeToken != null && !"java.lang.String".equals(typeToken.getType().getTypeName()) && !"java.lang.Void".equals(typeToken.getType().getTypeName())) {
|
if (result != null && typeToken != null && !"java.lang.String".equals(typeToken.getType().getTypeName()) && !"java.lang.Void".equals(typeToken.getType().getTypeName())) {
|
||||||
@@ -718,7 +725,8 @@ public class ZHubClient extends AbstractConsumer implements IConsumer, IProducer
|
|||||||
Rpc<T> rpc = null;
|
Rpc<T> rpc = null;
|
||||||
try {
|
try {
|
||||||
if (v instanceof String) {
|
if (v instanceof String) {
|
||||||
rpc = convert.convertFrom(IType.STRING.getType(), (String) v);
|
rpc = convert.convertFrom(new TypeToken<Rpc<String>>() {
|
||||||
|
}.getType(), (String) v);
|
||||||
} else {
|
} else {
|
||||||
rpc = (Rpc<T>) v;
|
rpc = (Rpc<T>) v;
|
||||||
}
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
package net.tccn.timer;
|
package dev.zhub.timer;
|
||||||
|
|
||||||
import net.tccn.timer.queue.TimerQueue;
|
import dev.zhub.timer.queue.TimerQueue;
|
||||||
import net.tccn.timer.task.Task;
|
import dev.zhub.timer.task.Task;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
@@ -1,8 +1,8 @@
|
|||||||
package net.tccn.timer;
|
package dev.zhub.timer;
|
||||||
|
|
||||||
import net.tccn.timer.scheduled.Scheduled;
|
import dev.zhub.timer.scheduled.Scheduled;
|
||||||
import net.tccn.timer.task.Job;
|
import dev.zhub.timer.task.Job;
|
||||||
import net.tccn.timer.task.Task;
|
import dev.zhub.timer.task.Task;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
@@ -1,6 +1,6 @@
|
|||||||
package net.tccn.timer;
|
package dev.zhub.timer;
|
||||||
|
|
||||||
import net.tccn.timer.scheduled.ScheduledCycle;
|
import dev.zhub.timer.scheduled.ScheduledCycle;
|
||||||
import org.redkale.util.Utility;
|
import org.redkale.util.Utility;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
@@ -1,6 +1,6 @@
|
|||||||
package net.tccn.timer.queue;
|
package dev.zhub.timer.queue;
|
||||||
|
|
||||||
import net.tccn.timer.task.Task;
|
import dev.zhub.timer.task.Task;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
@@ -1,4 +1,4 @@
|
|||||||
package net.tccn.timer.scheduled;
|
package dev.zhub.timer.scheduled;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
@@ -1,4 +1,4 @@
|
|||||||
package net.tccn.timer.scheduled;
|
package dev.zhub.timer.scheduled;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
@@ -1,4 +1,4 @@
|
|||||||
package net.tccn.timer.scheduled;
|
package dev.zhub.timer.scheduled;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
@@ -1,4 +1,4 @@
|
|||||||
package net.tccn.timer.task;
|
package dev.zhub.timer.task;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: liangxianyou at 2018/12/8 17:24.
|
* @author: liangxianyou at 2018/12/8 17:24.
|
@@ -1,7 +1,7 @@
|
|||||||
package net.tccn.timer.task;
|
package dev.zhub.timer.task;
|
||||||
|
|
||||||
import net.tccn.timer.TimerExecutor;
|
import dev.zhub.timer.TimerExecutor;
|
||||||
import net.tccn.timer.scheduled.Scheduled;
|
import dev.zhub.timer.scheduled.Scheduled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: liangxianyou at 2018/8/5 19:32.
|
* @author: liangxianyou at 2018/8/5 19:32.
|
@@ -1 +1 @@
|
|||||||
net.tccn.ZhubProvider
|
dev.zhub.ZhubProvider
|
@@ -1,7 +1,7 @@
|
|||||||
package net.tccn.mq;
|
package net.tccn.mq;
|
||||||
|
|
||||||
import net.tccn.Event;
|
import net.tccn.Event;
|
||||||
import net.tccn.timer.Timers;
|
import dev.zhub.timer.Timers;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
|
|
||||||
|
@@ -27,15 +27,15 @@ public class HelloService implements Service {
|
|||||||
@Resource(name = "vvvvhub2")
|
@Resource(name = "vvvvhub2")
|
||||||
private ZHubClient zhub2;*/
|
private ZHubClient zhub2;*/
|
||||||
|
|
||||||
//private net.tccn.zhub.ZHubClient zhubx = null;
|
//private dev.zhub.client.ZHubClient zhubx = null;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(AnyValue config) {
|
public void init(AnyValue config) {
|
||||||
|
|
||||||
/*CompletableFuture.runAsync(() -> {
|
/*CompletableFuture.runAsync(() -> {
|
||||||
zhubx = new net.tccn.zhub.ZHubClient("127.0.0.1", 1216, "g-dev", "DEV-LOCAL");
|
zhubx = new dev.zhub.client.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");
|
//zhubx = new dev.zhub.client.ZHubClient("47.111.150.118", 6066, "g-dev", "DEV-LOCAL");
|
||||||
});*/
|
});*/
|
||||||
|
|
||||||
// Function<Rpc<T>, RpcResult<R>> fun
|
// Function<Rpc<T>, RpcResult<R>> fun
|
||||||
|
Reference in New Issue
Block a user