Inheritance: BaseDataStructure
Exemplo n.º 1
0
 public void TestCommand()
 {
     ConsumerId value1 = new ConsumerId();
     value1.ConnectionId = "abc";
     value1.SessionId = 123;
     value1.Value = 456;
     
     ConsumerId value2 = new ConsumerId();
     value2.ConnectionId = "abc";
     value2.SessionId = 123;
     value2.Value = 456;
     
     ConsumerId value3 = new ConsumerId();
     value3.ConnectionId = "abc";
     value3.SessionId = 123;
     value3.Value = 457;
     
     Assert.AreEqual(value1, value2, "value1 and value2 should be equal");
     Assert.AreEqual(value1.GetHashCode(), value2.GetHashCode(), "value1 and value2 hash codes should be equal");
     
     Assert.IsTrue(!value1.Equals(value3), "value1 and value3 should not be equal");
     Assert.IsTrue(!value3.Equals(value2), "value3 and value2 should not be equal");
     
     // now lets test an IDictionary
     IDictionary dictionary = new Hashtable();
     dictionary[value1] = value3;
     
     // now lets lookup with a copy
     object actual = dictionary[value2];
     
     Assert.AreEqual(value3, actual, "Should have found item in Map using value2 as a key");
 }
Exemplo n.º 2
0
 public MessageAck(MessageDispatch dispatch, byte ackType, int messageCount) : base()
 {
     this.ackType       = ackType;
     this.consumerId    = dispatch.ConsumerId;
     this.destination   = dispatch.Destination;
     this.lastMessageId = dispatch.Message.MessageId;
     this.messageCount  = messageCount;
 }
Exemplo n.º 3
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();
		}
Exemplo n.º 4
0
        internal 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;

            this.connection.addDispatcher(consumerId, this);
            this.connection.SyncRequest(this.info);
        }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
0
		public ConsumerState removeConsumer(ConsumerId id)
		{
			ConsumerState ret = consumers[id];
			consumers.Remove(id);
			return ret;
		}
Exemplo n.º 7
0
		public ConsumerState this[ConsumerId consumerId]
		{
			get
			{
				return consumers[consumerId];
			}
		}
Exemplo n.º 8
0
		public ConsumerState getConsumerState(ConsumerId consumerId)
		{
			return consumers[consumerId];
		}
Exemplo n.º 9
0
        // 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.messageTransformation = this.session.Connection.MessageTransformation;

            if(session.Connection.MessagePrioritySupported)
            {
                this.unconsumedMessages = new SimplePriorityMessageDispatchChannel();
            }
            else
            {
                this.unconsumedMessages = new FifoMessageDispatchChannel();
            }

            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)
            {
                // Get options prefixed with "consumer.*"
                StringDictionary options = URISupport.GetProperties(destination.Options, "consumer.");
                // Extract out custom extension options "consumer.nms.*"
                StringDictionary customConsumerOptions = URISupport.ExtractProperties(options, "nms.");

                URISupport.SetProperties(this.info, options);
                URISupport.SetProperties(this, customConsumerOptions, "nms.");
            }
        }
Exemplo n.º 10
0
 internal void addDispatcher( ConsumerId id, IDispatcher dispatcher )
 {
     if(!this.closing.Value)
     {
         this.dispatchers.Add( id, dispatcher );
     }
 }
Exemplo n.º 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;
			}
Exemplo n.º 12
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;
        }
Exemplo n.º 13
0
 public void RemoveConsumer(ConsumerId objectId)
 {
     connection.removeDispatcher(objectId);
     if(!this.closing)
     {
         consumers.Remove(objectId);
     }
 }
Exemplo n.º 14
0
		// 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.");
            }
            else if(destination.PhysicalName == null)
            {
                throw new InvalidDestinationException("The destination object was not given a physical name.");
            }
            else if (destination.IsTemporary)
            {
                String physicalName = destination.PhysicalName;

                if(String.IsNullOrEmpty(physicalName))
                {
                    throw new InvalidDestinationException("Physical name of Destination should be valid: " + destination);
                }
    
                String connectionID = session.Connection.ConnectionId.Value;

                if(physicalName.IndexOf(connectionID) < 0)
                {
                    throw new InvalidDestinationException("Cannot use a Temporary destination from another Connection");
                }
    
                if(!session.Connection.IsTempDestinationActive(destination as ActiveMQTempDestination))
                {
                    throw new InvalidDestinationException("Cannot use a Temporary destination that has been deleted");
                }
            }

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

			if(session.Connection.MessagePrioritySupported)
			{
				this.unconsumedMessages = new SimplePriorityMessageDispatchChannel();
			}
			else
			{
				this.unconsumedMessages = new FifoMessageDispatchChannel();
			}

			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)
			{
				// Get options prefixed with "consumer.*"
				StringDictionary options = URISupport.GetProperties(destination.Options, "consumer.");
				// Extract out custom extension options "consumer.nms.*"
				StringDictionary customConsumerOptions = URISupport.ExtractProperties(options, "nms.");

				URISupport.SetProperties(this.info, options);
				URISupport.SetProperties(this, customConsumerOptions, "nms.");
			}
		}
Exemplo n.º 15
0
 public ConnectionId(ConsumerId consumerId)
 {
     this.value = consumerId.ConnectionId;
 }
Exemplo n.º 16
0
 public SessionId(ConsumerId consumerId)
 {
     this.ConnectionId = consumerId.ConnectionId;
     this.value        = consumerId.SessionId;
 }
Exemplo n.º 17
0
 public virtual Response processRemoveConsumer(ConsumerId id)
 {
     return null;
 }
Exemplo n.º 18
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);

            ConsumerInfo info = (ConsumerInfo)o;
            info.ConsumerId = (ConsumerId) TightUnmarshalCachedObject(wireFormat, dataIn, bs);
            info.Browser = bs.ReadBoolean();
            info.Destination = (ActiveMQDestination) TightUnmarshalCachedObject(wireFormat, dataIn, bs);
            info.PrefetchSize = dataIn.ReadInt32();
            info.MaximumPendingMessageLimit = dataIn.ReadInt32();
            info.DispatchAsync = bs.ReadBoolean();
            info.Selector = TightUnmarshalString(dataIn, bs);
            info.SubscriptionName = TightUnmarshalString(dataIn, bs);
            info.NoLocal = bs.ReadBoolean();
            info.Exclusive = bs.ReadBoolean();
            info.Retroactive = bs.ReadBoolean();
            info.Priority = dataIn.ReadByte();

            if (bs.ReadBoolean()) {
                short size = dataIn.ReadInt16();
                BrokerId[] value = new BrokerId[size];
                for( int i=0; i < size; i++ ) {
                    value[i] = (BrokerId) TightUnmarshalNestedObject(wireFormat,dataIn, bs);
                }
                info.BrokerPath = value;
            }
            else {
                info.BrokerPath = null;
            }
            info.AdditionalPredicate = (BooleanExpression) TightUnmarshalNestedObject(wireFormat, dataIn, bs);
            info.NetworkSubscription = bs.ReadBoolean();
            info.OptimizedAcknowledge = bs.ReadBoolean();
            info.NoRangeAcks = bs.ReadBoolean();

            if (bs.ReadBoolean()) {
                short size = dataIn.ReadInt16();
                ConsumerId[] value = new ConsumerId[size];
                for( int i=0; i < size; i++ ) {
                    value[i] = (ConsumerId) TightUnmarshalNestedObject(wireFormat,dataIn, bs);
                }
                info.NetworkConsumerPath = value;
            }
            else {
                info.NetworkConsumerPath = null;
            }
        }
Exemplo n.º 19
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 = connectionStates[connectionId];
                 if(cs != null)
                 {
                     SessionState ss = cs[sessionId];
                     if(ss != null)
                     {
                         ss.removeConsumer(id);
                     }
                 }
             }
         }
     }
     return TRACKED_RESPONSE_MARKER;
 }
Exemplo n.º 20
0
 internal void removeDispatcher( ConsumerId id )
 {
     if(!this.closing.Value)
     {
         this.dispatchers.Remove( id );
     }
 }
Exemplo n.º 21
0
        /// <summary>
        /// Check and ensure that the connection objcet is connected.  If it is not
        /// connected or is closed, a ConnectionClosedException is thrown.
        /// </summary>
        internal void CheckConnected()
        {
            if(closed.Value)
            {
                throw new ConnectionClosedException();
            }

            if(!connected.Value)
            {
                DateTime timeoutTime = DateTime.Now + this.RequestTimeout;
                int waitCount = 1;

                while(true)
                {
                    if(Monitor.TryEnter(checkConnectedLock))
                    {
                        try
                        {
                            if(!connected.Value)
                            {
                                if(!this.userSpecifiedClientID)
                                {
                                    this.info.ClientId = this.clientIdGenerator.GenerateId();
                                }

                                try
                                {
                                    if(null != transport)
                                    {
                                        // Send the connection and see if an ack/nak is returned.
                                        Response response = transport.Request(this.info, this.RequestTimeout);
                                        if(!(response is ExceptionResponse))
                                        {
                                            connected.Value = true;
                                            if(this.watchTopicAdviosires)
                                            {
                                                ConsumerId id = new ConsumerId(
                                                    new SessionId(info.ConnectionId, -1),
                                                    Interlocked.Increment(ref this.consumerIdCounter));
                                                this.advisoryConsumer = new AdvisoryConsumer(this, id);
                                            }
                                        }
                                    }
                                }
                                catch
                                {
                                }
                            }
                        }
                        finally
                        {
                            Monitor.Exit(checkConnectedLock);
                        }
                    }

                    if(connected.Value || DateTime.Now > timeoutTime)
                    {
                        break;
                    }

                    // Back off from being overly aggressive.  Having too many threads
                    // aggressively trying to connect to a down broker pegs the CPU.
                    Thread.Sleep(5 * (waitCount++));
                }

                if(!connected.Value)
                {
                    throw new ConnectionClosedException();
                }
            }
        }