void () { if (myState.compareAndSet(State.CONNECTED, State.DISCONNECTING)) { try { final ChannelFuture future = myConnectFuture; if (future != null) { try { beforeDisconnect(); } catch (Throwable e) { LOG.error(e); } final ChannelFuture closeFuture = future.channel().close(); closeFuture.awaitUninterruptibly(); } } finally { myConnectFuture = null; myState.compareAndSet(State.DISCONNECTING, State.DISCONNECTED); try { onDisconnect(); } catch (Throwable e) { LOG.error(e); } } } }