void stop(boolean failure) throws Exception {
state.setFailed(failure);
if (!stopped) {
protocolHandler.stop();
subscriptionManager.stop();
mqttPublishManager.stop();
if (serverSession != null) {
serverSession.stop();
serverSession.close(false);}
if (internalServerSession != null) {
internalServerSession.stop();
internalServerSession.close(false);}
state.setAttached(false);state.setDisconnectedTime(System.currentTimeMillis());
state.clearTopicAliases();
if (getVersion() == MQTTVersion.MQTT_5) {
if (state.getClientSessionExpiryInterval() == 0) {
if (state.isWill() && failure) {
sendWillMessage();
}
clean(false);
stateManager.removeSessionState(connection.getClientID());
}
} else {
if (state.isWill() && failure) {
sendWillMessage();
}
if (isClean()) {
clean(false);
stateManager.removeSessionState(connection.getClientID());
}
}
}
stopped = true;
}