public class HttpRpcProtocol extends AbstractProtocol
| 限定符和类型 | 字段和说明 |
|---|---|
protected String |
encoding |
static String |
PROTOCOL_TYPE |
protected int |
protocolType |
notEnoughDataException| 构造器和说明 |
|---|
HttpRpcProtocol(int protocolType,
String encoding) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addHttpResponseHeaders(io.netty.handler.codec.http.FullHttpResponse fullHttpResponse,
Response response,
io.netty.handler.codec.http.FullHttpRequest fullHttpRequest)
fill http response headers
|
void |
afterResponseSent(Request request,
Response response,
io.netty.channel.ChannelFuture channelFuture)
do something if needed after server channel writeAndFlush
|
void |
beforeRequestSent(Request request,
RpcClient rpcClient,
BrpcChannel channelGroup)
do something if needed before client send request
|
String |
buildHttpUri(String serviceName,
String methodName) |
Request |
createRequest()
create a new request instance
|
Response |
createResponse()
create a new response instance
|
Object |
decode(io.netty.channel.ChannelHandlerContext ctx,
DynamicCompositeByteBuf in,
boolean isDecodingRequest)
客户端/服务端解析请求包成header+body buffer
|
Object |
decodeBody(int protocolType,
String encoding,
byte[] bytes) |
Request |
decodeRequest(Object packet)
服务端反序列化rpc请求
|
Response |
decodeResponse(Object msg,
io.netty.channel.ChannelHandlerContext ctx)
客户端反序列化rpc响应
|
byte[] |
encodeBody(int protocolType,
String encoding,
Object body,
RpcMethodInfo rpcMethodInfo) |
io.netty.buffer.ByteBuf |
encodeRequest(Request request)
客户端序列化请求对象
|
io.netty.buffer.ByteBuf |
encodeResponse(Request request,
Response response)
服务端序列化返回结果。
|
byte[] |
encodeResponseBody(int protocolType,
Request request,
Response response) |
String |
getContentType(Integer protocolType) |
Request |
getRequest()
get a reusable request instance from threadLocal or pool
the request instance must be reset before reuse
|
Response |
getResponse()
get a reusable response instance from threadLocal or pool
the response instance must be reset before reuse
|
boolean |
isCoexistence()
该协议是否可以和其他协议共存。
|
Object |
makeRequest(int id,
String methodName,
Object[] args) |
Object |
makeResponse(int protocolType,
Response response) |
long |
parseCorrelationId(String headerCorrelationId,
Long channelAttachCorrelationId) |
Object |
parseHttpResponse(Object body,
RpcMethodInfo rpcMethodInfo) |
static int |
parseProtocolType(String contentType) |
Object[] |
parseRequestParam(int protocolType,
Object body,
RpcMethodInfo rpcMethodInfo) |
boolean |
returnChannelBeforeResponse()
连接被归还入池的时机
|
protected int protocolType
protected String encoding
public HttpRpcProtocol(int protocolType,
String encoding)
public Request createRequest()
ProtocolcreateRequest 在接口中 ProtocolcreateRequest 在类中 AbstractProtocolpublic Response createResponse()
ProtocolcreateResponse 在接口中 ProtocolcreateResponse 在类中 AbstractProtocolpublic Request getRequest()
ProtocolgetRequest 在接口中 ProtocolgetRequest 在类中 AbstractProtocolpublic Response getResponse()
ProtocolgetResponse 在接口中 ProtocolgetResponse 在类中 AbstractProtocolpublic Object decode(io.netty.channel.ChannelHandlerContext ctx, DynamicCompositeByteBuf in, boolean isDecodingRequest) throws BadSchemaException, TooBigDataException, NotEnoughDataException
Protocolin - 输入byte bufBadSchemaException - header格式不对TooBigDataException - body太大NotEnoughDataException - 可读长度不够,由于粘包拆包问题。public io.netty.buffer.ByteBuf encodeRequest(Request request) throws Exception
Protocolrequest - 待发送给服务端的对象Exception - 序列化异常public void beforeRequestSent(Request request, RpcClient rpcClient, BrpcChannel channelGroup)
ProtocolbeforeRequestSent 在接口中 ProtocolbeforeRequestSent 在类中 AbstractProtocolpublic Response decodeResponse(Object msg, io.netty.channel.ChannelHandlerContext ctx)
Protocolmsg - header & body的bufctx - netty channel contextpublic Request decodeRequest(Object packet)
Protocolpacket - header & body的bufpublic io.netty.buffer.ByteBuf encodeResponse(Request request, Response response)
Protocolresponse - 服务端要返回给客户端的对象public void afterResponseSent(Request request, Response response, io.netty.channel.ChannelFuture channelFuture)
ProtocolafterResponseSent 在接口中 ProtocolafterResponseSent 在类中 AbstractProtocolchannelFuture - the return value of writeAndFlushpublic byte[] encodeResponseBody(int protocolType,
Request request,
Response response)
public boolean returnChannelBeforeResponse()
ProtocolreturnChannelBeforeResponse 在接口中 ProtocolreturnChannelBeforeResponse 在类中 AbstractProtocolpublic boolean isCoexistence()
ProtocolisCoexistence 在接口中 ProtocolisCoexistence 在类中 AbstractProtocolpublic static int parseProtocolType(String contentType)
public byte[] encodeBody(int protocolType,
String encoding,
Object body,
RpcMethodInfo rpcMethodInfo)
public void addHttpResponseHeaders(io.netty.handler.codec.http.FullHttpResponse fullHttpResponse,
Response response,
io.netty.handler.codec.http.FullHttpRequest fullHttpRequest)
fullHttpResponse - netty http responseresponse - brpc standard responsefullHttpRequest - netty http requestpublic long parseCorrelationId(String headerCorrelationId, Long channelAttachCorrelationId)
public Object parseHttpResponse(Object body, RpcMethodInfo rpcMethodInfo)
public Object[] parseRequestParam(int protocolType, Object body, RpcMethodInfo rpcMethodInfo)
Copyright © 2019 Baidu, Inc.. All rights reserved.