同步获取响应数据

This commit is contained in:
Guoqs
2024-08-01 18:03:21 +08:00
parent eb40bd5798
commit 64028f04f3
20 changed files with 99 additions and 63 deletions

View File

@@ -0,0 +1,26 @@
package com.jsowell.pile.rpc;
import com.jsowell.common.protocol.RpcResponse;
import com.jsowell.common.protocol.SyncPromise;
import com.jsowell.common.util.RpcUtil;
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();
}
}
}