public class DefaultServerPushProtocol extends Object implements ServerPushProtocol
| 构造器和说明 |
|---|
DefaultServerPushProtocol(String encoding) |
| 限定符和类型 | 方法和说明 |
|---|---|
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
|
SPHead |
createSPHead() |
DefaultServerPushPacket |
decode(io.netty.channel.ChannelHandlerContext ctx,
DynamicCompositeByteBuf in,
boolean isDecodingRequest)
客户端/服务端解析请求包成header+body buffer
|
SPBody |
decodeBodyByteBuf(io.netty.buffer.ByteBuf bodyByteBuf) |
Request |
decodeRequest(Object packet)
服务端反序列化rpc请求
|
void |
decodeRequestBody(SPBody body,
Request request) |
Response |
decodeResponse(Object in,
io.netty.channel.ChannelHandlerContext ctx)
客户端反序列化rpc响应
|
Response |
decodeServerPushResponse(Object in,
io.netty.channel.ChannelHandlerContext ctx)
decode 从客户端返回的 serverPushResponse
|
io.netty.buffer.ByteBuf |
encodeRequest(Request request)
客户端序列化请求对象
|
io.netty.buffer.ByteBuf |
encodeRequestBody(Request request,
RpcMethodInfo rpcMethodInfo) |
io.netty.buffer.ByteBuf |
encodeResponse(Request request,
Response response)
服务端序列化返回结果。
|
io.netty.buffer.ByteBuf |
encodeResponseBody(Object result,
RpcMethodInfo rpcMethodInfo) |
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
|
DefaultSPHead |
headFromByteBuf(io.netty.buffer.ByteBuf buf) |
io.netty.buffer.ByteBuf |
headToBytes(SPHead spHead) |
boolean |
isCoexistence()
该协议是否可以和其他协议共存。
|
boolean |
returnChannelBeforeResponse()
连接被归还入池的时机
|
protected String encoding
public DefaultServerPushProtocol(String encoding)
public io.netty.buffer.ByteBuf encodeRequest(Request request) throws Exception
ProtocolencodeRequest 在接口中 Protocolrequest - 待发送给服务端的对象Exception - 序列化异常public void beforeRequestSent(Request request, RpcClient rpcClient, BrpcChannel channelGroup)
ProtocolbeforeRequestSent 在接口中 Protocolpublic Response decodeServerPushResponse(Object in, io.netty.channel.ChannelHandlerContext ctx)
decodeServerPushResponse 在接口中 ServerPushProtocolin - ctx - Exceptionpublic Response decodeResponse(Object in, io.netty.channel.ChannelHandlerContext ctx) throws Exception
ProtocoldecodeResponse 在接口中 Protocolin - header & body的bufctx - netty channel contextException - 反序列化异常public io.netty.buffer.ByteBuf encodeResponse(Request request, Response response) throws Exception
ProtocolencodeResponse 在接口中 Protocolresponse - 服务端要返回给客户端的对象Exception - 序列化异常public void afterResponseSent(Request request, Response response, io.netty.channel.ChannelFuture channelFuture)
ProtocolafterResponseSent 在接口中 ProtocolchannelFuture - the return value of writeAndFlushpublic Request decodeRequest(Object packet) throws Exception
ProtocoldecodeRequest 在接口中 Protocolpacket - header & body的bufExceptionpublic boolean returnChannelBeforeResponse()
ProtocolreturnChannelBeforeResponse 在接口中 Protocolpublic DefaultServerPushPacket decode(io.netty.channel.ChannelHandlerContext ctx, DynamicCompositeByteBuf in, boolean isDecodingRequest) throws BadSchemaException, TooBigDataException, NotEnoughDataException
Protocoldecode 在接口中 Protocolin - 输入byte bufBadSchemaException - header格式不对TooBigDataException - body太大NotEnoughDataException - 可读长度不够,由于粘包拆包问题。public SPBody decodeBodyByteBuf(io.netty.buffer.ByteBuf bodyByteBuf)
public Request createRequest()
ProtocolcreateRequest 在接口中 Protocolpublic Response createResponse()
ProtocolcreateResponse 在接口中 Protocolpublic Request getRequest()
ProtocolgetRequest 在接口中 Protocolpublic Response getResponse()
ProtocolgetResponse 在接口中 Protocolpublic boolean isCoexistence()
ProtocolisCoexistence 在接口中 Protocolpublic io.netty.buffer.ByteBuf encodeRequestBody(Request request, RpcMethodInfo rpcMethodInfo)
public io.netty.buffer.ByteBuf encodeResponseBody(Object result, RpcMethodInfo rpcMethodInfo)
public SPHead createSPHead()
createSPHead 在接口中 ServerPushProtocolpublic DefaultSPHead headFromByteBuf(io.netty.buffer.ByteBuf buf) throws BadSchemaException
headFromByteBuf 在接口中 ServerPushProtocolBadSchemaExceptionpublic io.netty.buffer.ByteBuf headToBytes(SPHead spHead)
headToBytes 在接口中 ServerPushProtocolCopyright © 2019 Baidu, Inc.. All rights reserved.