コード例 #1
0
        internal ChannelQueue(Channel channel,
                              ushort id,
                              ChannelQueueOptions options,
                              IMessageDeliveryHandler deliveryHandler)
        {
            Channel         = channel;
            Id              = id;
            Options         = options;
            Status          = options.Status;
            DeliveryHandler = deliveryHandler;
            State           = QueueStateFactory.Create(this, options.Status);

            TimeKeeper = new QueueTimeKeeper(this);
            TimeKeeper.Run();

            if (options.WaitForAcknowledge)
            {
                _ackSync = new SemaphoreSlim(1, 1);
            }

            _triggerTimer = new Timer(a =>
            {
                if (!_triggering && State.TriggerSupported)
                {
                    _ = Trigger();
                }
            }, null, TimeSpan.FromSeconds(5000), TimeSpan.FromSeconds(5000));
        }
コード例 #2
0
        /// <summary>
        /// Initializes queue to first use
        /// </summary>
        internal void InitializeQueue(IMessageDeliveryHandler deliveryHandler = null)
        {
            if (IsInitialized)
            {
                return;
            }

            IsInitialized = true;
            if (deliveryHandler != null)
            {
                DeliveryHandler = deliveryHandler;
            }

            if (DeliveryHandler == null)
            {
                throw new ArgumentNullException("Queue has no delivery handler: " + Name);
            }

            State = QueueStateFactory.Create(this, Options.Status);

            TimeKeeper = new QueueTimeKeeper(this);
            TimeKeeper.Run();

            _ackSync = new SemaphoreSlim(1, 1);

            _triggerTimer = new Timer(a =>
            {
                if (!_triggering && State.TriggerSupported)
                {
                    _ = Trigger();
                }

                _ = CheckAutoDestroy();
            }, null, TimeSpan.FromMilliseconds(5000), TimeSpan.FromMilliseconds(5000));
        }
コード例 #3
0
        /// <summary>
        /// Sets status of the queue
        /// </summary>
        public async Task SetStatus(QueueStatus status, IMessageDeliveryHandler newDeliveryHandler = null)
        {
            QueueStatus prevStatus = Status;
            IQueueState prevState  = State;

            if (prevStatus == status)
            {
                return;
            }

            QueueStatusAction leave = await State.LeaveStatus(status);

            if (leave == QueueStatusAction.Deny)
            {
                return;
            }

            if (leave == QueueStatusAction.DenyAndTrigger)
            {
                await Trigger();

                return;
            }

            Status = status;
            State  = QueueStateFactory.Create(this, status);

            QueueStatusAction enter = await State.EnterStatus(prevStatus);

            if (enter == QueueStatusAction.Deny || enter == QueueStatusAction.DenyAndTrigger)
            {
                Status = prevStatus;
                State  = prevState;
                await prevState.EnterStatus(prevStatus);

                if (enter == QueueStatusAction.DenyAndTrigger)
                {
                    await Trigger();
                }

                return;
            }

            if (Channel.EventHandler != null)
            {
                await Channel.EventHandler.OnQueueStatusChanged(this, prevStatus, status);
            }

            if (enter == QueueStatusAction.AllowAndTrigger)
            {
                _ = Trigger();
            }
        }
コード例 #4
0
        /// <summary>
        /// Sets status of the queue
        /// </summary>
        public async Task SetStatus(QueueStatus status, IMessageDeliveryHandler newDeliveryHandler = null)
        {
            QueueStatus prevStatus = Status;

            try
            {
                IQueueState prevState = State;
                if (prevStatus == status)
                {
                    return;
                }

                QueueStatusAction leave = await State.LeaveStatus(status);

                if (leave == QueueStatusAction.Deny)
                {
                    return;
                }

                if (leave == QueueStatusAction.DenyAndTrigger)
                {
                    await Trigger();

                    return;
                }

                Status = status;
                State  = QueueStateFactory.Create(this, status);

                QueueStatusAction enter = await State.EnterStatus(prevStatus);

                if (enter == QueueStatusAction.Deny || enter == QueueStatusAction.DenyAndTrigger)
                {
                    Status = prevStatus;
                    State  = prevState;
                    await prevState.EnterStatus(prevStatus);

                    if (enter == QueueStatusAction.DenyAndTrigger)
                    {
                        await Trigger();
                    }

                    return;
                }

                if (newDeliveryHandler != null)
                {
                    DeliveryHandler = newDeliveryHandler;
                }

                foreach (IQueueEventHandler handler in Server.QueueEventHandlers)
                {
                    await handler.OnStatusChanged(this, prevStatus, status);
                }

                if (enter == QueueStatusAction.AllowAndTrigger)
                {
                    _ = Trigger();
                }
            }
            catch (Exception e)
            {
                Server.SendError("SET_QUEUE_STATUS", e, $"QueueName:{Name}, PrevStatus:{prevStatus} NextStatus:{status}");
            }
        }