[*] 日常优化
This commit is contained in:
@@ -17,8 +17,6 @@ import com.acgist.taoyao.boot.model.MessageCodeException;
|
|||||||
import com.acgist.taoyao.signal.client.ClientAdapter;
|
import com.acgist.taoyao.signal.client.ClientAdapter;
|
||||||
import com.acgist.taoyao.signal.utils.CipherUtils;
|
import com.acgist.taoyao.signal.utils.CipherUtils;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,8 +25,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
* @author acgist
|
* @author acgist
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class SocketClient extends ClientAdapter<AsynchronousSocketChannel> {
|
public class SocketClient extends ClientAdapter<AsynchronousSocketChannel> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ public final class SocketSignalMessageHandler implements CompletionHandler<Integ
|
|||||||
final String message = this.decrypt(bytes);
|
final String message = this.decrypt(bytes);
|
||||||
log.debug("Socket信令消息:{} - {}", this.channel, message);
|
log.debug("Socket信令消息:{} - {}", this.channel, message);
|
||||||
// 处理
|
// 处理
|
||||||
this.execute(message.strip());
|
this.execute(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import com.acgist.taoyao.boot.model.Message;
|
|||||||
import com.acgist.taoyao.signal.client.ClientAdapter;
|
import com.acgist.taoyao.signal.client.ClientAdapter;
|
||||||
|
|
||||||
import jakarta.websocket.Session;
|
import jakarta.websocket.Session;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,8 +13,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
* @author acgist
|
* @author acgist
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class WebSocketClient extends ClientAdapter<Session> {
|
public class WebSocketClient extends ClientAdapter<Session> {
|
||||||
|
|
||||||
public WebSocketClient(long timeout, Session instance) {
|
public WebSocketClient(long timeout, Session instance) {
|
||||||
|
|||||||
@@ -37,11 +37,11 @@ public class WebSocketSignal {
|
|||||||
|
|
||||||
@OnMessage
|
@OnMessage
|
||||||
public void message(Session session, String message) {
|
public void message(Session session, String message) {
|
||||||
log.debug("WebSocket信令消息:{}-{}", session, message);
|
log.debug("WebSocket信令消息:{} - {}", session, message);
|
||||||
try {
|
try {
|
||||||
WebSocketSignal.protocolManager.execute(message.strip(), session);
|
WebSocketSignal.protocolManager.execute(message, session);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("处理WebSocket信令消息异常:{}-{}", WebSocketSignal.clientManager.clients(session), message, e);
|
log.error("处理WebSocket信令消息异常:{} - {}", WebSocketSignal.clientManager.clients(session), message, e);
|
||||||
WebSocketSignal.clientManager.push(session, WebSocketSignal.platformErrorProtocol.build(e));
|
WebSocketSignal.clientManager.push(session, WebSocketSignal.platformErrorProtocol.build(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ public class WebSocketSignal {
|
|||||||
@OnError
|
@OnError
|
||||||
public void error(Session session, Throwable e) {
|
public void error(Session session, Throwable e) {
|
||||||
log.error("WebSocket信令终端异常:{}", session, e);
|
log.error("WebSocket信令终端异常:{}", session, e);
|
||||||
this.close(session);
|
WebSocketSignal.clientManager.close(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class WebSocketSignalConfigurator extends ServerEndpointConfig.Configurat
|
|||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
config.getUserProperties().put(Constant.IP, ((RequestFacade) field.get(request)).getRemoteAddr());
|
config.getUserProperties().put(Constant.IP, ((RequestFacade) field.get(request)).getRemoteAddr());
|
||||||
} catch (SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
|
} catch (SecurityException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
|
||||||
throw MessageCodeException.of(e, "无效终端(IP):" + request);
|
throw MessageCodeException.of(e, "无效终端IP:" + request);
|
||||||
}
|
}
|
||||||
super.modifyHandshake(config, request, response);
|
super.modifyHandshake(config, request, response);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,13 +41,13 @@ public class ProtocolController {
|
|||||||
|
|
||||||
```
|
```
|
||||||
{
|
{
|
||||||
|
"code" : "状态编码",
|
||||||
|
"message": "状态描述",
|
||||||
"header": {
|
"header": {
|
||||||
"v": "消息版本",
|
"v" : "消息版本",
|
||||||
"id": "消息标识",
|
"id" : "消息标识",
|
||||||
"signal": "信令标识"
|
"signal": "信令标识"
|
||||||
},
|
},
|
||||||
"code": "状态编码",
|
|
||||||
"message": "状态描述",
|
|
||||||
"body": {
|
"body": {
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ public class ProtocolController {
|
|||||||
...:其他自定义的透传内容
|
...:其他自定义的透传内容
|
||||||
```
|
```
|
||||||
|
|
||||||
> 没有指定消息类型时表示和信令消息类型相同
|
> 消息类型可以省略表示和前面一致
|
||||||
|
|
||||||
""");
|
""");
|
||||||
this.applicationContext.getBeansOfType(Protocol.class).entrySet().stream()
|
this.applicationContext.getBeansOfType(Protocol.class).entrySet().stream()
|
||||||
@@ -75,38 +75,49 @@ public class ProtocolController {
|
|||||||
final String name = protocol.name();
|
final String name = protocol.name();
|
||||||
final String signal = protocol.signal();
|
final String signal = protocol.signal();
|
||||||
final Class<?> clazz;
|
final Class<?> clazz;
|
||||||
final Description description;
|
if(
|
||||||
if(AopUtils.isAopProxy(e) || AopUtils.isCglibProxy(protocol) || AopUtils.isJdkDynamicProxy(protocol)) {
|
AopUtils.isAopProxy(e) ||
|
||||||
|
AopUtils.isCglibProxy(protocol) ||
|
||||||
|
AopUtils.isJdkDynamicProxy(protocol)
|
||||||
|
) {
|
||||||
// 代理获取
|
// 代理获取
|
||||||
clazz = AopUtils.getTargetClass(protocol);
|
clazz = AopUtils.getTargetClass(protocol);
|
||||||
description = AnnotationUtils.findAnnotation(clazz, Description.class);
|
|
||||||
} else {
|
} else {
|
||||||
// 直接获取
|
// 直接获取
|
||||||
clazz = protocol.getClass();
|
clazz = protocol.getClass();
|
||||||
description = AnnotationUtils.findAnnotation(clazz, Description.class);
|
|
||||||
}
|
}
|
||||||
|
final Description description = AnnotationUtils.findAnnotation(clazz, Description.class);
|
||||||
if(description == null) {
|
if(description == null) {
|
||||||
log.info("信令没有注解:{} - {}", key, name);
|
log.info("信令没有注解:{} - {}", key, name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 信令名称
|
// 信令名称
|
||||||
builder.append("### ").append(name)
|
builder
|
||||||
|
.append("### ").append(name)
|
||||||
.append("(").append(signal).append(")")
|
.append("(").append(signal).append(")")
|
||||||
.append(newLine).append(newLine);
|
.append(newLine).append(newLine);
|
||||||
// 描述信息
|
// 描述信息
|
||||||
final String memo = description.memo().strip();
|
final String memo = description.memo().strip();
|
||||||
if(StringUtils.isNotEmpty(memo)) {
|
if(StringUtils.isNotEmpty(memo)) {
|
||||||
builder.append(memo).append(newLine).append(newLine);
|
builder
|
||||||
|
.append(memo)
|
||||||
|
.append(newLine).append(newLine);
|
||||||
}
|
}
|
||||||
// 消息主体
|
// 消息主体
|
||||||
builder
|
builder
|
||||||
.append("```").append(newLine)
|
.append("```")
|
||||||
.append("# 消息主体").append(newLine);
|
.append(newLine)
|
||||||
|
.append("# 消息主体")
|
||||||
|
.append(newLine);
|
||||||
Stream.of(description.body()).forEach(line -> builder.append(line.strip()).append(newLine));
|
Stream.of(description.body()).forEach(line -> builder.append(line.strip()).append(newLine));
|
||||||
// 数据流向
|
// 数据流向
|
||||||
builder.append("# 数据流向").append(newLine);
|
builder
|
||||||
|
.append("# 数据流向")
|
||||||
|
.append(newLine);
|
||||||
Stream.of(description.flow()).forEach(line -> builder.append(line.strip()).append(newLine));
|
Stream.of(description.flow()).forEach(line -> builder.append(line.strip()).append(newLine));
|
||||||
builder.append("```").append(newLine).append(newLine);
|
builder
|
||||||
|
.append("```")
|
||||||
|
.append(newLine).append(newLine);
|
||||||
});
|
});
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ public class ApplicationEventAdapter extends ApplicationEvent {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息
|
* 信令消息
|
||||||
*/
|
*/
|
||||||
private final Message message;
|
private final Message message;
|
||||||
/**
|
/**
|
||||||
* 主体
|
* 信令主体
|
||||||
*/
|
*/
|
||||||
private final Map<String, Object> body;
|
private final Map<String, Object> body;
|
||||||
|
|
||||||
@@ -55,6 +55,13 @@ public class ApplicationEventAdapter extends ApplicationEvent {
|
|||||||
return MapUtils.getLong(this.body, key);
|
return MapUtils.getLong(this.body, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see MapUtils#getDouble(Map, String)
|
||||||
|
*/
|
||||||
|
public Double getDouble(String key) {
|
||||||
|
return MapUtils.getDouble(this.body, key);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see MapUtils#getInteger(Map, String)
|
* @see MapUtils#getInteger(Map, String)
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user