// Constructor internal to prevent clients from creating an instance.
        internal MessageConsumer(Session session, ConsumerId id, ActiveMQDestination destination,
                                 String name, String selector, int prefetch, int maxPendingMessageCount,
                                 bool noLocal, bool browser, bool dispatchAsync)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Consumer cannot receive on Null Destinations.");
            }

            this.session          = session;
            this.redeliveryPolicy = this.session.Connection.RedeliveryPolicy;

            this.info                            = new ConsumerInfo();
            this.info.ConsumerId                 = id;
            this.info.Destination                = destination;
            this.info.SubscriptionName           = name;
            this.info.Selector                   = selector;
            this.info.PrefetchSize               = prefetch;
            this.info.MaximumPendingMessageLimit = maxPendingMessageCount;
            this.info.NoLocal                    = noLocal;
            this.info.Browser                    = browser;
            this.info.DispatchAsync              = dispatchAsync;
            this.info.Retroactive                = session.Retroactive;
            this.info.Exclusive                  = session.Exclusive;
            this.info.Priority                   = session.Priority;

            // If the destination contained a URI query, then use it to set public properties
            // on the ConsumerInfo
            if (destination.Options != null)
            {
                URISupport.SetProperties(this.info, destination.Options, "consumer.");
            }
        }
Example #2
0
 public MessageDispatch(ConsumerId consumerId, Destination destination, BytesMessage message, Int32 redeliveryCounter)
 {
     ConsumerId        = consumerId;
     Destination       = destination;
     Message           = message;
     RedeliveryCounter = redeliveryCounter;
 }
Example #3
0
 internal virtual MessageConsumer DoCreateMessageConsumer(
     ConsumerId id, ActiveMQDestination destination, string name, string selector,
     int prefetch, int maxPending, bool noLocal)
 {
     return(new MessageConsumer(this, id, destination, name, selector, prefetch,
                                maxPending, noLocal, false, this.DispatchAsync));
 }
Example #4
0
        public IMessageConsumer CreateConsumer(IDestination destination, string selector, bool noLocal)
        {
            ConsumerInfo command = CreateConsumerInfo(destination, selector);

            command.NoLocal             = noLocal;
            command.AcknowledgementMode = this.AcknowledgementMode;

            ConsumerId      consumerId = command.ConsumerId;
            MessageConsumer consumer   = null;

            try
            {
                consumer = new MessageConsumer(this, command, this.AcknowledgementMode);
                // lets register the consumer first in case we start dispatching messages immediately
                consumers[consumerId] = consumer;
                this.DoSend(command);
                return(consumer);
            }
            catch (Exception)
            {
                if (consumer != null)
                {
                    consumer.Close();
                }

                throw;
            }
        }
Example #5
0
        // Constructor internal to prevent clients from creating an instance.
        internal MessageConsumer(Session session, ConsumerId id, IDestination destination, String name, String selector, Int32 prefetch, Boolean noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Consumer cannot receive on null Destinations.");
            }

            _session         = session;
            RedeliveryPolicy = _session.Connection.RedeliveryPolicy;

            ConsumerInfo = new ConsumerInfo
            {
                ConsumerId                 = id,
                Destination                = Destination.Transform(destination),
                SubscriptionName           = name,
                Selector                   = selector,
                PrefetchSize               = prefetch,
                MaximumPendingMessageLimit = session.Connection.PrefetchPolicy.MaximumPendingMessageLimit,
                NoLocal       = noLocal,
                DispatchAsync = session.DispatchAsync,
                Retroactive   = session.Retroactive,
                Exclusive     = session.Exclusive,
                Priority      = session.Priority,
                AckMode       = session.AcknowledgementMode
            };

            // Removed unused consumer. options (ConsumerInfo => "consumer.")
            // TODO: Implement settings?

            // Removed unused message consumer. options (this => "consumer.nms.")
            // TODO: Implement settings?
        }
Example #6
0
        public IMessageConsumer CreateDurableConsumer(
            ITopic destination,
            string name,
            string selector,
            bool noLocal)
        {
            ConsumerInfo command    = CreateConsumerInfo(destination, selector);
            ConsumerId   consumerId = command.ConsumerId;

            command.SubscriptionName = name;
            command.NoLocal          = noLocal;

            try
            {
                MessageConsumer consumer = new MessageConsumer(this, command, acknowledgementMode);
                // lets register the consumer first in case we start dispatching messages immediately
                connection.AddConsumer(consumerId, consumer);

                connection.SyncRequest(command);

                consumers[consumerId] = consumer;
                return(consumer);
            }
            catch (Exception e)
            {
                connection.RemoveConsumer(consumerId);
                throw e;
            }
        }
Example #7
0
 public ConsumerState this[ConsumerId consumerId]
 {
     get
     {
         return(consumers[consumerId]);
     }
 }
Example #8
0
        protected virtual ConsumerInfo CreateConsumerInfo(IDestination destination, string selector)
        {
            ConsumerInfo answer = new ConsumerInfo();
            ConsumerId   id     = new ConsumerId();

            id.ConnectionId = info.SessionId.ConnectionId;
            id.SessionId    = info.SessionId.Value;
            lock (this)
            {
                id.Value = ++consumerCounter;
            }
            answer.ConsumerId    = id;
            answer.Destination   = ActiveMQDestination.Transform(destination);
            answer.Selector      = selector;
            answer.PrefetchSize  = prefetchSize;
            answer.Priority      = priority;
            answer.Exclusive     = exclusive;
            answer.DispatchAsync = dispatchAsync;
            answer.Retroactive   = retroactive;

            // If the destination contained a URI query, then use it to set public properties
            // on the ConsumerInfo
            ActiveMQDestination amqDestination = destination as ActiveMQDestination;

            if (amqDestination != null && amqDestination.Options != null)
            {
                Util.URISupport.SetProperties(answer, amqDestination.Options, "consumer.");
            }

            return(answer);
        }
Example #9
0
        public override Response ProcessRemoveConsumer(ConsumerId id)
        {
            if (id != null)
            {
                SessionId sessionId = id.ParentId;
                if (sessionId != null)
                {
                    ConnectionId connectionId = sessionId.ParentId;
                    if (connectionId != null)
                    {
                        ConnectionState cs = null;

                        if (connectionStates.TryGetValue(connectionId, out cs))
                        {
                            SessionState ss = cs[sessionId];
                            if (ss != null)
                            {
                                ss.RemoveConsumer(id);
                            }
                        }
                    }
                }
            }
            return(TRACKED_RESPONSE_MARKER);
        }
Example #10
0
        public ConsumerState this[ConsumerId id]
        {
            get
            {
                                #if DEBUG
                try
                {
                                #endif
                return(consumers[id]);

                                #if DEBUG
            }
            catch (System.Collections.Generic.KeyNotFoundException ex)
            {
                // Useful for dignosing missing consumer ids
                string consumerList = string.Empty;
                foreach (ConsumerId consumerId in consumers.Keys)
                {
                    consumerList += consumerId.ToString() + "\n";
                }
                System.Diagnostics.Debug.Assert(false,
                                                string.Format("Consumer '{0}' did not exist in the consumers collection.\n\nConsumers:-\n{1}", id, consumerList));
                throw ex;
            }
                                #endif
            }
        }
Example #11
0
 public BrowsingMessageConsumer(QueueBrowser parent, Session session, ConsumerId id, ActiveMQDestination destination,
                                String name, String selector, int prefetch, int maxPendingMessageCount,
                                bool noLocal, bool browser, bool dispatchAsync)
     : base(session, id, destination, name, selector, prefetch, maxPendingMessageCount, noLocal, browser, dispatchAsync)
 {
     this.parent = parent;
 }
Example #12
0
        public ConsumerState removeConsumer(ConsumerId id)
        {
            ConsumerState ret = consumers[id];

            consumers.Remove(id);
            return(ret);
        }
Example #13
0
 internal void addDispatcher(ConsumerId id, IDispatcher dispatcher)
 {
     if (!this.closing.Value)
     {
         this.dispatchers.Add(id, dispatcher);
     }
 }
Example #14
0
 internal void removeDispatcher(ConsumerId id)
 {
     if (!this.closing.Value)
     {
         this.dispatchers.Remove(id);
     }
 }
Example #15
0
        public IMessageConsumer CreateDurableConsumer(ITopic destination, string name, string selector, bool noLocal)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Cannot create a Consumer with a Null destination");
            }

            ConsumerInfo command    = CreateConsumerInfo(destination, selector);
            ConsumerId   consumerId = command.ConsumerId;

            command.SubscriptionName = name;
            command.NoLocal          = noLocal;
            MessageConsumer consumer = null;

            try
            {
                consumer = new MessageConsumer(this, command, this.AcknowledgementMode);
                // lets register the consumer first in case we start dispatching messages immediately
                consumers[consumerId] = consumer;
                this.DoSend(command);
            }
            catch (Exception)
            {
                if (consumer != null)
                {
                    consumer.Close();
                }

                throw;
            }

            return(consumer);
        }
Example #16
0
        public ConsumerState this[ConsumerId id]
        {
            get
            {
                ConsumerState consumerState = null;

                consumers.TryGetValue(id, out consumerState);

#if DEBUG
                if (null == consumerState)
                {
                    // Useful for dignosing missing consumer ids
                    string consumerList = string.Empty;
                    foreach (ConsumerId consumerId in consumers.Keys)
                    {
                        consumerList += consumerId.ToString() + "\n";
                    }

                    System.Diagnostics.Debug.Assert(false,
                                                    string.Format("Consumer '{0}' did not exist in the consumers collection.\n\nConsumers:-\n{1}", id, consumerList));
                }
#endif
                return(consumerState);
            }
        }
Example #17
0
        public ConsumerState removeConsumer(ConsumerId id)
        {
            ConsumerState ret = null;

            consumers.TryGetValue(id, out ret);
            consumers.Remove(id);
            return(ret);
        }
Example #18
0
        public void AddConsumer(MessageConsumer consumer)
        {
            ConsumerId id = consumer.ConsumerId;

            // Registered with Connection before we register at the broker.
            consumers[id] = consumer;
            connection.addDispatcher(id, this);
        }
Example #19
0
 public void DisposeOf(ConsumerId objectId)
 {
     Connection.RemoveDispatcher(objectId);
     if (!_closing)
     {
         _consumers.Remove(objectId);
     }
 }
 public void DisposeOf(ConsumerId objectId)
 {
     connection.removeDispatcher(objectId);
     if (!this.closing)
     {
         consumers.Remove(objectId);
     }
 }
Example #21
0
        //
        // Write a object instance to data output stream
        //
        public override void LooseMarshal(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut)
        {
            ConsumerId info = (ConsumerId)o;

            base.LooseMarshal(wireFormat, o, dataOut);
            LooseMarshalString(info.ConnectionId, dataOut);
            LooseMarshalLong(wireFormat, info.SessionId, dataOut);
            LooseMarshalLong(wireFormat, info.Value, dataOut);
        }
Example #22
0
 internal QueueBrowser(Session session, ConsumerId consumerId, ActiveMQDestination destination, string selector, bool dispatchAsync)
 {
     this.session       = session;
     this.consumerId    = consumerId;
     this.destination   = destination;
     this.selector      = selector;
     this.dispatchAsync = dispatchAsync;
     this.consumer      = CreateConsumer();
 }
Example #23
0
 internal NetTxMessageConsumer(Session session, ConsumerId id, ActiveMQDestination destination,
                               string name, string selector, int prefetch, int maxPendingMessageCount,
                               bool noLocal, bool browser, bool dispatchAsync) :
     base(session, id, destination, name, selector, prefetch,
          maxPendingMessageCount, noLocal, browser, dispatchAsync)
 {
     this.session            = session as NetTxSession;
     this.transactionContext = session.TransactionContext as NetTxTransactionContext;
 }
Example #24
0
 private AdvisoryConsumer(Connection connection, ConsumerId consumerId) : base()
 {
     this.connection        = connection;
     this.info              = new ConsumerInfo();
     this.info.ConsumerId   = consumerId;
     this.info.Destination  = AdvisorySupport.TEMP_DESTINATION_COMPOSITE_ADVISORY_TOPIC;
     this.info.PrefetchSize = 1000;
     this.info.NoLocal      = true;
 }
Example #25
0
        public ConsumerId GetNextConsumerId()
        {
            ConsumerId id = new ConsumerId();

            id.ConnectionId = info.SessionId.ConnectionId;
            id.SessionId    = info.SessionId.Value;
            id.Value        = Interlocked.Increment(ref consumerCounter);

            return(id);
        }
Example #26
0
        //
        // Write a object instance to data output stream
        //
        public override void TightMarshal2(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut, BooleanStream bs)
        {
            base.TightMarshal2(wireFormat, o, dataOut, bs);

            ConsumerId info = (ConsumerId)o;

            TightMarshalString2(info.ConnectionId, dataOut, bs);
            TightMarshalLong2(wireFormat, info.SessionId, dataOut, bs);
            TightMarshalLong2(wireFormat, info.Value, dataOut, bs);
        }
Example #27
0
        //
        // Un-marshal an object instance from the data input stream
        //
        public override void TightUnmarshal(OpenWireFormat wireFormat, Object o, BinaryReader dataIn, BooleanStream bs)
        {
            base.TightUnmarshal(wireFormat, o, dataIn, bs);

            ConsumerId info = (ConsumerId)o;

            info.ConnectionId = TightUnmarshalString(dataIn, bs);
            info.SessionId    = TightUnmarshalLong(wireFormat, dataIn, bs);
            info.Value        = TightUnmarshalLong(wireFormat, dataIn, bs);
        }
Example #28
0
        //
        // Un-marshal an object instance from the data input stream
        //
        public override void LooseUnmarshal(OpenWireFormat wireFormat, Object o, BinaryReader dataIn)
        {
            base.LooseUnmarshal(wireFormat, o, dataIn);

            ConsumerId info = (ConsumerId)o;

            info.ConnectionId = LooseUnmarshalString(dataIn);
            info.SessionId    = LooseUnmarshalLong(wireFormat, dataIn);
            info.Value        = LooseUnmarshalLong(wireFormat, dataIn);
        }
Example #29
0
        public void DisposeOf(ConsumerId objectId, long lastDeliveredSequenceId)
        {
            connection.removeDispatcher(objectId);
            this.lastDeliveredSequenceId = Math.Min(this.lastDeliveredSequenceId, lastDeliveredSequenceId);

            if (!this.closing)
            {
                consumers.Remove(objectId);
            }
        }
Example #30
0
        private ConsumerId GetNextConsumerId()
        {
            var id = new ConsumerId
            {
                ConnectionId = _info.SessionId.ConnectionId,
                SessionId    = _info.SessionId.Value,
                Value        = Interlocked.Increment(ref _consumerCounter)
            };

            return(id);
        }
Example #31
0
 public SessionId( ConsumerId consumerId )
 {
     this.ConnectionId = consumerId.ConnectionId;
     this.value = consumerId.SessionId;
 }
Example #32
0
 public ConnectionId( ConsumerId consumerId )
 {
     this.value = consumerId.ConnectionId;
 }
Example #33
0
        public virtual bool Equals(ConsumerId that)
        {
            if(!Equals(this.ConnectionId, that.ConnectionId))
            {
                return false;
            }
            if(!Equals(this.SessionId, that.SessionId))
            {
                return false;
            }
            if(!Equals(this.Value, that.Value))
            {
                return false;
            }

            return true;
        }