TCP数据包优化
This commit is contained in:
@@ -50,6 +50,7 @@ public class AgentDecoderHandler extends ChannelInboundHandlerAdapter {
|
|||||||
AssertLog.info("<<[up1]:IP:{},[up-content]==>{}", sessionManager.client(ctx),messages);
|
AssertLog.info("<<[up1]:IP:{},[up-content]==>{}", sessionManager.client(ctx),messages);
|
||||||
|
|
||||||
String content = "";
|
String content = "";
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
boolean isClear = false;
|
boolean isClear = false;
|
||||||
String tempMsg = lruCache.get(sessionManager.client(ctx));
|
String tempMsg = lruCache.get(sessionManager.client(ctx));
|
||||||
tempMsg = tempMsg == null ? "" : tempMsg;
|
tempMsg = tempMsg == null ? "" : tempMsg;
|
||||||
@@ -66,11 +67,13 @@ public class AgentDecoderHandler extends ChannelInboundHandlerAdapter {
|
|||||||
if(endsWith){
|
if(endsWith){
|
||||||
lruCache.remove(sessionManager.client(ctx));
|
lruCache.remove(sessionManager.client(ctx));
|
||||||
tmpMsgSize = 0;
|
tmpMsgSize = 0;
|
||||||
content = arr_msg[0]+"@tong-ran";
|
sb.append(arr_msg[0]+"@tong-ran");
|
||||||
|
// content = arr_msg[0]+"@tong-ran";
|
||||||
}else{
|
}else{
|
||||||
lruCache.remove(sessionManager.client(ctx));
|
lruCache.remove(sessionManager.client(ctx));
|
||||||
tmpMsgSize = 0;
|
tmpMsgSize = 0;
|
||||||
content = arr_msg[0];
|
sb.append(arr_msg[0]);
|
||||||
|
// content = arr_msg[0];
|
||||||
lruCache.put(sessionManager.client(ctx), content, DateUnit.SECOND.getMillis() * 3000);
|
lruCache.put(sessionManager.client(ctx), content, DateUnit.SECOND.getMillis() * 3000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,15 +82,23 @@ public class AgentDecoderHandler extends ChannelInboundHandlerAdapter {
|
|||||||
if(!endsWith){
|
if(!endsWith){
|
||||||
lruCache.remove(sessionManager.client(ctx));
|
lruCache.remove(sessionManager.client(ctx));
|
||||||
tmpMsgSize = 0;
|
tmpMsgSize = 0;
|
||||||
content = arr_msg[0]+"@tong-ran";
|
for (int i = 0; i < arr_msg.length; i++) {
|
||||||
lruCache.put(sessionManager.client(ctx), arr_msg[1], DateUnit.SECOND.getMillis() * 3000);
|
if(i == arr_msg.length -1){
|
||||||
|
lruCache.put(sessionManager.client(ctx), arr_msg[i], DateUnit.SECOND.getMillis() * 5000);
|
||||||
|
}else{
|
||||||
|
sb.append(arr_msg[i].replaceAll("agent-server:","")+"@tong-ran");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
lruCache.remove(sessionManager.client(ctx));
|
lruCache.remove(sessionManager.client(ctx));
|
||||||
tmpMsgSize = 0;
|
tmpMsgSize = 0;
|
||||||
content = String.join("@tong-ran", arr_msg);
|
sb.append(String.join("@tong-ran", arr_msg));
|
||||||
|
// content = String.join("@tong-ran", arr_msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
content = sb.toString();
|
||||||
if (tmpMsgSize > 0) {
|
if (tmpMsgSize > 0) {
|
||||||
content = tempMsg + messages;
|
content = tempMsg + messages;
|
||||||
endsWith = content.endsWith("@tong-ran");
|
endsWith = content.endsWith("@tong-ran");
|
||||||
@@ -95,16 +106,16 @@ public class AgentDecoderHandler extends ChannelInboundHandlerAdapter {
|
|||||||
isClear = true;
|
isClear = true;
|
||||||
}else{
|
}else{
|
||||||
lruCache.remove(sessionManager.client(ctx));
|
lruCache.remove(sessionManager.client(ctx));
|
||||||
tmpMsgSize = 0;
|
|
||||||
lruCache.put(sessionManager.client(ctx), content, DateUnit.SECOND.getMillis() * 3000);
|
lruCache.put(sessionManager.client(ctx), content, DateUnit.SECOND.getMillis() * 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
AssertLog.info("<<[up2]:IP:{},[up-content]==>{}", sessionManager.client(ctx),content);
|
AssertLog.info("<<[up2]:IP:{},[up-content]==>{}", sessionManager.client(ctx),content);
|
||||||
endsWith = content.endsWith("@tong-ran");
|
endsWith = content.endsWith("@tong-ran");
|
||||||
//判断是否是整包
|
//判断是否是整包
|
||||||
if(endsWith){
|
if(endsWith){
|
||||||
|
content = content.replaceAll("agent-server:","");
|
||||||
String[] arr = content.split("@tong-ran");
|
String[] arr = content.split("@tong-ran");
|
||||||
|
try {
|
||||||
for (String message : arr) {
|
for (String message : arr) {
|
||||||
JSONObject jsonObject = JSONObject.parseObject(message);
|
JSONObject jsonObject = JSONObject.parseObject(message);
|
||||||
String clientId = jsonObject.getString("clientId");
|
String clientId = jsonObject.getString("clientId");
|
||||||
@@ -123,6 +134,9 @@ public class AgentDecoderHandler extends ChannelInboundHandlerAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
AssertLog.error("=====channelRead:{}=====" + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isClear) {
|
if (isClear) {
|
||||||
lruCache.remove(sessionManager.client(ctx));
|
lruCache.remove(sessionManager.client(ctx));
|
||||||
|
|||||||
Reference in New Issue
Block a user