Revert "Revert "Adjust to current master""

This reverts commit 91ea9028f4.
This commit is contained in:
norman 2011-11-11 08:38:10 +01:00
parent 91ea9028f4
commit 852e0a1ed8
2 changed files with 20 additions and 22 deletions

View File

@ -69,7 +69,7 @@ public class DelimiterBasedFrameDecoder extends FrameDecoder {
private final boolean stripDelimiter; private final boolean stripDelimiter;
private boolean discardingTooLongFrame; private boolean discardingTooLongFrame;
private int tooLongFrameLength; private int tooLongFrameLength;
private boolean failImmediatelyOnTooLongFrame = false; private final boolean failImmediatelyOnTooLongFrame;
/** /**
* Creates a new instance. * Creates a new instance.
@ -103,6 +103,7 @@ public class DelimiterBasedFrameDecoder extends FrameDecoder {
}; };
this.maxFrameLength = maxFrameLength; this.maxFrameLength = maxFrameLength;
this.stripDelimiter = stripDelimiter; this.stripDelimiter = stripDelimiter;
this.failImmediatelyOnTooLongFrame = false;
} }
/** /**
@ -117,6 +118,14 @@ public class DelimiterBasedFrameDecoder extends FrameDecoder {
this(maxFrameLength, true, delimiters); this(maxFrameLength, true, delimiters);
} }
/**
* Calls {@link #DelimiterBasedFrameDecoder(int, boolean, boolean, ChannelBuffer...)} with failImmediatelyOnTooLongFrame set to <code>false</code>
*/
public DelimiterBasedFrameDecoder(
int maxFrameLength, boolean stripDelimiter, ChannelBuffer... delimiters) {
this(maxFrameLength, stripDelimiter, false, delimiters);
}
/** /**
* Creates a new instance. * Creates a new instance.
* *
@ -125,10 +134,16 @@ public class DelimiterBasedFrameDecoder extends FrameDecoder {
* the length of the frame exceeds this value. * the length of the frame exceeds this value.
* @param stripDelimiter whether the decoded frame should strip out the * @param stripDelimiter whether the decoded frame should strip out the
* delimiter or not * delimiter or not
* @param failImmediatelyOnTooLongFrame If false (the default) a {@link TooLongFrameException}
* is thrown if the length of the frame exceeds maxFrameLength,
* after the delimiter has been read.
* If true a {@link TooLongFrameException} is thrown immediately
* when the length of the frame exceeds maxFrameLength,
* regardless of whether a delimiter has been found yet.
* @param delimiters the delimiters * @param delimiters the delimiters
*/ */
public DelimiterBasedFrameDecoder( public DelimiterBasedFrameDecoder(
int maxFrameLength, boolean stripDelimiter, ChannelBuffer... delimiters) { int maxFrameLength, boolean stripDelimiter, boolean failImmediatelyOnTooLongFrame, ChannelBuffer... delimiters) {
validateMaxFrameLength(maxFrameLength); validateMaxFrameLength(maxFrameLength);
if (delimiters == null) { if (delimiters == null) {
throw new NullPointerException("delimiters"); throw new NullPointerException("delimiters");
@ -144,6 +159,7 @@ public class DelimiterBasedFrameDecoder extends FrameDecoder {
} }
this.maxFrameLength = maxFrameLength; this.maxFrameLength = maxFrameLength;
this.stripDelimiter = stripDelimiter; this.stripDelimiter = stripDelimiter;
this.failImmediatelyOnTooLongFrame = failImmediatelyOnTooLongFrame;
} }
@Override @Override
@ -213,23 +229,6 @@ public class DelimiterBasedFrameDecoder extends FrameDecoder {
} }
} }
/**
* Set the behavior when a frame longer than maxFrameLength is encountered.
*
* @param failImmediatelyOnTooLongFrame If false (the default) a {@link TooLongFrameException}
* is thrown if the length of the frame exceeds maxFrameLength,
* after the delimiter has been read.
* If true a {@link TooLongFrameException} is thrown immediately
* when the length of the frame exceeds maxFrameLength,
* regardless of whether a delimiter has been found yet.
*/
public DelimiterBasedFrameDecoder setFailImmediatelyOnTooLongFrame(
boolean failImmediatelyOnTooLongFrame)
{
this.failImmediatelyOnTooLongFrame = failImmediatelyOnTooLongFrame;
return this;
}
private void fail(ChannelHandlerContext ctx, long frameLength) { private void fail(ChannelHandlerContext ctx, long frameLength) {
if (frameLength > 0) { if (frameLength > 0) {
Channels.fireExceptionCaught( Channels.fireExceptionCaught(

View File

@ -50,8 +50,7 @@ public class DelimiterBasedFrameDecoderTest {
@Test @Test
public void testFailImmediatelyTooLongFrameRecovery() throws Exception { public void testFailImmediatelyTooLongFrameRecovery() throws Exception {
DecoderEmbedder<ChannelBuffer> embedder = new DecoderEmbedder<ChannelBuffer>( DecoderEmbedder<ChannelBuffer> embedder = new DecoderEmbedder<ChannelBuffer>(
new DelimiterBasedFrameDecoder(1, Delimiters.nulDelimiter()). new DelimiterBasedFrameDecoder(1, true, true, Delimiters.nulDelimiter()));
setFailImmediatelyOnTooLongFrame(true));
for (int i = 0; i < 2; i ++) { for (int i = 0; i < 2; i ++) {
try { try {