Object selectorExpression = commandMessage.getHeaders().get(CommandMessage.SELECTOR_HEADER);
// Create a JMSConsumer for this destination and associate it with the client id
if (settings.getDestinationType().equals(TOPIC))
{
MessageClient existingMessageClient = null;
// This could happen when client disconnects without unsubscribing first.
if (topicConsumers.containsKey(clientId))
{
removeConsumer(clientId, true /*unsubscribe*/, false /*invalidate*/, null);
existingMessageClient = messageClients.get(clientId);
}
// Create the consumer.
consumer = new JMSTopicConsumer();
consumer.initialize(settings);
if (selectorExpression != null)
consumer.setSelectorExpression((String)selectorExpression);
// Need to build a subscription name, in case durable subscriptions are used.
((JMSTopicConsumer)consumer).setDurableSubscriptionName(buildSubscriptionName(clientId));
consumer.setMessageReceiver(buildMessageReceiver(consumer));
// Add JMSAdapter as JMS exception and message listener.
consumer.addJMSExceptionListener(this);
consumer.addJMSMessageListener(this);
topicConsumers.put(clientId, consumer);
consumerToClientId.put(consumer, clientId);
// Means client was disconnected without unsubscribing, hence no
// new message client will be created. Make sure the old one is
// wired up with the new JMS consumer properly.
if (existingMessageClient != null)
messageClientCreated(existingMessageClient);
}
else if (settings.getDestinationType().equals(QUEUE))
{
MessageClient existingMessageClient = null;
if (queueConsumers.containsKey(clientId))
{
removeConsumer(clientId, true /*unsubscribe*/, false /*invalidate*/, null);
existingMessageClient = messageClients.get(clientId);
}