public class WebSocketServerExtensionHandler extends ChannelDuplexHandler
ChannelHandler.Sharable
构造器和说明 |
---|
WebSocketServerExtensionHandler(WebSocketServerExtensionHandshaker... extensionHandshakers)
Constructor
|
限定符和类型 | 方法和说明 |
---|---|
void |
channelRead(ChannelHandlerContext ctx,
java.lang.Object msg)
Calls
ChannelHandlerContext.fireChannelRead(Object) to forward
to the next ChannelInboundHandler in the ChannelPipeline . |
protected void |
onHttpRequestChannelRead(ChannelHandlerContext ctx,
HttpRequest request)
This is a method exposed to perform fail-fast checks of user-defined http types.
|
protected void |
onHttpResponseWrite(ChannelHandlerContext ctx,
HttpResponse response,
ChannelPromise promise)
This is a method exposed to perform fail-fast checks of user-defined http types.
|
void |
write(ChannelHandlerContext ctx,
java.lang.Object msg,
ChannelPromise promise)
Calls
ChannelOutboundInvoker.write(Object, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline . |
bind, close, connect, deregister, disconnect, flush, read
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
exceptionCaught, handlerAdded, handlerRemoved
public WebSocketServerExtensionHandler(WebSocketServerExtensionHandshaker... extensionHandshakers)
extensionHandshakers
- The extension handshaker in priority order. A handshaker could be repeated many times
with fallback configuration.public void channelRead(ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelRead(Object)
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelRead
在接口中 ChannelInboundHandler
channelRead
在类中 ChannelInboundHandlerAdapter
java.lang.Exception
@UnstableApi protected void onHttpRequestChannelRead(ChannelHandlerContext ctx, HttpRequest request) throws java.lang.Exception
eg:
If the user has defined a specific HttpRequest
type i.e.CustomHttpRequest
and
channelRead(io.netty.channel.ChannelHandlerContext, java.lang.Object)
can receive LastHttpContent.EMPTY_LAST_CONTENT
msg
types too, can override it like this:
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg != LastHttpContent.EMPTY_LAST_CONTENT) { if (msg instanceof CustomHttpRequest) { onHttpRequestChannelRead(ctx, (CustomHttpRequest) msg); } else { // if it's handling other HttpRequest types it MUST use onHttpRequestChannelRead again // or have to delegate it to super.channelRead (that can perform redundant checks). // If msg is not implementing HttpRequest, it can call ctx.fireChannelRead(msg) on it // ... super.channelRead(ctx, msg); } } else { // given that msg isn't a HttpRequest type we can just skip calling super.channelRead ctx.fireChannelRead(msg); } }IMPORTANT: It already call
super.channelRead(ctx, request)
before returning.java.lang.Exception
public void write(ChannelHandlerContext ctx, java.lang.Object msg, ChannelPromise promise) throws java.lang.Exception
ChannelDuplexHandler
ChannelOutboundInvoker.write(Object, ChannelPromise)
to forward
to the next ChannelOutboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.write
在接口中 ChannelOutboundHandler
write
在类中 ChannelDuplexHandler
ctx
- the ChannelHandlerContext
for which the write operation is mademsg
- the message to writepromise
- the ChannelPromise
to notify once the operation completesjava.lang.Exception
- thrown if an error occurs@UnstableApi protected void onHttpResponseWrite(ChannelHandlerContext ctx, HttpResponse response, ChannelPromise promise) throws java.lang.Exception
eg:
If the user has defined a specific HttpResponse
type i.e.CustomHttpResponse
and
write(io.netty.channel.ChannelHandlerContext, java.lang.Object, io.netty.channel.ChannelPromise)
can receive ByteBuf
msg
types too, it can be overridden like this:
public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (msg != Unpooled.EMPTY_BUFFER && !(msg instanceof ByteBuf)) { if (msg instanceof CustomHttpResponse) { onHttpResponseWrite(ctx, (CustomHttpResponse) msg, promise); } else { // if it's handling other HttpResponse types it MUST use onHttpResponseWrite again // or have to delegate it to super.write (that can perform redundant checks). // If msg is not implementing HttpResponse, it can call ctx.write(msg, promise) on it // ... super.write(ctx, msg, promise); } } else { // given that msg isn't a HttpResponse type we can just skip calling super.write ctx.write(msg, promise); } }IMPORTANT: It already call
super.write(ctx, response, promise)
before returning.java.lang.Exception