Fix sharable check logic
Motivation: There is an logic issue when checking if ChannelHandler is sharable. Modification: Corrected || to &&
This commit is contained in:
parent
ef5ebb40c9
commit
73e8122fc1
@ -36,7 +36,7 @@ public class Http2MultiplexCodecBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static ChannelHandler checkSharable(ChannelHandler handler) {
|
private static ChannelHandler checkSharable(ChannelHandler handler) {
|
||||||
if ((handler instanceof ChannelHandlerAdapter && !((ChannelHandlerAdapter) handler).isSharable()) ||
|
if ((handler instanceof ChannelHandlerAdapter && !((ChannelHandlerAdapter) handler).isSharable()) &&
|
||||||
!handler.getClass().isAnnotationPresent(ChannelHandler.Sharable.class)) {
|
!handler.getClass().isAnnotationPresent(ChannelHandler.Sharable.class)) {
|
||||||
throw new IllegalArgumentException("The handler must be Sharable");
|
throw new IllegalArgumentException("The handler must be Sharable");
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import io.netty.buffer.Unpooled;
|
|||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelHandler.Sharable;
|
import io.netty.channel.ChannelHandler.Sharable;
|
||||||
|
import io.netty.channel.ChannelHandlerAdapter;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
@ -225,4 +226,33 @@ public class Http2MultiplexCodecBuilderTest {
|
|||||||
ctx.fireChannelInactive();
|
ctx.fireChannelInactive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class SharableChannelHandler1 extends ChannelHandlerAdapter {
|
||||||
|
@Override
|
||||||
|
public boolean isSharable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Sharable
|
||||||
|
private static class SharableChannelHandler2 extends ChannelHandlerAdapter {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class UnsharableChannelHandler extends ChannelHandlerAdapter {
|
||||||
|
@Override
|
||||||
|
public boolean isSharable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSharableCheck() {
|
||||||
|
assertNotNull(Http2MultiplexCodecBuilder.forServer(new SharableChannelHandler1()));
|
||||||
|
assertNotNull(Http2MultiplexCodecBuilder.forServer(new SharableChannelHandler2()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testUnsharableHandler() {
|
||||||
|
Http2MultiplexCodecBuilder.forServer(new UnsharableChannelHandler());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user