Class WebSocketProtocolHandler
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.handler.codec.MessageToMessageDecoder<WebSocketFrame>
-
- io.netty.handler.codec.http.websocketx.WebSocketProtocolHandler
-
- All Implemented Interfaces:
ChannelHandler,ChannelInboundHandler,ChannelOutboundHandler
- Direct Known Subclasses:
WebSocketClientProtocolHandler,WebSocketServerProtocolHandler
abstract class WebSocketProtocolHandler extends MessageToMessageDecoder<WebSocketFrame> implements ChannelOutboundHandler
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field Description private ChannelPromisecloseSentprivate WebSocketCloseStatuscloseStatusprivate booleandropPongFramesprivate longforceCloseTimeoutMillisprivate Future<?>forceCloseTimeoutTask
-
Constructor Summary
Constructors Constructor Description WebSocketProtocolHandler()Creates a newWebSocketProtocolHandlerthat will dropPongWebSocketFrames.WebSocketProtocolHandler(boolean dropPongFrames)Creates a newWebSocketProtocolHandler, given a parameter that determines whether or not to dropPongWebSocketFrames.WebSocketProtocolHandler(boolean dropPongFrames, WebSocketCloseStatus closeStatus, long forceCloseTimeoutMillis)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidapplyCloseSentTimeout(ChannelHandlerContext ctx)voidbind(ChannelHandlerContext ctx, java.net.SocketAddress localAddress, ChannelPromise promise)Called once a bind operation is made.protected WebSocketHandshakeExceptionbuildHandshakeException(java.lang.String message)Returns aWebSocketHandshakeExceptionthat depends on which client or server pipeline this handler belongs.voidclose(ChannelHandlerContext ctx, ChannelPromise promise)Called once a close operation is made.(package private) voidcloseSent(ChannelPromise promise)Records theChannelPromiseused to write the outgoing close frame.voidconnect(ChannelHandlerContext ctx, java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress, ChannelPromise promise)Called once a connect operation is made.protected voiddecode(ChannelHandlerContext ctx, WebSocketFrame frame, java.util.List<java.lang.Object> out)Decode from one message to an other.voidderegister(ChannelHandlerContext ctx, ChannelPromise promise)Called once a deregister operation is made from the current registeredEventLoop.voiddisconnect(ChannelHandlerContext ctx, ChannelPromise promise)Called once a disconnect operation is made.voidexceptionCaught(ChannelHandlerContext ctx, java.lang.Throwable cause)CallsChannelHandlerContext.fireExceptionCaught(Throwable)to forward to the nextChannelHandlerin theChannelPipeline.voidflush(ChannelHandlerContext ctx)Called once a flush operation is made.voidread(ChannelHandlerContext ctx)InterceptsChannelHandlerContext.read().private static voidreadIfNeeded(ChannelHandlerContext ctx)voidwrite(ChannelHandlerContext ctx, java.lang.Object msg, ChannelPromise promise)Called once a write operation is made.-
Methods inherited from class io.netty.handler.codec.MessageToMessageDecoder
acceptInboundMessage, channelRead, channelReadComplete
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
-
-
-
Field Detail
-
dropPongFrames
private final boolean dropPongFrames
-
closeStatus
private final WebSocketCloseStatus closeStatus
-
forceCloseTimeoutMillis
private final long forceCloseTimeoutMillis
-
closeSent
private ChannelPromise closeSent
-
forceCloseTimeoutTask
private Future<?> forceCloseTimeoutTask
-
-
Constructor Detail
-
WebSocketProtocolHandler
WebSocketProtocolHandler()
Creates a newWebSocketProtocolHandlerthat will dropPongWebSocketFrames.
-
WebSocketProtocolHandler
WebSocketProtocolHandler(boolean dropPongFrames)
Creates a newWebSocketProtocolHandler, given a parameter that determines whether or not to dropPongWebSocketFrames.- Parameters:
dropPongFrames-trueifPongWebSocketFrames should be dropped
-
WebSocketProtocolHandler
WebSocketProtocolHandler(boolean dropPongFrames, WebSocketCloseStatus closeStatus, long forceCloseTimeoutMillis)
-
-
Method Detail
-
decode
protected void decode(ChannelHandlerContext ctx, WebSocketFrame frame, java.util.List<java.lang.Object> out) throws java.lang.Exception
Description copied from class:MessageToMessageDecoderDecode from one message to an other. This method will be called for each written message that can be handled by this decoder.- Specified by:
decodein classMessageToMessageDecoder<WebSocketFrame>- Parameters:
ctx- theChannelHandlerContextwhich thisMessageToMessageDecoderbelongs toframe- the message to decode to an other oneout- theListto which decoded messages should be added- Throws:
java.lang.Exception- is thrown if an error occurs
-
readIfNeeded
private static void readIfNeeded(ChannelHandlerContext ctx)
-
close
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws java.lang.Exception
Description copied from interface:ChannelOutboundHandlerCalled once a close operation is made.- Specified by:
closein interfaceChannelOutboundHandler- Parameters:
ctx- theChannelHandlerContextfor which the close operation is madepromise- theChannelPromiseto notify once the operation completes- Throws:
java.lang.Exception- thrown if an error occurs
-
write
public void write(ChannelHandlerContext ctx, java.lang.Object msg, ChannelPromise promise) throws java.lang.Exception
Description copied from interface:ChannelOutboundHandlerCalled once a write operation is made. The write operation will write the messages through theChannelPipeline. Those are then ready to be flushed to the actualChannelonceChannel.flush()is called- Specified by:
writein interfaceChannelOutboundHandler- Parameters:
ctx- theChannelHandlerContextfor which the write operation is mademsg- the message to writepromise- theChannelPromiseto notify once the operation completes- Throws:
java.lang.Exception- thrown if an error occurs
-
flush
public void flush(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from interface:ChannelOutboundHandlerCalled once a flush operation is made. The flush operation will try to flush out all previous written messages that are pending.- Specified by:
flushin interfaceChannelOutboundHandler- Parameters:
ctx- theChannelHandlerContextfor which the flush operation is made- Throws:
java.lang.Exception- thrown if an error occurs
-
closeSent
void closeSent(ChannelPromise promise)
Records theChannelPromiseused to write the outgoing close frame. Every code path that initiates the close handshake must call this, and must subsequently giveapplyCloseSentTimeout(ChannelHandlerContext)a chance to run (directly, or indirectly viaflush(ChannelHandlerContext)) so the channel is guaranteed to close even if the outbound write never completes (e.g. the peer stops reading and the socket send buffer fills up).
-
applyCloseSentTimeout
void applyCloseSentTimeout(ChannelHandlerContext ctx)
-
buildHandshakeException
protected WebSocketHandshakeException buildHandshakeException(java.lang.String message)
Returns aWebSocketHandshakeExceptionthat depends on which client or server pipeline this handler belongs. Should be overridden in implementation otherwise a default exception is used.
-
bind
public void bind(ChannelHandlerContext ctx, java.net.SocketAddress localAddress, ChannelPromise promise) throws java.lang.Exception
Description copied from interface:ChannelOutboundHandlerCalled once a bind operation is made.- Specified by:
bindin interfaceChannelOutboundHandler- Parameters:
ctx- theChannelHandlerContextfor which the bind operation is madelocalAddress- theSocketAddressto which it should boundpromise- theChannelPromiseto notify once the operation completes- Throws:
java.lang.Exception- thrown if an error occurs
-
connect
public void connect(ChannelHandlerContext ctx, java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress, ChannelPromise promise) throws java.lang.Exception
Description copied from interface:ChannelOutboundHandlerCalled once a connect operation is made.- Specified by:
connectin interfaceChannelOutboundHandler- Parameters:
ctx- theChannelHandlerContextfor which the connect operation is maderemoteAddress- theSocketAddressto which it should connectlocalAddress- theSocketAddresswhich is used as source on connectpromise- theChannelPromiseto notify once the operation completes- Throws:
java.lang.Exception- thrown if an error occurs
-
disconnect
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws java.lang.Exception
Description copied from interface:ChannelOutboundHandlerCalled once a disconnect operation is made.- Specified by:
disconnectin interfaceChannelOutboundHandler- Parameters:
ctx- theChannelHandlerContextfor which the disconnect operation is madepromise- theChannelPromiseto notify once the operation completes- Throws:
java.lang.Exception- thrown if an error occurs
-
deregister
public void deregister(ChannelHandlerContext ctx, ChannelPromise promise) throws java.lang.Exception
Description copied from interface:ChannelOutboundHandlerCalled once a deregister operation is made from the current registeredEventLoop.- Specified by:
deregisterin interfaceChannelOutboundHandler- Parameters:
ctx- theChannelHandlerContextfor which the close operation is madepromise- theChannelPromiseto notify once the operation completes- Throws:
java.lang.Exception- thrown if an error occurs
-
read
public void read(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from interface:ChannelOutboundHandlerInterceptsChannelHandlerContext.read().- Specified by:
readin interfaceChannelOutboundHandler- Throws:
java.lang.Exception
-
exceptionCaught
public void exceptionCaught(ChannelHandlerContext ctx, java.lang.Throwable cause) throws java.lang.Exception
Description copied from class:ChannelInboundHandlerAdapterCallsChannelHandlerContext.fireExceptionCaught(Throwable)to forward to the nextChannelHandlerin theChannelPipeline. Sub-classes may override this method to change behavior.- Specified by:
exceptionCaughtin interfaceChannelHandler- Specified by:
exceptionCaughtin interfaceChannelInboundHandler- Overrides:
exceptionCaughtin classChannelInboundHandlerAdapter- Throws:
java.lang.Exception
-
-