Fix #263 No way to pass unfold=true to decoder superclass

- Allow modifying unfold property until the decoder is added to a
  pipeline
This commit is contained in:
Trustin Lee 2012-06-24 22:19:17 +09:00
parent 1311a2edc1
commit 8650cfbc53

View File

@ -179,7 +179,7 @@ import org.jboss.netty.handler.codec.replay.ReplayingDecoder;
*/ */
public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implements LifeCycleAwareChannelHandler { public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implements LifeCycleAwareChannelHandler {
private final boolean unfold; private boolean unfold;
protected ChannelBuffer cumulation; protected ChannelBuffer cumulation;
private volatile ChannelHandlerContext ctx; private volatile ChannelHandlerContext ctx;
private int copyThreshold; private int copyThreshold;
@ -192,6 +192,19 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
this.unfold = unfold; this.unfold = unfold;
} }
public final boolean isUnfold() {
return unfold;
}
public final void setUnfold(boolean unfold) {
if (ctx == null) {
this.unfold = unfold;
} else {
throw new IllegalStateException(
"decoder properties cannot be changed once the decoder is added to a pipeline.");
}
}
/** /**
* See {@link #setMaxCumulationBufferCapacity(int)} for explaintation of this setting * See {@link #setMaxCumulationBufferCapacity(int)} for explaintation of this setting
* *
@ -224,13 +237,13 @@ public abstract class FrameDecoder extends SimpleChannelUpstreamHandler implemen
*/ */
public final void setMaxCumulationBufferCapacity(int copyThreshold) { public final void setMaxCumulationBufferCapacity(int copyThreshold) {
if (copyThreshold < 0) { if (copyThreshold < 0) {
throw new IllegalArgumentException("MaxCumulationBufferCapacity must be >= 0"); throw new IllegalArgumentException("maxCumulationBufferCapacity must be >= 0");
} }
if (ctx == null) { if (ctx == null) {
this.copyThreshold = copyThreshold; this.copyThreshold = copyThreshold;
} else { } else {
throw new IllegalStateException("MaxCumulationBufferCapacity " + throw new IllegalStateException(
"can only be changed before the Decoder was added to the ChannelPipeline"); "decoder properties cannot be changed once the decoder is added to a pipeline.");
} }
} }