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