Exemplo n.º 1
0
        private IMessageConsumer GetCachedConsumer(IDestination destination, string selector, bool noLocal, string durableSubscriptionName)
        {
            var cacheKey = new ConsumerCacheKey(destination, selector, noLocal, durableSubscriptionName);

            if (cachedConsumers.TryGetValue(cacheKey, out var consumer))
            {
                if (Log.IsDebugEnabled)
                {
                    Log.Debug("Found cached NMS MessageConsumer for destination [" + destination + "]: " + consumer);
                }
            }
            else
            {
                if (destination is ITopic topic)
                {
                    consumer = (durableSubscriptionName != null
                                    ? target.CreateDurableConsumer(topic, durableSubscriptionName, selector, noLocal)
                                    : target.CreateConsumer(topic, selector, noLocal));
                }
                else
                {
                    consumer = target.CreateConsumer(destination, selector);
                }
                if (Log.IsDebugEnabled)
                {
                    Log.Debug("Creating cached NMS MessageConsumer for destination [" + destination + "]: " + consumer);
                }
                cachedConsumers[cacheKey] = consumer;
            }
            return(new CachedMessageConsumer(consumer));
        }
Exemplo n.º 2
0
        private IMessageConsumer GetCachedConsumer(IDestination destination, string selector, bool noLocal, string durableSubscriptionName)
        {
            object           cacheKey = new ConsumerCacheKey(destination, selector, noLocal, durableSubscriptionName);
            IMessageConsumer consumer = (IMessageConsumer)cachedConsumers[cacheKey];

            if (consumer != null)
            {
                if (LOG.IsDebugEnabled)
                {
                    LOG.Debug("Found cached NMS MessageConsumer for destination [" + destination + "]: " + consumer);
                }
            }
            else
            {
                if (destination is ITopic)
                {
                    consumer = (durableSubscriptionName != null
                                    ? target.CreateDurableConsumer((ITopic)destination, durableSubscriptionName, selector, noLocal)
                                    : target.CreateConsumer(destination, selector, noLocal));
                }
                else
                {
                    consumer = target.CreateConsumer(destination, selector);
                }
                if (LOG.IsDebugEnabled)
                {
                    LOG.Debug("Creating cached NMS MessageConsumer for destination [" + destination + "]: " + consumer);
                }
                cachedConsumers[cacheKey] = consumer;
            }
            return(new CachedMessageConsumer(consumer));
        }
Exemplo n.º 3
0
        private void LogicalClose()
        {
            // Preserve rollback-on-close semantics.
            if (this.transactionOpen && this.target.Transacted)
            {
                this.transactionOpen = false;
                this.target.Rollback();
            }

            // Physically close durable subscribers at time of Session close call.
            IList ToRemove = new ArrayList();

            foreach (DictionaryEntry dictionaryEntry in cachedConsumers)
            {
                ConsumerCacheKey key = (ConsumerCacheKey)dictionaryEntry.Key;
                if (key.Subscription != null)
                {
                    ((IMessageConsumer)dictionaryEntry.Value).Close();
                    ToRemove.Add(key);
                }
            }
            foreach (ConsumerCacheKey key in ToRemove)
            {
                cachedConsumers.Remove(key);
            }

            // Allow for multiple close calls...
            if (!sessionList.Contains(this))
            {
                #region Logging

                if (LOG.IsDebugEnabled)
                {
                    LOG.Debug("Returning cached Session: " + target);
                }

                #endregion

                sessionList.Add(this); //add to end of linked list.
            }
        }
Exemplo n.º 4
0
        private void LogicalClose()
        {
            // Preserve rollback-on-close semantics.
            if (transactionOpen && target.Transacted)
            {
                transactionOpen = false;
                target.Rollback();
            }

            // Physically close durable subscribers at time of Session close call.
            var toRemove = new List <ConsumerCacheKey>();

            foreach (var dictionaryEntry in cachedConsumers)
            {
                ConsumerCacheKey key = dictionaryEntry.Key;
                if (key.Subscription != null)
                {
                    dictionaryEntry.Value.Close();
                    toRemove.Add(key);
                }
            }
            foreach (ConsumerCacheKey key in toRemove)
            {
                cachedConsumers.Remove(key);
            }

            // Allow for multiple close calls...
            if (!sessionList.Contains(this))
            {
                if (Log.IsDebugEnabled)
                {
                    Log.Debug("Returning cached Session: " + target);
                }

                sessionList.Add(this); //add to end of linked list.
            }
        }
Exemplo n.º 5
0
 protected bool Equals(ConsumerCacheKey consumerCacheKey)
 {
     if (consumerCacheKey == null)
     {
         return(false);
     }
     if (!Equals(destination, consumerCacheKey.destination))
     {
         return(false);
     }
     if (!ObjectUtils.NullSafeEquals(selector, consumerCacheKey.selector))
     {
         return(false);
     }
     if (!Equals(noLocal, consumerCacheKey.noLocal))
     {
         return(false);
     }
     if (!ObjectUtils.NullSafeEquals(subscription, consumerCacheKey.subscription))
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 6
0
 protected bool Equals(ConsumerCacheKey consumerCacheKey)
 {
     if (consumerCacheKey == null) return false;
     if (!Equals(destination, consumerCacheKey.destination)) return false;
     if (!ObjectUtils.NullSafeEquals(selector, consumerCacheKey.selector)) return false;
     if (!Equals(noLocal, consumerCacheKey.noLocal)) return false;
     if (!ObjectUtils.NullSafeEquals(subscription, consumerCacheKey.subscription)) return false;
     return true;
 }
Exemplo n.º 7
0
 private IMessageConsumer GetCachedConsumer(IDestination destination, string selector, bool noLocal, string durableSubscriptionName)
 {
     object cacheKey = new ConsumerCacheKey(destination, selector, noLocal, durableSubscriptionName);
     IMessageConsumer consumer = (IMessageConsumer)cachedConsumers[cacheKey];
     if (consumer != null)
     {
         if (LOG.IsDebugEnabled)
         {
             LOG.Debug("Found cached NMS MessageConsumer for destination [" + destination + "]: " + consumer);
         }
     }
     else
     {
         if (destination is ITopic)
         {
             consumer = (durableSubscriptionName != null
                             ? target.CreateDurableConsumer((ITopic)destination, durableSubscriptionName, selector, noLocal)
                             : target.CreateConsumer(destination, selector, noLocal));
         }
         else
         {
             consumer = target.CreateConsumer(destination, selector);
         }
         if (LOG.IsDebugEnabled)
         {
             LOG.Debug("Creating cached NMS MessageConsumer for destination [" + destination + "]: " + consumer);
         }
         cachedConsumers[cacheKey] = consumer;
     }
     return new CachedMessageConsumer(consumer);
 }