Fix NoSuchElementException raised by ChannelInitializer
.. again.
This commit is contained in:
parent
3d54a323ca
commit
524726fd99
@ -60,23 +60,21 @@ public abstract class ChannelInitializer<C extends Channel> extends ChannelHandl
|
|||||||
*/
|
*/
|
||||||
protected abstract void initChannel(C ch) throws Exception;
|
protected abstract void initChannel(C ch) throws Exception;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
public final void channelRegistered(ChannelHandlerContext ctx)
|
@SuppressWarnings("unchecked")
|
||||||
throws Exception {
|
public final void channelRegistered(ChannelHandlerContext ctx) throws Exception {
|
||||||
boolean removed = false;
|
ChannelPipeline pipeline = ctx.pipeline();
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
initChannel((C) ctx.channel());
|
initChannel((C) ctx.channel());
|
||||||
ctx.pipeline().remove(this);
|
pipeline.remove(this);
|
||||||
removed = true;
|
|
||||||
ctx.fireChannelRegistered();
|
ctx.fireChannelRegistered();
|
||||||
success = true;
|
success = true;
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
logger.warn("Failed to initialize a channel. Closing: " + ctx.channel(), t);
|
logger.warn("Failed to initialize a channel. Closing: " + ctx.channel(), t);
|
||||||
} finally {
|
} finally {
|
||||||
if (!removed) {
|
if (pipeline.context(this) != null) {
|
||||||
ctx.pipeline().remove(this);
|
pipeline.remove(this);
|
||||||
}
|
}
|
||||||
if (!success) {
|
if (!success) {
|
||||||
ctx.close();
|
ctx.close();
|
||||||
|
Loading…
Reference in New Issue
Block a user