Module io.netty5.codec.http
Class WebSocketFrameAggregator
- java.lang.Object
-
- io.netty5.channel.ChannelHandlerAdapter
-
- io.netty5.handler.codec.MessageToMessageDecoder<I>
-
- io.netty5.handler.codec.MessageAggregator<WebSocketFrame,WebSocketFrame,ContinuationWebSocketFrame,WebSocketFrame>
-
- io.netty5.handler.codec.http.websocketx.WebSocketFrameAggregator
-
- All Implemented Interfaces:
ChannelHandler
public class WebSocketFrameAggregator extends MessageAggregator<WebSocketFrame,WebSocketFrame,ContinuationWebSocketFrame,WebSocketFrame>
Handler that aggregate fragmented WebSocketFrame's. Be aware if PING/PONG/CLOSE frames are send in the middle of a fragmentedWebSocketFramethey will just get forwarded to the next handler in the pipeline.
-
-
Constructor Summary
Constructors Constructor Description WebSocketFrameAggregator(int maxContentLength)Creates a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaggregate(BufferAllocator allocator, WebSocketFrame aggregated, ContinuationWebSocketFrame content)Aggregated the passedcontentin the passedaggregate.protected WebSocketFramebeginAggregation(BufferAllocator allocator, WebSocketFrame start)Creates a new aggregated message from the specified start message.protected booleancloseAfterContinueResponse(Object msg)Determine if the channel should be closed after the result ofMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)is written.protected booleanignoreContentAfterContinueResponse(Object msg)Determine if all objects for the current request/response should be ignored or not.protected booleanisAggregated(Object msg)Returnstrueif and only if the specified message is already aggregated.protected booleanisContentLengthInvalid(WebSocketFrame start, int maxContentLength)Determine if the messagestart's content length is known, and if it greater thanmaxContentLength.protected booleanisLastContentMessage(ContinuationWebSocketFrame msg)Returnstrueif and only if the specified message is the last content message.protected intlengthForAggregation(WebSocketFrame msg)Returns the length in bytes of the passed message.protected intlengthForContent(ContinuationWebSocketFrame msg)Returns the length in bytes of the passed message.protected ObjectnewContinueResponse(WebSocketFrame start, int maxContentLength, ChannelPipeline pipeline)Returns the 'continue response' for the specified start message if necessary.protected ContinuationWebSocketFrametryContentMessage(Object msg)protected WebSocketFrametryStartMessage(Object msg)-
Methods inherited from class io.netty5.handler.codec.MessageAggregator
acceptInboundMessage, channelInactive, channelReadComplete, ctx, decode, finishAggregation, handleOversizedMessage, handlerAdded, handlerRemoved, maxContentLength
-
Methods inherited from class io.netty5.handler.codec.MessageToMessageDecoder
channelRead, decodeAndClose
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelActive, channelExceptionCaught, channelInboundEvent, channelRegistered, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown, write
-
-
-
-
Constructor Detail
-
WebSocketFrameAggregator
public WebSocketFrameAggregator(int maxContentLength)
Creates a new instance- Parameters:
maxContentLength- If the size of the aggregated frame exceeds this value, aTooLongFrameExceptionis thrown.
-
-
Method Detail
-
tryStartMessage
protected WebSocketFrame tryStartMessage(Object msg)
Description copied from class:MessageAggregator- Specified by:
tryStartMessagein classMessageAggregator<WebSocketFrame,WebSocketFrame,ContinuationWebSocketFrame,WebSocketFrame>
-
tryContentMessage
protected ContinuationWebSocketFrame tryContentMessage(Object msg)
Description copied from class:MessageAggregator- Specified by:
tryContentMessagein classMessageAggregator<WebSocketFrame,WebSocketFrame,ContinuationWebSocketFrame,WebSocketFrame>
-
isLastContentMessage
protected boolean isLastContentMessage(ContinuationWebSocketFrame msg)
Description copied from class:MessageAggregatorReturnstrueif and only if the specified message is the last content message. Typically, this method is implemented as a singlereturnstatement withinstanceof:return msg instanceof MyLastContentMessage;
or withinstanceofand boolean field check:return msg instanceof MyContentMessage && msg.isLastFragment();
- Specified by:
isLastContentMessagein classMessageAggregator<WebSocketFrame,WebSocketFrame,ContinuationWebSocketFrame,WebSocketFrame>
-
isAggregated
protected boolean isAggregated(Object msg) throws Exception
Description copied from class:MessageAggregatorReturnstrueif and only if the specified message is already aggregated. If this method returnstrue, this handler will simply forward the message to the next handler as-is.- Specified by:
isAggregatedin classMessageAggregator<WebSocketFrame,WebSocketFrame,ContinuationWebSocketFrame,WebSocketFrame>- Throws:
Exception
-
isContentLengthInvalid
protected boolean isContentLengthInvalid(WebSocketFrame start, int maxContentLength)
Description copied from class:MessageAggregatorDetermine if the messagestart's content length is known, and if it greater thanmaxContentLength.- Specified by:
isContentLengthInvalidin classMessageAggregator<WebSocketFrame,WebSocketFrame,ContinuationWebSocketFrame,WebSocketFrame>- Parameters:
start- The message which may indicate the content length.maxContentLength- The maximum allowed content length.- Returns:
trueif the messagestart's content length is known, and if it greater thanmaxContentLength.falseotherwise.
-
newContinueResponse
protected Object newContinueResponse(WebSocketFrame start, int maxContentLength, ChannelPipeline pipeline)
Description copied from class:MessageAggregatorReturns the 'continue response' for the specified start message if necessary. For example, this method is useful to handle an HTTP 100-continue header.- Specified by:
newContinueResponsein classMessageAggregator<WebSocketFrame,WebSocketFrame,ContinuationWebSocketFrame,WebSocketFrame>- Returns:
- the 'continue response', or
nullif there's no message to send
-
closeAfterContinueResponse
protected boolean closeAfterContinueResponse(Object msg) throws Exception
Description copied from class:MessageAggregatorDetermine if the channel should be closed after the result ofMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)is written.- Specified by:
closeAfterContinueResponsein classMessageAggregator<WebSocketFrame,WebSocketFrame,ContinuationWebSocketFrame,WebSocketFrame>- Parameters:
msg- The return value fromMessageAggregator.newContinueResponse(Object, int, ChannelPipeline).- Returns:
trueif the channel should be closed after the result ofMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)is written.falseotherwise.- Throws:
Exception
-
ignoreContentAfterContinueResponse
protected boolean ignoreContentAfterContinueResponse(Object msg) throws Exception
Description copied from class:MessageAggregatorDetermine if all objects for the current request/response should be ignored or not. Messages will stop being ignored the next timeMessageAggregator.tryContentMessage(Object)returns anon nullvalue.- Specified by:
ignoreContentAfterContinueResponsein classMessageAggregator<WebSocketFrame,WebSocketFrame,ContinuationWebSocketFrame,WebSocketFrame>- Parameters:
msg- The return value fromMessageAggregator.newContinueResponse(Object, int, ChannelPipeline).- Returns:
trueif all objects for the current request/response should be ignored or not.falseotherwise.- Throws:
Exception
-
lengthForContent
protected int lengthForContent(ContinuationWebSocketFrame msg)
Description copied from class:MessageAggregatorReturns the length in bytes of the passed message.- Specified by:
lengthForContentin classMessageAggregator<WebSocketFrame,WebSocketFrame,ContinuationWebSocketFrame,WebSocketFrame>- Parameters:
msg- to calculate length.- Returns:
- Length in bytes of the passed message.
-
lengthForAggregation
protected int lengthForAggregation(WebSocketFrame msg)
Description copied from class:MessageAggregatorReturns the length in bytes of the passed message.- Specified by:
lengthForAggregationin classMessageAggregator<WebSocketFrame,WebSocketFrame,ContinuationWebSocketFrame,WebSocketFrame>- Parameters:
msg- to calculate length.- Returns:
- Length in bytes of the passed message.
-
beginAggregation
protected WebSocketFrame beginAggregation(BufferAllocator allocator, WebSocketFrame start)
Description copied from class:MessageAggregatorCreates a new aggregated message from the specified start message.- Specified by:
beginAggregationin classMessageAggregator<WebSocketFrame,WebSocketFrame,ContinuationWebSocketFrame,WebSocketFrame>
-
aggregate
protected void aggregate(BufferAllocator allocator, WebSocketFrame aggregated, ContinuationWebSocketFrame content) throws Exception
Description copied from class:MessageAggregatorAggregated the passedcontentin the passedaggregate.- Specified by:
aggregatein classMessageAggregator<WebSocketFrame,WebSocketFrame,ContinuationWebSocketFrame,WebSocketFrame>- Throws:
Exception
-
-