/** * Registers this with the associated {@link DestinationCache}s. The consumer may receive messages * immediately. * * @throws JMSException for any JMS error */ protected void init() throws JMSException { JmsTopic topic = (JmsTopic) getDestination(); // register the endpoint with the destination if (topic.isWildCard()) { // if the topic is a wild card then we need to retrieve a // set of matching destination caches. _caches = _destinations.getTopicDestinationCaches(topic); // for each cache register this endpoint as a consumer of // it's messages. Before doing so register as a destination // event listener with the DestinationManager _destinations.addDestinationEventListener(this); DestinationCache[] caches = getDestinationCaches(); for (int i = 0; i < caches.length; ++i) { caches[i].addConsumer(this); } } else { // if the topic is not a wildcard then we need to get the // destination cache. If one does not exist then we need to // create it. DestinationCache cache = _destinations.getDestinationCache(topic); _caches.put(topic, cache); cache.addConsumer(this); } }
/** * Invoked when a message cache is created. * * @param destination the destination that messages are being cached for * @param cache the corresponding cache */ public void cacheAdded(JmsDestination destination, DestinationCache cache) { if (destination instanceof JmsTopic) { JmsTopic myTopic = (JmsTopic) getDestination(); JmsTopic topic = (JmsTopic) destination; if (myTopic.match(topic) && !_caches.containsKey(topic)) { _caches.put(topic, cache); cache.addConsumer(this); } } }
/** * Determines if this consumer can consume messages from the specified destination. * * @param destination the destination * @return <code>true</code> if the consumer can consume messages from <code>destination</code>; * otherwise <code>false</code> */ public boolean canConsume(JmsDestination destination) { boolean result = false; if (destination instanceof JmsTopic) { JmsTopic topic = (JmsTopic) getDestination(); if (!topic.isWildCard()) { result = super.canConsume(destination); } else { result = topic.match((JmsTopic) destination); } } return result; }