Fixed NETTY-141 Codec embedder does not rethrow the exceptions raised by codec

* Made DefaultChannelPipeline.notifyHandlerException() protected so that AbstractCodecEmbedder can intercept all exceptions.
This commit is contained in:
Trustin Lee 2009-04-08 07:03:53 +00:00
parent 5c95161bf5
commit 8ed510e94a
2 changed files with 23 additions and 3 deletions

View File

@ -625,7 +625,7 @@ public class DefaultChannelPipeline implements ChannelPipeline {
return realCtx;
}
void notifyHandlerException(ChannelEvent e, Throwable t) {
protected void notifyHandlerException(ChannelEvent e, Throwable t) {
if (e instanceof ExceptionEvent) {
logger.warn(
"An exception was thrown by a user handler " +

View File

@ -37,7 +37,7 @@ import org.jboss.netty.channel.ChannelPipelineCoverage;
import org.jboss.netty.channel.ChannelPipelineException;
import org.jboss.netty.channel.ChannelSink;
import org.jboss.netty.channel.ChannelUpstreamHandler;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.DefaultChannelPipeline;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
@ -52,10 +52,11 @@ public abstract class AbstractCodecEmbedder<T> implements CodecEmbedder<T> {
private final ChannelPipeline pipeline;
private final EmbeddedChannelSink sink = new EmbeddedChannelSink();
CodecEmbedderException exception;
final Queue<Object> productQueue = new LinkedList<Object>();
protected AbstractCodecEmbedder(ChannelHandler... handlers) {
pipeline = Channels.pipeline();
pipeline = new EmbeddedChannelPipeline();
configurePipeline(handlers);
channel = new EmbeddedChannel(pipeline, sink);
fireInitialEvents();
@ -155,4 +156,23 @@ public abstract class AbstractCodecEmbedder<T> implements CodecEmbedder<T> {
throw new CodecEmbedderException(actualCause);
}
}
private static final class EmbeddedChannelPipeline extends DefaultChannelPipeline {
EmbeddedChannelPipeline() {
super();
}
@Override
protected void notifyHandlerException(ChannelEvent e, Throwable t) {
while (t instanceof ChannelPipelineException && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof CodecEmbedderException) {
throw (CodecEmbedderException) t;
} else {
throw new CodecEmbedderException(t);
}
}
}
}