Trigger exceptionCaught event from the middle of the pipline (#210)

.. because the previous handlers have no interest in the exceptions
raised by the next handlers.
This commit is contained in:
Trustin Lee 2012-02-29 14:02:12 -08:00
parent 40e7a5d948
commit 4158152b24
3 changed files with 20 additions and 7 deletions

View File

@ -169,16 +169,14 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
}
currentEvent.getFuture().setFailure(cause);
fireExceptionCaught = true;
currentEvent = null;
}
if (fireExceptionCaught) {
if (fireNow) {
fireExceptionCaught(ctx.getChannel(), cause);
fireExceptionCaught(ctx, cause);
} else {
fireExceptionCaughtLater(ctx.getChannel(), cause);
fireExceptionCaughtLater(ctx, cause);
}
}
}
@ -227,7 +225,7 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
if (fireNow) {
fireExceptionCaught(ctx, t);
} else {
fireExceptionCaughtLater(ctx.getChannel(), t);
fireExceptionCaughtLater(ctx, t);
}
closeInput(chunks);

View File

@ -154,7 +154,7 @@ public class WriteTimeoutHandler extends SimpleChannelDownstreamHandler
}
protected void writeTimedOut(ChannelHandlerContext ctx) throws Exception {
Channels.fireExceptionCaughtLater(ctx.getChannel(), EXCEPTION);
Channels.fireExceptionCaughtLater(ctx, EXCEPTION);
}
private final class WriteTimeoutTask implements TimerTask {

View File

@ -520,7 +520,22 @@ public final class Channels {
});
}
/**
* Sends a {@code "exceptionCaught"} event to the
* {@link ChannelUpstreamHandler} which is placed in the closest upstream
* from the handler associated with the specified
* {@link ChannelHandlerContext} once the io-thread runs again.
*/
public static ChannelFuture fireExceptionCaughtLater(final ChannelHandlerContext ctx, final Throwable cause) {
return ctx.getPipeline().execute(new Runnable() {
@Override
public void run() {
fireExceptionCaught(ctx, cause);
}
});
}
/**
* Sends a {@code "exceptionCaught"} event to the first
* {@link ChannelUpstreamHandler} in the {@link ChannelPipeline} of