public void SubscribeToQueue(string queueName)
        {
            Queue queue;

            if (!this.Server.Queues.TryGetValue(queueName, out queue))
            {
                return;
            }

            this.subscriptionDataLock.EnterWriteLock();

            if (this.RootContext == null || !this.RootContext.AddQueue(queue))
            {
                QueueGroupContext group = new QueueGroupContext(queue);
                group.Next       = this.RootContext;
                this.RootContext = group;
            }

            this.subscriptionDataLock.ExitWriteLock();

            queue.AddSubscriber(this.LogicalConnection);//TODO. Check locks.

            this.Server.MeasurementMgr.IncrementCumulativeValue(Analytics.MeasurementMgr.Metrics.BroadcastSubscriptionCount);
            this.Server.MeasurementMgr.IncrementDistributionValue(Analytics.MeasurementMgr.Metrics.BroadcastSubscriptionCountPerQueue, queue.Id);
        }
        public void UnsubscribeFromAll()
        {
            this.subscriptionDataLock.EnterWriteLock();

            this.RootContext = null;

            this.subscriptionDataLock.ExitWriteLock();
        }
        public void CheckAndProcessPendingBroadcast(bool somethingHappened)
        {
            if (somethingHappened)
            {
                this.skipCheckNextMessage = false;
            }

            if (Interlocked.CompareExchange(ref broadcastRunFlag, 1, 0) == 1)
            {
                return;
            }

            if (this.skipCheckNextMessage)
            {
                return;
            }

            if (this.isWriteInProgress)
            {
                return;
            }

            this.subscriptionDataLock.EnterReadLock();

            QueueGroupContext context = this.RootContext;

            while (context != null)
            {
                if (!this.CanPushBroadcast)
                {
                    break;
                }

                Queue  originQueue;
                object message = context.GetNextMessage(out originQueue);

                if (message != null)
                {
                    Buffer bytes;
                    this.Server.Serializer.Serialize(message, out bytes);
                    this.SendSerializedMessage(bytes);

                    this.Server.MeasurementMgr.IncrementDistributionValue(Analytics.MeasurementMgr.Metrics.BroadcastSentMessageVolPerQueue, originQueue.Id, 1);
                    this.Server.MeasurementMgr.IncrementAvgDistributionValue(Analytics.MeasurementMgr.Metrics.BroadcastAvgMessageSizePerQueue, originQueue.Id, bytes.Size);

                    this.Server.MeasurementMgr.IncrementKeyedAveragedValue(Analytics.MeasurementMgr.Metrics.BroadcastSentMessagePerConnection, this.InternalId, 1);
                }
                else
                {
                    context = context.Next;
                }
            }

            broadcastRunFlag = 0;
            this.subscriptionDataLock.ExitReadLock();
        }
Esempio n. 4
0
        public void RemoveQueue(string queueName)
        {
            QueueContext context  = this.Head;
            QueueContext previous = null;

            while (context != null)
            {
                if (context.Queue.Name == queueName)
                {
                    break;
                }

                previous = context;
                context  = context.Next;
            }

            if (context != null)
            {
                if (previous != null)
                {
                    previous.Next = context.Next;
                }
                else
                {
                    this.Head = context.Next;
                }

                //
                context.Next = null;
                if (this.Current == context)
                {
                    this.Current = this.Head;
                }
            }
            else
            {
                if (this.Next != null)
                {
                    this.Next.RemoveQueue(queueName);

                    QueueGroupContext nextGroup = this.Next;

                    if (nextGroup.Head == null)
                    {
                        this.Next      = nextGroup.Next;
                        nextGroup.Next = null;
                    }
                }
            }

            //
        }
        public void UnsubscribeFromQueue(string queueName)
        {
            this.subscriptionDataLock.EnterWriteLock();

            if (this.RootContext != null)
            {
                this.RootContext.RemoveQueue(queueName);
                QueueGroupContext nextGroup = this.RootContext;

                if (nextGroup.Head == null)
                {
                    this.RootContext = nextGroup.Next;
                    nextGroup.Next   = null;
                }
            }

            this.subscriptionDataLock.ExitWriteLock();
        }
Esempio n. 6
0
        public bool AddQueue(Queue queue)
        {
            if (this.Head.Queue.QueueOptions.Priority < queue.QueueOptions.Priority)
            {
                return(false);
            }

            if (this.Head.Queue.QueueOptions.Priority == queue.QueueOptions.Priority)
            {
                this.AddQueueIntern(queue);
                return(true);
            }

            // queue has a lower priority:
            if (this.Next == null || !this.Next.AddQueue(queue))
            {
                QueueGroupContext group = new QueueGroupContext(queue);
                group.Next = this.Next;
                this.Next  = group;
            }

            return(true);
        }