netty - Is there a possibility that pipeline.fireChannelActive() is executed twice when executing ServerBootstrap.bind()? -
all following code netty4.0.31.final. serverbootstrap
's channel nioserversocketchannel
.
the main logic of serverbootstrap.bind(int)
in abstractbootstrap.dobind(socketaddress)
:
private channelfuture dobind(final socketaddress localaddress) { final channelfuture regfuture = initandregister(); ... if (regfuture.isdone()) { ... dobind0(regfuture, channel, localaddress, promise); ... } else { regfuture.addlistener(new channelfuturelistener() { @override public void operationcomplete(channelfuture future) throws exception { ... dobind0(regfuture, channel, localaddress, promise); } }); } }
the code in initandregister()
goes abstractunsafe.register0(channelpromise promise)
:
private void register0(channelpromise promise) { try { ... boolean firstregistration = neverregistered; doregister(); ... if (firstregistration && isactive()) { pipeline.firechannelactive(); } } catch (throwable t) { ... } }
as can see, pipeline.firechannelactive()
may executed here.
let's abstractbootstrap.dobind(socketaddress)
,in dobind0(regfuture, channel, localaddress, promise)
code goes abstractunsafe.bind(socketaddress,channelpromise)
:
public final void bind(final socketaddress localaddress, final channelpromise promise) { ... boolean wasactive = isactive(); try { dobind(localaddress); } catch (throwable t) { ... } if (!wasactive && isactive()) { invokelater(new onetimetask() { @override public void run() { pipeline.firechannelactive(); } }); } ... }
as can see, pipeline.firechannelactive()
may executed here.
so, there possibility pipeline.firechannelactive()
executed twice when creating , binding 1 nioserversocketchannel
?
not unless isactive
can flip flop true false true again in flow pointed out. think can go active once, false -> true -> false
relevant code post:
boolean firstregistration = neverregistered; ... if (firstregistration && isactive()) { pipeline.firechannelactive(); // isactive must true } ... boolean wasactive = isactive(); ... // if firechannelactive fired, wasactive true, // preventing firing again if (!wasactive && isactive()) { invokelater(new onetimetask() { @override public void run() { pipeline.firechannelactive();
Comments
Post a Comment