• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Disruptor.Sequence类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Disruptor.Sequence的典型用法代码示例。如果您正苦于以下问题:C# Sequence类的具体用法?C# Sequence怎么用?C# Sequence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Sequence类属于Disruptor命名空间,在下文中一共展示了Sequence类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SerialisePublishing

        ///<summary>
        /// Serialise publishers in sequence and set cursor to latest available sequence.
        ///</summary>
        ///<param name="sequence">sequence to be applied</param>
        ///<param name="cursor">cursor to serialise against.</param>
        ///<param name="batchSize">batchSize of the sequence.</param>
        public override void SerialisePublishing(long sequence, Sequence cursor, long batchSize)
        {
            var spinWait = default(SpinWait);
            while (sequence - cursor.Value > _pendingPublication.Length)
            {
                spinWait.SpinOnce();
            }

            long expectedSequence = sequence - batchSize;
            for (long pendingSequence = expectedSequence + 1; pendingSequence <= sequence; pendingSequence++)
            {
                _pendingPublication.WriteCompilerOnlyFence((int)pendingSequence & _pendingMask, pendingSequence);                
            }
            _pendingPublication.WriteFullFence((int)sequence & _pendingMask, sequence);

            long cursorSequence = cursor.Value;
            if (cursorSequence >= sequence)
            {
                return;
            }
            expectedSequence = Math.Max(expectedSequence, cursorSequence);
            long nextSequence = expectedSequence + 1;
            while (cursor.CompareAndSet(expectedSequence, nextSequence))
            {
                expectedSequence = nextSequence;
                nextSequence++;
                if (_pendingPublication.ReadFullFence((int)nextSequence & _pendingMask) != nextSequence)
                {
                    break;
                }
            }
        }
开发者ID:Xamarui,项目名称:Disruptor-net,代码行数:38,代码来源:MultiThreadedClaimStrategy.cs


示例2: WaitFor

        /// <summary>
        /// <see cref="IWaitStrategy.WaitFor"/>
        /// </summary>
        public long WaitFor(long sequence, Sequence cursor, ISequence dependentSequence, ISequenceBarrier barrier)
        {
            long startTime = 0;
            int counter = _spinTries;

            do
            {
                long availableSequence;
                if ((availableSequence = dependentSequence.Value) >= sequence)
                    return availableSequence;

                if (0 == --counter)
                {
                    if (0 == startTime)
                    {
                        startTime = GetSystemTimeTicks();
                    }
                    else
                    {
                        var timeDelta = GetSystemTimeTicks() - startTime;
                        if (timeDelta > _yieldTimeoutTicks)
                        {
                            return _fallbackStrategy.WaitFor(sequence, cursor, dependentSequence, barrier);
                        }

                        if (timeDelta > _spinTimeoutTicks)
                        {
                            Thread.Yield();
                        }
                    }
                    counter = _spinTries;
                }
            }
            while (true);
        }
开发者ID:disruptor-net,项目名称:Disruptor-net,代码行数:38,代码来源:PhasedBackoffWaitStrategy.cs


示例3: WaitFor

        /// <summary>
        /// <see cref="IWaitStrategy.WaitFor"/>
        /// </summary>
        public long WaitFor(long sequence, Sequence cursor, ISequence dependentSequence, ISequenceBarrier barrier)
        {
            var timeSpan = _timeout;
            if (cursor.Value < sequence)
            {
                lock (_gate)
                {
                    while (cursor.Value < sequence)
                    {
                        barrier.CheckAlert();
                        if (!Monitor.Wait(_gate, timeSpan))
                        {
                            throw TimeoutException.Instance;
                        }
                    }
                }
            }

            long availableSequence;
            while ((availableSequence = dependentSequence.Value) < sequence)
            {
                barrier.CheckAlert();
            }

            return availableSequence;
        }
开发者ID:disruptor-net,项目名称:Disruptor-net,代码行数:29,代码来源:TimeoutBlockingWaitStrategy.cs


示例4: WaitFor

        /// <summary>
        /// <see cref="IWaitStrategy.WaitFor"/>.
        /// </summary>
        public long WaitFor(long sequence, Sequence cursor, ISequence dependentSequence, ISequenceBarrier barrier)
        {
            var milliseconds = _timeoutInMilliseconds;

            long availableSequence;
            if (cursor.Value < sequence)
            {
                lock (_lock)
                {
                    while (cursor.Value < sequence)
                    {
                        Interlocked.Exchange(ref _signalNeeded, 1);

                        barrier.CheckAlert();

                         if (!Monitor.Wait(_lock, milliseconds))
                        {
                            throw TimeoutException.Instance;
                        }
                    }
                }
            }

            while ((availableSequence = dependentSequence.Value) < sequence)
            {
                barrier.CheckAlert();
            }

            return availableSequence;
        }
开发者ID:disruptor-net,项目名称:Disruptor-net,代码行数:33,代码来源:LiteTimeoutBlockingWaitStrategy.cs


示例5: WaitFor

        /// <summary>
        /// Wait for the given sequence to be available with a timeout specified.
        /// </summary>
        /// <param name="sequence">sequence to be waited on.</param>
        /// <param name="cursor">cursor on which to wait.</param>
        /// <param name="dependents">dependents further back the chain that must advance first</param>
        /// <param name="barrier">barrier the processor is waiting on.</param>
        /// <param name="timeout">timeout value to abort after.</param>
        /// <returns>the sequence that is available which may be greater than the requested sequence.</returns>
        /// <exception cref="AlertException">AlertException if the status of the Disruptor has changed.</exception>
        public long WaitFor(long sequence, Sequence cursor, Sequence[] dependents, ISequenceBarrier barrier,
                        TimeSpan timeout)
        {
            long availableSequence;
            if ((availableSequence = cursor.Value) < sequence)
            {
                Monitor.Enter(_gate);
                try
                {
                    while ((availableSequence = cursor.Value) < sequence)
                    {
                        barrier.CheckAlert();

                        if (!Monitor.Wait(_gate, timeout))
                        {
                            break;
                        }
                    }
                }
                finally
                {
                    Monitor.Exit(_gate);
                }
            }

            if (dependents.Length != 0)
            {
                while ((availableSequence = Util.GetMinimumSequence(dependents)) < sequence)
                {
                    barrier.CheckAlert();
                }
            }

            return availableSequence;
        }
开发者ID:quantedge,项目名称:Disruptor-net,代码行数:45,代码来源:BlockingWaitStrategy.cs


示例6: WaitFor

        /// <summary>
        /// Wait for the given sequence to be available
        /// </summary>
        /// <param name="sequence">sequence to be waited on.</param>
        /// <param name="cursor">Ring buffer cursor on which to wait.</param>
        /// <param name="dependents">dependents further back the chain that must advance first</param>
        /// <param name="barrier">barrier the <see cref="IEventProcessor"/> is waiting on.</param>
        /// <returns>the sequence that is available which may be greater than the requested sequence.</returns>
        public long WaitFor(long sequence, Sequence cursor, Sequence[] dependents, ISequenceBarrier barrier)
        {
            long availableSequence;
            var spinWait = default(SpinWait);

            if (dependents.Length == 0)
            {
                while ((availableSequence = cursor.Value) < sequence) // volatile read
                {
                    barrier.CheckAlert();
                    spinWait.SpinOnce();
                    if (spinWait.Count > 5000)
                        break;
                }
            }
            else
            {
                while ((availableSequence = Util.GetMinimumSequence(dependents)) < sequence)
                {
                    barrier.CheckAlert();
                    spinWait.SpinOnce();
                    if (spinWait.Count > 5000)
                        break;
                }
            }

            return availableSequence;
        }
开发者ID:gaoshilin,项目名称:Disruptor.Net,代码行数:36,代码来源:SleepingWaitStrategy.cs


示例7: WaitFor

        /// <summary>
        /// Wait for the given sequence to be available with a timeout specified.
        /// </summary>
        /// <param name="sequence">sequence to be waited on.</param>
        /// <param name="cursor">cursor on which to wait.</param>
        /// <param name="dependents">dependents further back the chain that must advance first</param>
        /// <param name="barrier">barrier the processor is waiting on.</param>
        /// <param name="timeout">timeout value to abort after.</param>
        /// <returns>the sequence that is available which may be greater than the requested sequence.</returns>
        /// <exception cref="AlertException">AlertException if the status of the Disruptor has changed.</exception>
        public long WaitFor(long sequence, Sequence cursor, Sequence[] dependents, ISequenceBarrier barrier, TimeSpan timeout)
        {
            long availableSequence;
            var spinWait = default(SpinWait);
            var sw = Stopwatch.StartNew();

            if (dependents.Length == 0)
            {
                while ((availableSequence = cursor.Value) < sequence) // volatile read
                {
                    barrier.CheckAlert();
                    spinWait.SpinOnce();

                    if (sw.Elapsed > timeout)
                    {
                        break;
                    }
                }
            }
            else
            {
                while ((availableSequence = Util.GetMinimumSequence(dependents)) < sequence)
                {
                    barrier.CheckAlert();
                    spinWait.SpinOnce();

                    if (sw.Elapsed > timeout)
                    {
                        break;
                    }
                }
            }

            return availableSequence;
        }
开发者ID:Xamarui,项目名称:Disruptor-net,代码行数:45,代码来源:SleepingWaitStrategy.cs


示例8: Remove

        /// <summary>
        /// Remove the first occurrence of the <see cref="Sequence"/> from this aggregate.
        /// </summary>
        /// <param name="sequence">sequence to be removed from this aggregate.</param>
        /// <returns>true if the sequence was removed otherwise false.</returns>
        public bool Remove(Sequence sequence)
        {
            var found = false;
            Sequence[] oldSequences;
            Sequence[] newSequences;
            do
            {
                oldSequences = _sequencesRef.ReadFullFence();
                int oldSize = oldSequences.Length;
                newSequences = new Sequence[oldSize - 1];

                int pos = 0;
                for (int i = 0; i < oldSize; i++)
                {
                    var testSequence = oldSequences[i];
                    if (sequence == testSequence && !found)
                    {
                        found = true;
                    }
                    else
                    {
                        newSequences[pos++] = testSequence;
                    }
                }

                if (!found)
                {
                    break;
                }
            }
            while (!_sequencesRef.AtomicCompareExchange(newSequences, oldSequences));

            return found;
        }
开发者ID:Xamarui,项目名称:Disruptor-net,代码行数:39,代码来源:SequenceGroup.cs


示例9: WaitFor

        /// <summary>
        /// Wait for the given sequence to be available with a timeout specified.
        /// </summary>
        /// <param name="sequence">sequence to be waited on.</param>
        /// <param name="cursor">cursor on which to wait.</param>
        /// <param name="dependents">dependents further back the chain that must advance first</param>
        /// <param name="barrier">barrier the processor is waiting on.</param>
        /// <param name="timeout">timeout value to abort after.</param>
        /// <returns>the sequence that is available which may be greater than the requested sequence.</returns>
        /// <exception cref="AlertException">AlertException if the status of the Disruptor has changed.</exception>
        public long WaitFor(long sequence, Sequence cursor, Sequence[] dependents, ISequenceBarrier barrier, TimeSpan timeout)
        {
            long availableSequence;
            var counter = 0;
            var sw = Stopwatch.StartNew();

            if (dependents.Length == 0)
            {
                while ((availableSequence = cursor.Value) < sequence) // volatile read
                {
                    counter = ApplyWaitMethod(barrier, counter);
                    if (sw.Elapsed > timeout)
                    {
                        break;
                    }
                }
            }
            else
            {
                while ((availableSequence = Util.GetMinimumSequence(dependents)) < sequence)
                {
                    counter = ApplyWaitMethod(barrier, counter);
                    if (sw.Elapsed > timeout)
                    {
                        break;
                    }
                }
            }

            return availableSequence;
        }
开发者ID:gaoshilin,项目名称:Disruptor.Net,代码行数:41,代码来源:BetterYieldingWaitStrategy.cs


示例10: ShouldWaitForWorkCompleteWhereCompleteWorkThresholdIsAhead

        public void ShouldWaitForWorkCompleteWhereCompleteWorkThresholdIsAhead()
        {
            const int expectedNumberEvents = 10;
            const int expectedWorkSequence = 9;
            FillRingBuffer(expectedNumberEvents);

            var sequence1 = new Sequence(expectedNumberEvents);
            var sequence2 = new Sequence(expectedWorkSequence);
            var sequence3 = new Sequence(expectedNumberEvents);

            _eventProcessorMock1.SetupGet(c => c.Sequence).Returns(sequence1);
            _eventProcessorMock2.SetupGet(c => c.Sequence).Returns(sequence2);
            _eventProcessorMock3.SetupGet(c => c.Sequence).Returns(sequence3);

            var dependencyBarrier = _ringBuffer.NewBarrier(_eventProcessorMock1.Object.Sequence,
                                                           _eventProcessorMock2.Object.Sequence,
                                                           _eventProcessorMock3.Object.Sequence);

            var completedWorkSequence = dependencyBarrier.WaitFor(expectedWorkSequence);
            Assert.IsTrue(completedWorkSequence >= expectedWorkSequence);

            _eventProcessorMock1.Verify();
            _eventProcessorMock2.Verify();
            _eventProcessorMock3.Verify();
        }
开发者ID:bingyang001,项目名称:disruptor-net-3.3.0-alpha,代码行数:25,代码来源:SequenceBarrierTest.cs


示例11: ShouldAddOneSequenceToGroup

        public void ShouldAddOneSequenceToGroup()
        {
            var sequence = new Sequence(7L);
            var sequenceGroup = new SequenceGroup();
            sequenceGroup.Add(sequence);

            Assert.AreEqual(sequence.Value, sequenceGroup.Value);
        }
开发者ID:bingyang001,项目名称:disruptor-net-3.3.0-alpha,代码行数:8,代码来源:SequenceGroupTest.cs


示例12: IncrementAndGet

        /// <summary>
        /// Claim the next sequence in the <see cref="Sequencer"/>
        /// The caller should be held up until the claimed sequence is available by tracking the dependentSequences.
        /// </summary>
        /// <param name="dependentSequences">dependentSequences to be checked for range.</param>
        /// <returns>the index to be used for the publishing.</returns>
        public long IncrementAndGet(Sequence[] dependentSequences)
        {
            long nextSequence = _claimSequence.Value + 1L;
            _claimSequence.Value = nextSequence;
            WaitForFreeSlotAt(nextSequence, dependentSequences);

            return nextSequence;
        }
开发者ID:TimGebhardt,项目名称:Disruptor-net,代码行数:14,代码来源:SingleThreadedClaimStrategy.cs


示例13: ProcessingSequenceBarrier

 public ProcessingSequenceBarrier(IWaitStrategy waitStrategy, 
                        Sequence cursorSequence, 
                        Sequence[] dependentSequences)
 {
     _waitStrategy = waitStrategy;
     _cursorSequence = cursorSequence;
     _dependentSequences = dependentSequences;
 }
开发者ID:Xamarui,项目名称:Disruptor-net,代码行数:8,代码来源:ProcessingSequenceBarrier.cs


示例14: IncrementAndGet

        /// <summary>
        /// Claim the next sequence in the <see cref="Sequencer"/>
        /// The caller should be held up until the claimed sequence is available by tracking the dependentSequences.
        /// </summary>
        /// <param name="dependentSequences">dependentSequences to be checked for range.</param>
        /// <returns>the index to be used for the publishing.</returns>
        public long IncrementAndGet(Sequence[] dependentSequences)
        {
            long nextSequence = _claimSequence.ReadUnfenced() + 1L;
            _claimSequence.WriteUnfenced(nextSequence);
            WaitForFreeSlotAt(nextSequence, dependentSequences);

            return nextSequence;
        }
开发者ID:JoonyLi,项目名称:Disruptor-net,代码行数:14,代码来源:SingleThreadedClaimStrategy.cs


示例15: CheckAndIncrement

        public long CheckAndIncrement(int availableCapacity, int delta, Sequence[] dependentSequences)
        {
            if (!HasAvailableCapacity(availableCapacity, dependentSequences))
            {
                throw InsufficientCapacityException.Instance;
            }

            return IncrementAndGet(delta, dependentSequences);
        }
开发者ID:quantedge,项目名称:Disruptor-net,代码行数:9,代码来源:SingleThreadedClaimStrategy.cs


示例16: SerialisePublishing

        ///<summary>
        /// Serialise publishers in sequence and set cursor to latest available sequence.
        ///</summary>
        ///<param name="sequence">sequence to be applied</param>
        ///<param name="cursor">cursor to serialise against.</param>
        ///<param name="batchSize">batchSize of the sequence.</param>
        public override void SerialisePublishing(long sequence, Sequence cursor, long batchSize)
        {
            long expectedSequence = sequence - batchSize;
            while (expectedSequence != cursor.Value)
            {
                // busy spin
            }

            cursor.LazySet(sequence);
        }
开发者ID:gaoshilin,项目名称:Disruptor.Net,代码行数:16,代码来源:MultiThreadedLowContentionClaimStrategy.cs


示例17: ShouldReportTheMinimumSequenceForGroupOfTwo

        public void ShouldReportTheMinimumSequenceForGroupOfTwo()
        {
            var sequenceThree = new Sequence(3L);
            var sequenceSeven = new Sequence(7L);
            var sequenceGroup = new SequenceGroup();
            sequenceGroup.Add(sequenceSeven);
            sequenceGroup.Add(sequenceThree);

            Assert.AreEqual(sequenceThree.Value, sequenceGroup.Value);
        }
开发者ID:bingyang001,项目名称:disruptor-net-3.3.0-alpha,代码行数:10,代码来源:SequenceGroupTest.cs


示例18: AssertWaitForWithDelayOf

        public static void AssertWaitForWithDelayOf(TimeSpan sleepTimeMillis, IWaitStrategy waitStrategy)
        {
            var sequenceUpdater = new SequenceUpdater(sleepTimeMillis, waitStrategy);
            Task.Factory.StartNew(() => sequenceUpdater.run(), CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
            sequenceUpdater.WaitForStartup();
            var cursor = new Sequence(0);
            var sequence = waitStrategy.WaitFor(0, cursor, sequenceUpdater.sequence, new DummySequenceBarrier());
            Assert.AreEqual(sequence, 0L);

        }
开发者ID:bingyang001,项目名称:disruptor-net-3.3.0-alpha,代码行数:10,代码来源:WaitStrategyTestUtil.cs


示例19: IncrementAndGet

        /// <summary>
        /// Claim the next sequence in the <see cref="Sequencer"/>
        /// The caller should be held up until the claimed sequence is available by tracking the dependentSequences.
        /// </summary>
        /// <param name="dependentSequences">dependentSequences to be checked for range.</param>
        /// <returns>the index to be used for the publishing.</returns>
        public long IncrementAndGet(Sequence[] dependentSequences)
        {
            MutableLong minGatingSequence = _minGatingSequenceThreadLocal.Value;
            WaitForCapacity(dependentSequences, minGatingSequence);

            long nextSequence = _claimSequence.IncrementAndGet();
            WaitForFreeSlotAt(nextSequence, dependentSequences, minGatingSequence);

            return nextSequence;
        }
开发者ID:Xamarui,项目名称:Disruptor-net,代码行数:16,代码来源:AbstractMultiThreadedClaimStrategy.cs


示例20: ShouldReturnMinimumOf2Sequences

        public void ShouldReturnMinimumOf2Sequences()
        {
            var sequence1 = new Sequence(34);
            var sequnece2 = new Sequence(47);
            var group = new FixedSequenceGroup(new Sequence[] { sequence1, sequnece2 });

            Assert.AreEqual(group.Value, 34);
            sequence1.Value = 35;
            Assert.AreEqual(group.Value, 35);
            sequence1.Value = 48;
            Assert.AreEqual(group.Value, 47);
        }
开发者ID:bingyang001,项目名称:disruptor-net-3.3.0-alpha,代码行数:12,代码来源:FixedSequenceGroupTest.cs



注:本文中的Disruptor.Sequence类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# EF.CokeDataContext类代码示例发布时间:2022-05-24
下一篇:
C# Math.ShadeRec类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap