同步获取响应数据

This commit is contained in:
Guoqs
2024-07-31 16:48:29 +08:00
parent a6d3cf3366
commit eed9a7bc2c
25 changed files with 590 additions and 276 deletions

View File

@@ -0,0 +1,23 @@
package rpc;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
public class RpcResponseHandler extends SimpleChannelInboundHandler<RpcResponse> {
@Override
protected void channelRead0(ChannelHandlerContext ctx, RpcResponse msg) throws Exception {
// 根据请求id在集合中找到与外部线程通信的SyncPromise对象
SyncPromise syncPromise = RpcUtil.getSyncPromiseMap().get(msg.getId());
if(syncPromise != null) {
// 设置响应结果
syncPromise.setRpcResponse(msg);
// 唤醒外部线程
syncPromise.wake();
}
}
}