Allow empty handler list when creating a new EmbeddedChannel
.. so that it can be used for dynamically initialized pipelines - Fixes #1899
This commit is contained in:
parent
517da2b46a
commit
a65f097d53
@ -44,7 +44,8 @@ import java.util.Queue;
|
|||||||
*/
|
*/
|
||||||
public class EmbeddedChannel extends AbstractChannel {
|
public class EmbeddedChannel extends AbstractChannel {
|
||||||
|
|
||||||
private enum State { OPEN, ACTIVE, CLOSED };
|
private static final ChannelHandler[] EMPTY_HANDLERS = new ChannelHandler[0];
|
||||||
|
private enum State { OPEN, ACTIVE, CLOSED }
|
||||||
|
|
||||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(EmbeddedChannel.class);
|
private static final InternalLogger logger = InternalLoggerFactory.getInstance(EmbeddedChannel.class);
|
||||||
|
|
||||||
@ -60,7 +61,14 @@ public class EmbeddedChannel extends AbstractChannel {
|
|||||||
private State state;
|
private State state;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance
|
* Create a new instance with an empty pipeline.
|
||||||
|
*/
|
||||||
|
public EmbeddedChannel() {
|
||||||
|
this(EMPTY_HANDLERS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance with the pipeline initialized with the specified handlers.
|
||||||
*
|
*
|
||||||
* @param handlers the @link ChannelHandler}s which will be add in the {@link ChannelPipeline}
|
* @param handlers the @link ChannelHandler}s which will be add in the {@link ChannelPipeline}
|
||||||
*/
|
*/
|
||||||
@ -71,20 +79,14 @@ public class EmbeddedChannel extends AbstractChannel {
|
|||||||
throw new NullPointerException("handlers");
|
throw new NullPointerException("handlers");
|
||||||
}
|
}
|
||||||
|
|
||||||
int nHandlers = 0;
|
|
||||||
ChannelPipeline p = pipeline();
|
ChannelPipeline p = pipeline();
|
||||||
for (ChannelHandler h: handlers) {
|
for (ChannelHandler h: handlers) {
|
||||||
if (h == null) {
|
if (h == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
nHandlers ++;
|
|
||||||
p.addLast(h);
|
p.addLast(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nHandlers == 0) {
|
|
||||||
throw new IllegalArgumentException("handlers is empty.");
|
|
||||||
}
|
|
||||||
|
|
||||||
p.addLast(new LastInboundHandler());
|
p.addLast(new LastInboundHandler());
|
||||||
loop.register(this);
|
loop.register(this);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user