public interface Protocol
| 限定符和类型 | 方法和说明 |
|---|---|
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
|
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
|
Request |
decodeRequest(Object packet)
服务端反序列化rpc请求
|
Response |
decodeResponse(Object msg,
io.netty.channel.ChannelHandlerContext ctx)
客户端反序列化rpc响应
|
io.netty.buffer.ByteBuf |
encodeRequest(Request request)
客户端序列化请求对象
|
io.netty.buffer.ByteBuf |
encodeResponse(Request request,
Response response)
服务端序列化返回结果。
|
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()
该协议是否可以和其他协议共存。
|
boolean |
returnChannelBeforeResponse()
连接被归还入池的时机
|
Object decode(io.netty.channel.ChannelHandlerContext ctx, DynamicCompositeByteBuf in, boolean isDecodingRequest) throws BadSchemaException, TooBigDataException, NotEnoughDataException
in - 输入byte bufBadSchemaException - header格式不对TooBigDataException - body太大NotEnoughDataException - 可读长度不够,由于粘包拆包问题。boolean isCoexistence()
Request createRequest()
Response createResponse()
Request getRequest()
Response getResponse()
io.netty.buffer.ByteBuf encodeRequest(Request request) throws Exception
request - 待发送给服务端的对象Exception - 序列化异常void beforeRequestSent(Request request, RpcClient rpcClient, BrpcChannel channelGroup)
Response decodeResponse(Object msg, io.netty.channel.ChannelHandlerContext ctx) throws Exception
msg - header & body的bufctx - netty channel contextException - 反序列化异常boolean returnChannelBeforeResponse()
Request decodeRequest(Object packet) throws Exception
packet - header & body的bufExceptionio.netty.buffer.ByteBuf encodeResponse(Request request, Response response) throws Exception
response - 服务端要返回给客户端的对象Exception - 序列化异常Copyright © 2019 Baidu, Inc.. All rights reserved.