This commit is contained in:
Guoqs
2024-08-01 10:54:13 +08:00
parent 7294d82a7e
commit c16081feda
16 changed files with 16 additions and 16 deletions

View File

@@ -0,0 +1,23 @@
package com.jsowell.netty.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();
}
}
}