public MpscLinkedArrayQueue(int capacity)
        {
            var q = new QueueSection(capacity);

            Volatile.Write(ref consumerQueue, q);
            Volatile.Write(ref producerQueue, q);
        }
        public bool Poll(out T item)
        {
            var q      = consumerQueue;
            var a      = q.entries;
            var m      = a.Length - 1;
            var ci     = consumerIndex;
            var offset = (int)(ci) & m;

            int s = Volatile.Read(ref a[offset].state);

            if (s == 0)
            {
                item = default(T);
                return(false);
            }

            if (s == 2)
            {
                var q2 = q.next;
                a             = q2.entries;
                q.next        = null;
                consumerQueue = q2;
            }

            item = a[offset].value;
            Volatile.Write(ref a[offset].state, 0);
            Volatile.Write(ref consumerIndex, ci + 1);
            return(true);
        }
        public bool Offer(T item)
        {
            var q          = producerQueue;
            var a          = q.entries;
            var m          = a.Length - 1;
            var pi         = producerIndex;
            var offsetNext = (int)(pi + 1) & m;
            var offset     = (int)(pi) & m;

            if (Volatile.Read(ref a[offsetNext].state) != 0)
            {
                var q2 = new QueueSection(m + 1);
                var b  = q2.entries;
                b[offset].value = item;
                b[offset].state = 1;
                q.next          = q2;
                producerQueue   = q2;
                Volatile.Write(ref a[offset].state, 2);
                Volatile.Write(ref producerIndex, pi + 1);
                return(true);
            }
            a[offset].value = item;
            Volatile.Write(ref a[offset].state, 1);
            Volatile.Write(ref producerIndex, pi + 1);
            return(true);
        }
        public SpscLinkedArrayQueue(int bufferSize)
        {
            int c = QueueHelper.Pow2(Math.Max(2, bufferSize));
            var q = new QueueSection(c);

            producerQueue = q;
            Volatile.Write(ref consumerQueue, q);
        }
Пример #5
0
        public static List <IRepository> GetAllRepositories(QueueSection queueSection)
        {
            var repositorys = new List <IRepository>();

            foreach (var queue in queueSection.Queue)
            {
                repositorys.Add(GetRepository(queue.ConnectionString, queue.QueueName));
            }

            return(repositorys);
        }
        public static List<IRepository> GetAllRepositories(QueueSection queueSection)
        {
            var repositorys = new List<IRepository>();

            foreach (var queue in queueSection.Queue)
            {
                repositorys.Add(GetRepository(queue.ConnectionString, queue.QueueName));
            }

            return repositorys;
        }  
        public bool Offer(T item)
        {
            var q = Volatile.Read(ref producerQueue);
            var a = q.array;
            var n = a.Length;

            for (;;)
            {
                int offset = Volatile.Read(ref q.producerIndex);
                if (offset < n)
                {
                    offset = Interlocked.Increment(ref q.producerIndex) - 1;
                }
                if (offset >= n)
                {
                    var next = Volatile.Read(ref q.next);
                    if (next != null)
                    {
                        Interlocked.CompareExchange(ref producerQueue, next, q);
                        q = next;
                        a = next.array;
                        continue;
                    }

                    next               = new QueueSection(n);
                    a                  = next.array;
                    a[0].item          = item;
                    a[0].state         = 1;
                    next.producerIndex = 1;

                    if (Interlocked.CompareExchange(ref q.next, next, null) != null)
                    {
                        next = q.next;
                        Interlocked.CompareExchange(ref producerQueue, next, q);
                        q = next;
                        a = q.array;
                        continue;
                    }

                    Interlocked.CompareExchange(ref producerQueue, next, q);
                    return(true);
                }
                a[offset].item = item;
                Volatile.Write(ref a[offset].state, 1);
                return(true);
            }
        }
        /// <summary>
        /// Creates or gets a queue defined by configuration
        /// This method requires a queue to be configured in the application config file with the name provided in queueName
        /// </summary>
        /// <param name="queueName">The name of the queue as defined in the configuration file</param>
        /// <returns>The IQueue singleton object</returns>
        /// <example>
        /// Source Code;
        /// <code language="cs">
        /// IQueue defaultQueue = QueueFactory.CreateQueue("myqueue");
        /// </code>
        ///
        /// Configuration:
        /// <code>
        /// <![CDATA[
        /// <configuration>
        ///    <configSections>
        ///       <section name="queueit.security" type="QueueIT.Security.Configuration.SettingsSection, QueueIT.Security"/>
        ///    </configSections>
        ///    <queueit.security
        ///       secretKey="a774b1e2-8da7-4d51-b1a9-7647147bb13bace77210-a488-4b6f-afc9-8ba94551a7d7">
        ///       <queues>
        ///          <queue name="myqueue" customerId="ticketania" eventId="advanced"/>
        ///       </queues>
        ///    </queueit.security>
        /// </configuration>
        /// ]]>
        /// </code>
        /// </example>
        public static IQueue CreateQueue(string queueName)
        {
            if (string.IsNullOrEmpty(queueName))
            {
                throw new ArgumentException("Queue Name cannot be null or empty", "queueName");
            }

            if (_settings == null)
            {
                throw new ConfigurationErrorsException(string.Format(
                                                           "Configuration section '{0}' is missing from configuration file",
                                                           SettingsSection.ConfigurationSectionName));
            }

            QueueSection queueConfiguration = _settings.Queues == null
                ? null
                :_settings.Queues.GetGeneric().FirstOrDefault(queueConfig => queueConfig.Name == queueName);

            if (queueConfiguration == null)
            {
                throw new ConfigurationErrorsException(string.Format(
                                                           "Configuration for Queue Name '{0}' in section '{1}' is missing from configuration file",
                                                           queueName,
                                                           SettingsSection.ConfigurationSectionName));
            }

            Queue queue = InstantiateQueue(
                queueConfiguration.CustomerId,
                queueConfiguration.EventId,
                string.IsNullOrEmpty(queueConfiguration.DomainAlias) ? null : queueConfiguration.DomainAlias,
                string.IsNullOrEmpty(queueConfiguration.LandingPage) ? null : queueConfiguration.LandingPage,
                queueConfiguration.UseSsl,
                queueConfiguration.IncludeTargetUrl,
                string.IsNullOrEmpty(queueConfiguration.Language) ? null : new CultureInfo(queueConfiguration.Language),
                string.IsNullOrEmpty(queueConfiguration.LayoutName) ? null : queueConfiguration.LayoutName);

            return(queue);
        }
        public bool Poll(out T item)
        {
            var q  = consumerQueue;
            var a  = q.array;
            var n  = a.Length;
            var ci = consumerIndex;

            for (;;)
            {
                if (ci == n)
                {
                    var q2 = Volatile.Read(ref q.next);
                    if (q2 == null)
                    {
                        item = default(T);
                        return(false);
                    }
                    //q.next = null;
                    consumerQueue = q2;
                    a             = q2.array;
                    ci            = 0;
                }
                if (Volatile.Read(ref a[ci].state) != 0)
                {
                    item          = a[ci].item;
                    a[ci].item    = default(T);
                    consumerIndex = ci + 1;
                    return(true);
                }

                if (ci == Math.Min(n, Volatile.Read(ref q.producerIndex)) && Volatile.Read(ref q.next) == null)
                {
                    item = default(T);
                    return(false);
                }
            }
        }
Пример #10
0
        public void Configure(QueueSenderConfig config)
        {
            var configSectionName = config.sectionName;

            _queueConfig = Helper.QueueConfig(configSectionName);
        }