public class DefaultServerPushProtocol extends Object implements ServerPushProtocol
| Constructor and Description |
|---|
DefaultServerPushProtocol(String encoding) |
| Modifier and Type | Method and Description |
|---|---|
void |
afterResponseSent(Request request,
Response response,
io.netty.channel.ChannelFuture channelFuture)
do something if needed after server channel writeAndFlush
|
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()
连接被归还入池的时机
|
boolean |
supportHeartbeat()
check if the protocol supports heartbeat packet
|
protected String encoding
public DefaultServerPushProtocol(String encoding)
public io.netty.buffer.ByteBuf encodeRequest(Request request) throws Exception
ProtocolencodeRequest in interface Protocolrequest - 待发送给服务端的对象Exception - 序列化异常public Response decodeServerPushResponse(Object in, io.netty.channel.ChannelHandlerContext ctx)
decodeServerPushResponse in interface ServerPushProtocolin - ctx - Exceptionpublic Response decodeResponse(Object in, io.netty.channel.ChannelHandlerContext ctx) throws Exception
ProtocoldecodeResponse in interface Protocolin - header & body的bufctx - netty channel contextException - 反序列化异常public io.netty.buffer.ByteBuf encodeResponse(Request request, Response response) throws Exception
ProtocolencodeResponse in interface Protocolresponse - 服务端要返回给客户端的对象Exception - 序列化异常public void afterResponseSent(Request request, Response response, io.netty.channel.ChannelFuture channelFuture)
ProtocolafterResponseSent in interface ProtocolchannelFuture - the return value of writeAndFlushpublic Request decodeRequest(Object packet) throws Exception
ProtocoldecodeRequest in interface Protocolpacket - header & body的bufExceptionpublic boolean returnChannelBeforeResponse()
ProtocolreturnChannelBeforeResponse in interface Protocolpublic DefaultServerPushPacket decode(io.netty.channel.ChannelHandlerContext ctx, DynamicCompositeByteBuf in, boolean isDecodingRequest) throws BadSchemaException, TooBigDataException, NotEnoughDataException
Protocoldecode in interface Protocolin - 输入byte bufBadSchemaException - header格式不对TooBigDataException - body太大NotEnoughDataException - 可读长度不够,由于粘包拆包问题。public SPBody decodeBodyByteBuf(io.netty.buffer.ByteBuf bodyByteBuf)
public Request createRequest()
ProtocolcreateRequest in interface Protocolpublic Response createResponse()
ProtocolcreateResponse in interface Protocolpublic Request getRequest()
ProtocolgetRequest in interface Protocolpublic Response getResponse()
ProtocolgetResponse in interface Protocolpublic boolean isCoexistence()
ProtocolisCoexistence in interface Protocolpublic io.netty.buffer.ByteBuf encodeRequestBody(Request request, RpcMethodInfo rpcMethodInfo)
public io.netty.buffer.ByteBuf encodeResponseBody(Object result, RpcMethodInfo rpcMethodInfo)
public SPHead createSPHead()
createSPHead in interface ServerPushProtocolpublic DefaultSPHead headFromByteBuf(io.netty.buffer.ByteBuf buf) throws BadSchemaException
headFromByteBuf in interface ServerPushProtocolBadSchemaExceptionpublic io.netty.buffer.ByteBuf headToBytes(SPHead spHead)
headToBytes in interface ServerPushProtocolpublic boolean supportHeartbeat()
ProtocolsupportHeartbeat in interface ProtocolCopyright © 2020 Baidu, Inc.. All rights reserved.