@Override public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { // First chunk in the request. See if this channel has been marked for death. Integer actualNumOpenChannels = ctx.channel().attr(TOO_MANY_OPEN_CONNECTIONS_THIS_CHANNEL_SHOULD_CLOSE).get(); if (actualNumOpenChannels != null && actualNumOpenChannels >= maxOpenChannelsThreshold) throw new TooManyOpenChannelsException(actualNumOpenChannels, maxOpenChannelsThreshold); } return PipelineContinuationBehavior.CONTINUE; }
@Override public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { // First chunk in the request. See if this channel has been marked for death. Integer actualNumOpenChannels = ctx.channel().attr(TOO_MANY_OPEN_CONNECTIONS_THIS_CHANNEL_SHOULD_CLOSE).get(); if (actualNumOpenChannels != null && actualNumOpenChannels >= maxOpenChannelsThreshold) throw new TooManyOpenChannelsException(actualNumOpenChannels, maxOpenChannelsThreshold); } return PipelineContinuationBehavior.CONTINUE; }
@Test public void should_handle_TooManyOpenChannelsException() { verifyExceptionHandled(new TooManyOpenChannelsException(43, 42), singletonError(testProjectApiErrors.getTemporaryServiceProblemApiError())); }