Skip to content

Commit 6bd1629

Browse files
committed
修复一些idea给出的建议问题
1 parent 65a22ef commit 6bd1629

File tree

7 files changed

+28
-45
lines changed

7 files changed

+28
-45
lines changed

run/src/main/java/org/wowtools/hppt/common/client/ClientTalker.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public static boolean receiveServerBytes(CommonConfig config, byte[] responseBod
134134
if (null != sessionIdCallBack) {
135135
sessionIdCallBack.cb(sessionId);
136136
} else {
137-
log.warn("没有对应的SessionIdCallBack {}", sessionIdCallBack);
137+
log.warn("没有对应的SessionIdCallBack {}", sessionId);
138138
}
139139
}
140140
case Constant.ScCommands.CloseSession -> {

run/src/main/java/org/wowtools/hppt/common/pojo/SendAbleSessionBytes.java

+4-10
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@
22

33
/**
44
* 可发送的SessionBytes,被发送后会触发回调函数并告知是否成功
5+
*
56
* @author liuyu
67
* @date 2024/10/20
78
*/
8-
public class SendAbleSessionBytes {
9-
public interface CallBack{
9+
public record SendAbleSessionBytes(SessionBytes sessionBytes,
10+
org.wowtools.hppt.common.pojo.SendAbleSessionBytes.CallBack callBack) {
11+
public interface CallBack {
1012
void cb(boolean success);
1113
}
1214

13-
public final SessionBytes sessionBytes;
14-
15-
public final CallBack callBack;
16-
17-
public SendAbleSessionBytes(SessionBytes sessionBytes, CallBack callBack) {
18-
this.sessionBytes = sessionBytes;
19-
this.callBack = callBack;
20-
}
2115
}

run/src/main/java/org/wowtools/hppt/common/server/LoginClientService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private static List<SendAbleSessionBytes> merge(List<SendAbleSessionBytes> bytes
159159
SessionBytes sessionBytes = new SessionBytes(sessionId, BytesUtil.merge(mergeCell.bytesList));
160160
SendAbleSessionBytes.CallBack callBack;
161161
if (mergeCell.callBacks.size() == 1) {
162-
callBack = mergeCell.callBacks.get(0);
162+
callBack = mergeCell.callBacks.getFirst();
163163
} else {
164164
callBack = (success) -> {
165165
for (SendAbleSessionBytes.CallBack callBack1 : mergeCell.callBacks) {

run/src/main/java/org/wowtools/hppt/common/server/ServerSessionManager.java

+6-11
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,14 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception {
234234
disposeServerSession(session, "channelInactive");
235235
}
236236

237-
private static final class CallBack implements SendAbleSessionBytes.CallBack {
238-
private final CompletableFuture<Boolean> future;
239-
240-
public CallBack(CompletableFuture<Boolean> future) {
241-
this.future = future;
242-
}
237+
private record CallBack(CompletableFuture<Boolean> future) implements SendAbleSessionBytes.CallBack {
243238

244239
@Override
245-
public void cb(boolean success) {
246-
//锁住当前线程直至字节发送成功,避免缓冲区积压过多数据或后发先至问题
247-
future.complete(success);
248-
}
249-
}
240+
public void cb(boolean success) {
241+
//锁住当前线程直至字节发送成功,避免缓冲区积压过多数据或后发先至问题
242+
future.complete(success);
243+
}
244+
}
250245

251246
@Override
252247
public void channelRead(ChannelHandlerContext ctx, Object msg) {

run/src/main/java/org/wowtools/hppt/common/server/ServerTalker.java

+8-20
Original file line numberDiff line numberDiff line change
@@ -177,33 +177,21 @@ public static void replyToClient(CommonConfig config, ServerSessionManager serve
177177
}
178178

179179
//处理SendAbleSessionBytes的回调
180-
private static final class SendAbleSessionBytesResult {
181-
private final boolean success;
182-
private final SendAbleSessionBytes.CallBack callBack;
183-
184-
public SendAbleSessionBytesResult(boolean success, SendAbleSessionBytes.CallBack callBack) {
185-
this.success = success;
186-
this.callBack = callBack;
187-
}
180+
private record SendAbleSessionBytesResult(boolean success, SendAbleSessionBytes.CallBack callBack) {
188181
}
189182

190183
@Slf4j
191-
private static final class CbRunnable implements Runnable {
192-
private final SendAbleSessionBytesResult sendAbleSessionBytesResult;
193-
194-
public CbRunnable(SendAbleSessionBytesResult sendAbleSessionBytesResult) {
195-
this.sendAbleSessionBytesResult = sendAbleSessionBytesResult;
196-
}
184+
private record CbRunnable(SendAbleSessionBytesResult sendAbleSessionBytesResult) implements Runnable {
197185

198186
@Override
199-
public void run() {
200-
try {
201-
sendAbleSessionBytesResult.callBack.cb(sendAbleSessionBytesResult.success);
202-
} catch (Exception e) {
203-
log.warn("CbRunnable err", e);
187+
public void run() {
188+
try {
189+
sendAbleSessionBytesResult.callBack.cb(sendAbleSessionBytesResult.success);
190+
} catch (Exception e) {
191+
log.warn("CbRunnable err", e);
192+
}
204193
}
205194
}
206-
}
207195

208196
private static final BufferPool<SendAbleSessionBytesResult> sendAbleSessionBytesResultQueue
209197
= new BufferPool<>("ServerTalker.sendAbleSessionBytesResultQueue");

run/src/main/java/org/wowtools/hppt/run/ss/post/PostCtx.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @author liuyu
1010
* @date 2024/3/20
1111
*/
12-
class PostCtx {
12+
public class PostCtx {
1313
final String cookie;
1414
final BufferPool<byte[]> sendQueue = new BufferPool<>(">PostCtx-sendQueue");
1515

run/src/main/java/org/wowtools/hppt/run/ss/rhppt/RHpptServerSessionService.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.netty.channel.socket.SocketChannel;
77
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
88
import io.netty.handler.codec.LengthFieldPrepender;
9+
import lombok.extern.slf4j.Slf4j;
910
import org.wowtools.hppt.common.util.BytesUtil;
1011
import org.wowtools.hppt.common.util.NettyObjectBuilder;
1112
import org.wowtools.hppt.run.ss.common.ServerSessionService;
@@ -15,6 +16,7 @@
1516
* @author liuyu
1617
* @date 2024/4/15
1718
*/
19+
@Slf4j
1820
public class RHpptServerSessionService extends ServerSessionService<ChannelHandlerContext> {
1921

2022
private EventLoopGroup group;
@@ -70,7 +72,11 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
7072

7173
@Override
7274
protected void sendBytesToClient(ChannelHandlerContext ctx, byte[] bytes) {
73-
BytesUtil.writeToChannelHandlerContext(ctx, bytes);
75+
Throwable e = BytesUtil.writeToChannelHandlerContext(ctx, bytes);
76+
if (null != e) {
77+
log.warn("sendBytesToClient err", e);
78+
ctx.close();
79+
}
7480
}
7581

7682
@Override

0 commit comments

Comments
 (0)