if (heapState != null) {
nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, sessionId, "Subscription termination received for subscription %s with reason %s", subscriptionId, reason);
if (reason == Subscription.CloseReason.REQUESTED_BY_SUBSCRIBER || reason == Subscription.CloseReason.REQUESTED_BY_SUBSCRIBER_ADMINISTRATOR) {
try {
nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, session, "Notifying server that client wants to terminate subscription %s", subscriptionId);
NioUtils.writeEventMessageToSession(session, new TerminateSubscription(heapId, subscriptionId, reason.name()), objectIOFactory);
} catch (Exception ioe) {
// if we can't write to the stream to tell the server that the client wants to unsub, then it's likely the session is already
// gone. however, we'll log a message to let people know and then request a close of the session to make sure.
nioLogger.log(NioLogger.LoggingLevel.SESSION, session, "Error occurred whilst trying to inform server of subscription termination, closing session");
logger.log(Level.INFO, "Error occurred whilst trying to inform server of subscription termination, closing session", ioe);