attemptingInvalidationClientNotification = notifyClient;
// Build a subscription invalidation message and push to the client if it is still valid.
if (notifyClient && flexClient != null && flexClient.isValid())
{
CommandMessage msg = new CommandMessage();
msg.setDestination(destination.getId());
msg.setClientId(clientId);
msg.setOperation(CommandMessage.SUBSCRIPTION_INVALIDATE_OPERATION);
Set subscriberIds = new TreeSet();
subscriberIds.add(clientId);
try
{
((MessageService)destination.getService()).pushMessageToClients(destination, subscriberIds, msg, false /* don't eval selector */);
}
catch (MessageException ignore) {}
}
// Notify messageClientDestroyed listeners that we're being invalidated.
if (destroyedListeners != null && !destroyedListeners.isEmpty())
{
for (Iterator iter = destroyedListeners.iterator(); iter.hasNext();)
{
((MessageClientListener)iter.next()).messageClientDestroyed(this);
}
destroyedListeners.clear();
}
// And generate unsubscribe messages for all of the MessageClient's subscriptions and
// route them to the destination this MessageClient is subscribed to.
// The reason we send a message to the service rather than just going straight to the SubscriptionManager
// is that some adapters manage their own subscription state (i.e. JMS) in addition to us keeping track of
// things with our SubscriptionManager.
ArrayList unsubMessages = new ArrayList();
synchronized (lock)
{
for (Iterator iter = subscriptions.iterator(); iter.hasNext();)
{
SubscriptionInfo subInfo = (SubscriptionInfo)iter.next();
CommandMessage unsubMessage = new CommandMessage();
unsubMessage.setDestination(destination.getId());
unsubMessage.setClientId(clientId);
unsubMessage.setOperation(CommandMessage.UNSUBSCRIBE_OPERATION);
unsubMessage.setHeader(CommandMessage.SUBSCRIPTION_INVALIDATED_HEADER, Boolean.TRUE);
unsubMessage.setHeader(CommandMessage.SELECTOR_HEADER, subInfo.selector);
unsubMessage.setHeader(AsyncMessage.SUBTOPIC_HEADER_NAME, subInfo.subtopic);
unsubMessages.add(unsubMessage);
}
}
// Release the lock and send the unsub messages.
for (Iterator iter = unsubMessages.iterator(); iter.hasNext();)