Package io.netty.handler.codec.spdy
Class SpdyFrameCodec
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.handler.codec.ByteToMessageDecoder
-
- io.netty.handler.codec.spdy.SpdyFrameCodec
-
- All Implemented Interfaces:
ChannelHandler
,ChannelInboundHandler
,ChannelOutboundHandler
,SpdyFrameDecoderDelegate
public class SpdyFrameCodec extends ByteToMessageDecoder implements SpdyFrameDecoderDelegate, ChannelOutboundHandler
AChannelHandler
that encodes and decodes SPDY Frames.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.netty.handler.codec.ByteToMessageDecoder
ByteToMessageDecoder.Cumulator
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field Description protected static SpdyProtocolException
INVALID_FRAME
protected SpdyFrameDecoder
spdyFrameDecoder
protected SpdyFrameEncoder
spdyFrameEncoder
-
Fields inherited from class io.netty.handler.codec.ByteToMessageDecoder
COMPOSITE_CUMULATOR, MERGE_CUMULATOR
-
-
Constructor Summary
Constructors Modifier Constructor Description SpdyFrameCodec(SpdyVersion version)
Creates a new instance with the specifiedversion
,validateHeaders (true)
, and the default decoder and encoder options (maxChunkSize (8192)
,maxHeaderSize (16384)
,compressionLevel (6)
,windowBits (15)
, andmemLevel (8)
).SpdyFrameCodec(SpdyVersion version, boolean validateHeaders)
Creates a new instance with the specifiedversion
,validateHeaders
, and the default decoder and encoder options (maxChunkSize (8192)
,maxHeaderSize (16384)
,compressionLevel (6)
,windowBits (15)
, andmemLevel (8)
).SpdyFrameCodec(SpdyVersion version, int maxChunkSize, int maxHeaderSize, int compressionLevel, int windowBits, int memLevel)
Creates a new instance with the specifiedversion
,validateHeaders (true)
, decoder and encoder options.SpdyFrameCodec(SpdyVersion version, int maxChunkSize, int maxHeaderSize, int compressionLevel, int windowBits, int memLevel, boolean validateHeaders)
Creates a new instance with the specifiedversion
,validateHeaders
, decoder and encoder options.SpdyFrameCodec(SpdyVersion version, int maxChunkSize, int maxHeaderSize, int compressionLevel, int windowBits, int memLevel, boolean validateHeaders, boolean supportsUnknownFrames)
Creates a new instance with the specifiedversion
,validateHeaders
, decoder and encoder options.protected
SpdyFrameCodec(SpdyVersion version, int maxChunkSize, SpdyHeaderBlockDecoder spdyHeaderBlockDecoder, SpdyHeaderBlockEncoder spdyHeaderBlockEncoder, boolean validateHeaders)
protected
SpdyFrameCodec(SpdyVersion version, int maxChunkSize, SpdyHeaderBlockDecoder spdyHeaderBlockDecoder, SpdyHeaderBlockEncoder spdyHeaderBlockEncoder, boolean validateHeaders, boolean supportsUnknownFrames)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bind(ChannelHandlerContext ctx, java.net.SocketAddress localAddress, ChannelPromise promise)
Called once a bind operation is made.void
channelReadComplete(ChannelHandlerContext ctx)
CallsChannelHandlerContext.fireChannelReadComplete()
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
close(ChannelHandlerContext ctx, ChannelPromise promise)
Called once a close operation is made.void
connect(ChannelHandlerContext ctx, java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress, ChannelPromise promise)
Called once a connect operation is made.protected SpdyFrameDecoder
createDecoder(SpdyVersion version, SpdyFrameDecoderDelegate delegate, int maxChunkSize)
protected SpdyFrameEncoder
createEncoder(SpdyVersion version)
protected void
decode(ChannelHandlerContext ctx, ByteBuf in, java.util.List<java.lang.Object> out)
Decode the from oneByteBuf
to an other.void
deregister(ChannelHandlerContext ctx, ChannelPromise promise)
Called once a deregister operation is made from the current registeredEventLoop
.void
disconnect(ChannelHandlerContext ctx, ChannelPromise promise)
Called once a disconnect operation is made.void
flush(ChannelHandlerContext ctx)
Called once a flush operation is made.void
handlerAdded(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.protected boolean
isValidUnknownFrameHeader(int streamId, int type, byte flags, int length)
Check whether the unknown frame is valid, if not, the frame will be discarded, otherwise, the frame will be passed toSpdyFrameDecoder.decodeUnknownFrame(int, byte, int, ByteBuf)
.protected SpdyFrame
newSpdyUnknownFrame(int frameType, byte flags, ByteBuf payload)
Create a SpdyUnknownFrame.void
read(ChannelHandlerContext ctx)
InterceptsChannelHandlerContext.read()
.void
readDataFrame(int streamId, boolean last, ByteBuf data)
Called when a DATA frame is received.void
readFrameError(java.lang.String message)
Called when an unrecoverable session error has occurred.void
readGoAwayFrame(int lastGoodStreamId, int statusCode)
Called when a GOAWAY frame is received.void
readHeaderBlock(ByteBuf headerBlock)
Called when the header block within a SYN_STREAM, SYN_REPLY, or HEADERS frame is received.void
readHeaderBlockEnd()
Called when an entire header block has been received.void
readHeadersFrame(int streamId, boolean last)
Called when a HEADERS frame is received.void
readPingFrame(int id)
Called when a PING frame is received.void
readRstStreamFrame(int streamId, int statusCode)
Called when a RST_STREAM frame is received.void
readSetting(int id, int value, boolean persistValue, boolean persisted)
Called when an individual setting within a SETTINGS frame is received.void
readSettingsEnd()
Called when the entire SETTINGS frame has been received.void
readSettingsFrame(boolean clearPersisted)
Called when a SETTINGS frame is received.void
readSynReplyFrame(int streamId, boolean last)
Called when a SYN_REPLY frame is received.void
readSynStreamFrame(int streamId, int associatedToStreamId, byte priority, boolean last, boolean unidirectional)
Called when a SYN_STREAM frame is received.void
readUnknownFrame(int frameType, byte flags, ByteBuf payload)
Called when an unknown frame is received.void
readWindowUpdateFrame(int streamId, int deltaWindowSize)
Called when a WINDOW_UPDATE frame is received.void
write(ChannelHandlerContext ctx, java.lang.Object msg, ChannelPromise promise)
Called once a write operation is made.-
Methods inherited from class io.netty.handler.codec.ByteToMessageDecoder
actualReadableBytes, callDecode, channelInactive, channelRead, decodeLast, discardSomeReadBytes, handlerRemoved, handlerRemoved0, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, 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
handlerRemoved
-
-
-
-
Field Detail
-
INVALID_FRAME
protected static final SpdyProtocolException INVALID_FRAME
-
spdyFrameDecoder
protected final SpdyFrameDecoder spdyFrameDecoder
-
spdyFrameEncoder
protected final SpdyFrameEncoder spdyFrameEncoder
-
-
Constructor Detail
-
SpdyFrameCodec
public SpdyFrameCodec(SpdyVersion version)
Creates a new instance with the specifiedversion
,validateHeaders (true)
, and the default decoder and encoder options (maxChunkSize (8192)
,maxHeaderSize (16384)
,compressionLevel (6)
,windowBits (15)
, andmemLevel (8)
).
-
SpdyFrameCodec
public SpdyFrameCodec(SpdyVersion version, boolean validateHeaders)
Creates a new instance with the specifiedversion
,validateHeaders
, and the default decoder and encoder options (maxChunkSize (8192)
,maxHeaderSize (16384)
,compressionLevel (6)
,windowBits (15)
, andmemLevel (8)
).
-
SpdyFrameCodec
public SpdyFrameCodec(SpdyVersion version, int maxChunkSize, int maxHeaderSize, int compressionLevel, int windowBits, int memLevel)
Creates a new instance with the specifiedversion
,validateHeaders (true)
, decoder and encoder options.
-
SpdyFrameCodec
public SpdyFrameCodec(SpdyVersion version, int maxChunkSize, int maxHeaderSize, int compressionLevel, int windowBits, int memLevel, boolean validateHeaders)
Creates a new instance with the specifiedversion
,validateHeaders
, decoder and encoder options.
-
SpdyFrameCodec
public SpdyFrameCodec(SpdyVersion version, int maxChunkSize, int maxHeaderSize, int compressionLevel, int windowBits, int memLevel, boolean validateHeaders, boolean supportsUnknownFrames)
Creates a new instance with the specifiedversion
,validateHeaders
, decoder and encoder options.
-
SpdyFrameCodec
protected SpdyFrameCodec(SpdyVersion version, int maxChunkSize, SpdyHeaderBlockDecoder spdyHeaderBlockDecoder, SpdyHeaderBlockEncoder spdyHeaderBlockEncoder, boolean validateHeaders)
-
SpdyFrameCodec
protected SpdyFrameCodec(SpdyVersion version, int maxChunkSize, SpdyHeaderBlockDecoder spdyHeaderBlockDecoder, SpdyHeaderBlockEncoder spdyHeaderBlockEncoder, boolean validateHeaders, boolean supportsUnknownFrames)
-
-
Method Detail
-
createDecoder
protected SpdyFrameDecoder createDecoder(SpdyVersion version, SpdyFrameDecoderDelegate delegate, int maxChunkSize)
-
createEncoder
protected SpdyFrameEncoder createEncoder(SpdyVersion version)
-
handlerAdded
public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelHandlerAdapter
Do nothing by default, sub-classes may override this method.- Specified by:
handlerAdded
in interfaceChannelHandler
- Overrides:
handlerAdded
in classChannelHandlerAdapter
- Throws:
java.lang.Exception
-
decode
protected void decode(ChannelHandlerContext ctx, ByteBuf in, java.util.List<java.lang.Object> out) throws java.lang.Exception
Description copied from class:ByteToMessageDecoder
Decode the from oneByteBuf
to an other. This method will be called till either the inputByteBuf
has nothing to read when return from this method or till nothing was read from the inputByteBuf
.- Specified by:
decode
in classByteToMessageDecoder
- Parameters:
ctx
- theChannelHandlerContext
which thisByteToMessageDecoder
belongs toin
- theByteBuf
from which to read dataout
- theList
to which decoded messages should be added- Throws:
java.lang.Exception
- is thrown if an error occurs
-
channelReadComplete
public void channelReadComplete(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelReadComplete()
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelReadComplete
in interfaceChannelInboundHandler
- Overrides:
channelReadComplete
in classByteToMessageDecoder
- Throws:
java.lang.Exception
-
bind
public void bind(ChannelHandlerContext ctx, java.net.SocketAddress localAddress, ChannelPromise promise) throws java.lang.Exception
Description copied from interface:ChannelOutboundHandler
Called once a bind operation is made.- Specified by:
bind
in interfaceChannelOutboundHandler
- Parameters:
ctx
- theChannelHandlerContext
for which the bind operation is madelocalAddress
- theSocketAddress
to which it should boundpromise
- theChannelPromise
to 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:ChannelOutboundHandler
Called once a connect operation is made.- Specified by:
connect
in interfaceChannelOutboundHandler
- Parameters:
ctx
- theChannelHandlerContext
for which the connect operation is maderemoteAddress
- theSocketAddress
to which it should connectlocalAddress
- theSocketAddress
which is used as source on connectpromise
- theChannelPromise
to 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:ChannelOutboundHandler
Called once a disconnect operation is made.- Specified by:
disconnect
in interfaceChannelOutboundHandler
- Parameters:
ctx
- theChannelHandlerContext
for which the disconnect operation is madepromise
- theChannelPromise
to notify once the operation completes- Throws:
java.lang.Exception
- thrown if an error occurs
-
close
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws java.lang.Exception
Description copied from interface:ChannelOutboundHandler
Called once a close operation is made.- Specified by:
close
in interfaceChannelOutboundHandler
- Parameters:
ctx
- theChannelHandlerContext
for which the close operation is madepromise
- theChannelPromise
to 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:ChannelOutboundHandler
Called once a deregister operation is made from the current registeredEventLoop
.- Specified by:
deregister
in interfaceChannelOutboundHandler
- Parameters:
ctx
- theChannelHandlerContext
for which the close operation is madepromise
- theChannelPromise
to 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:ChannelOutboundHandler
InterceptsChannelHandlerContext.read()
.- Specified by:
read
in interfaceChannelOutboundHandler
- Throws:
java.lang.Exception
-
flush
public void flush(ChannelHandlerContext ctx) throws java.lang.Exception
Description copied from interface:ChannelOutboundHandler
Called once a flush operation is made. The flush operation will try to flush out all previous written messages that are pending.- Specified by:
flush
in interfaceChannelOutboundHandler
- Parameters:
ctx
- theChannelHandlerContext
for which the flush operation is made- 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:ChannelOutboundHandler
Called once a write operation is made. The write operation will write the messages through theChannelPipeline
. Those are then ready to be flushed to the actualChannel
onceChannel.flush()
is called- Specified by:
write
in interfaceChannelOutboundHandler
- Parameters:
ctx
- theChannelHandlerContext
for which the write operation is mademsg
- the message to writepromise
- theChannelPromise
to notify once the operation completes- Throws:
java.lang.Exception
- thrown if an error occurs
-
readDataFrame
public void readDataFrame(int streamId, boolean last, ByteBuf data)
Description copied from interface:SpdyFrameDecoderDelegate
Called when a DATA frame is received.- Specified by:
readDataFrame
in interfaceSpdyFrameDecoderDelegate
-
readSynStreamFrame
public void readSynStreamFrame(int streamId, int associatedToStreamId, byte priority, boolean last, boolean unidirectional)
Description copied from interface:SpdyFrameDecoderDelegate
Called when a SYN_STREAM frame is received. The Name/Value Header Block is not included. See readHeaderBlock().- Specified by:
readSynStreamFrame
in interfaceSpdyFrameDecoderDelegate
-
readSynReplyFrame
public void readSynReplyFrame(int streamId, boolean last)
Description copied from interface:SpdyFrameDecoderDelegate
Called when a SYN_REPLY frame is received. The Name/Value Header Block is not included. See readHeaderBlock().- Specified by:
readSynReplyFrame
in interfaceSpdyFrameDecoderDelegate
-
readRstStreamFrame
public void readRstStreamFrame(int streamId, int statusCode)
Description copied from interface:SpdyFrameDecoderDelegate
Called when a RST_STREAM frame is received.- Specified by:
readRstStreamFrame
in interfaceSpdyFrameDecoderDelegate
-
readSettingsFrame
public void readSettingsFrame(boolean clearPersisted)
Description copied from interface:SpdyFrameDecoderDelegate
Called when a SETTINGS frame is received. Settings are not included. See readSetting().- Specified by:
readSettingsFrame
in interfaceSpdyFrameDecoderDelegate
-
readSetting
public void readSetting(int id, int value, boolean persistValue, boolean persisted)
Description copied from interface:SpdyFrameDecoderDelegate
Called when an individual setting within a SETTINGS frame is received.- Specified by:
readSetting
in interfaceSpdyFrameDecoderDelegate
-
readSettingsEnd
public void readSettingsEnd()
Description copied from interface:SpdyFrameDecoderDelegate
Called when the entire SETTINGS frame has been received.- Specified by:
readSettingsEnd
in interfaceSpdyFrameDecoderDelegate
-
readPingFrame
public void readPingFrame(int id)
Description copied from interface:SpdyFrameDecoderDelegate
Called when a PING frame is received.- Specified by:
readPingFrame
in interfaceSpdyFrameDecoderDelegate
-
readGoAwayFrame
public void readGoAwayFrame(int lastGoodStreamId, int statusCode)
Description copied from interface:SpdyFrameDecoderDelegate
Called when a GOAWAY frame is received.- Specified by:
readGoAwayFrame
in interfaceSpdyFrameDecoderDelegate
-
readHeadersFrame
public void readHeadersFrame(int streamId, boolean last)
Description copied from interface:SpdyFrameDecoderDelegate
Called when a HEADERS frame is received. The Name/Value Header Block is not included. See readHeaderBlock().- Specified by:
readHeadersFrame
in interfaceSpdyFrameDecoderDelegate
-
readWindowUpdateFrame
public void readWindowUpdateFrame(int streamId, int deltaWindowSize)
Description copied from interface:SpdyFrameDecoderDelegate
Called when a WINDOW_UPDATE frame is received.- Specified by:
readWindowUpdateFrame
in interfaceSpdyFrameDecoderDelegate
-
readHeaderBlock
public void readHeaderBlock(ByteBuf headerBlock)
Description copied from interface:SpdyFrameDecoderDelegate
Called when the header block within a SYN_STREAM, SYN_REPLY, or HEADERS frame is received.- Specified by:
readHeaderBlock
in interfaceSpdyFrameDecoderDelegate
-
readHeaderBlockEnd
public void readHeaderBlockEnd()
Description copied from interface:SpdyFrameDecoderDelegate
Called when an entire header block has been received.- Specified by:
readHeaderBlockEnd
in interfaceSpdyFrameDecoderDelegate
-
readUnknownFrame
public void readUnknownFrame(int frameType, byte flags, ByteBuf payload)
Description copied from interface:SpdyFrameDecoderDelegate
Called when an unknown frame is received.- Specified by:
readUnknownFrame
in interfaceSpdyFrameDecoderDelegate
- Parameters:
frameType
- the frame type from the spdy header.flags
- the flags in the frame header.payload
- the payload of the frame.
-
newSpdyUnknownFrame
protected SpdyFrame newSpdyUnknownFrame(int frameType, byte flags, ByteBuf payload)
Create a SpdyUnknownFrame.
-
isValidUnknownFrameHeader
protected boolean isValidUnknownFrameHeader(int streamId, int type, byte flags, int length)
Check whether the unknown frame is valid, if not, the frame will be discarded, otherwise, the frame will be passed toSpdyFrameDecoder.decodeUnknownFrame(int, byte, int, ByteBuf)
.By default this method always returns
false
, sub-classes may override this.
-
readFrameError
public void readFrameError(java.lang.String message)
Description copied from interface:SpdyFrameDecoderDelegate
Called when an unrecoverable session error has occurred.- Specified by:
readFrameError
in interfaceSpdyFrameDecoderDelegate
-
-