log.debug("{} is already {}", this, state.get() == CLOSED ? "closed" : "closing");
}
} else {
if (state.compareAndSet(0, GRACEFUL)) {
log.debug("Closing {} gracefully", this);
SshFuture grace = doCloseGracefully();
if (grace != null) {
grace.addListener(new SshFutureListener() {
public void operationComplete(SshFuture future) {
if (state.compareAndSet(GRACEFUL, IMMEDIATE)) {
doCloseImmediately();
}
}