use of com.alipay.sofa.rpc.transport.ClientHandler in project sofa-rpc by sofastack.
the class AbstractHttp2ClientTransport method doSend.
protected void doSend(final SofaRequest request, AbstractHttpClientHandler callback, final int timeoutMills) {
AbstractByteBuf data = null;
try {
// 序列化
byte serializeType = request.getSerializeType();
Serializer serializer = SerializerFactory.getSerializer(serializeType);
data = serializer.encode(request, null);
request.setData(data);
// 记录请求序列化大小 不是很准,没有记录HTTP头
RpcInternalContext.getContext().setAttachment(RpcConstants.INTERNAL_KEY_REQ_SIZE, data.readableBytes());
// 转换请求
FullHttpRequest httpRequest = convertToHttpRequest(request);
// 发送请求
final int requestId = sendHttpRequest(httpRequest, callback);
if (request.isAsync()) {
TIMEOUT_TIMER.newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
Map.Entry<ChannelFuture, AbstractHttpClientHandler> entry = responseChannelHandler.removePromise(requestId);
if (entry != null) {
ClientHandler handler = entry.getValue();
Exception e = timeoutException(request, timeoutMills, null);
handler.onException(e);
}
}
}, timeoutMills, TimeUnit.MILLISECONDS);
}
} finally {
if (data != null) {
data.release();
}
}
}
Aggregations