Exemple #1
0
        public long WaitFor(long sequence)
        {
            CheckAlert();

            var availableSequence = _waitStrategy.WaitFor(sequence, _cursorSequence, _dependentSequence, this);

            return(availableSequence < sequence ? availableSequence : _sequencer.GetHighestPublishedSequence(sequence, availableSequence));
        }
 public long WaitFor(long sequence)
 {
     while (_dependent.Value < sequence)
     {
         _waitStrategy.WaitFor(sequence, _cursor, _dependent, this);
     }
     return(_sequencer.GetAvailableSequence(sequence, _dependent.Value));
 }
        public static void AssertWaitForWithDelayOf(long sleepTimeMillis, IWaitStrategy waitStrategy)
        {
            var sequenceUpdater = new SequenceUpdater(sleepTimeMillis, waitStrategy);
            Task.Factory.StartNew(sequenceUpdater.Run);
            sequenceUpdater.WaitForStartup();
            var cursor = new Sequence(0);
            var sequence = waitStrategy.WaitFor(0, cursor, sequenceUpdater.Sequence, new DummySequenceBarrier());

            Assert.That(sequence, Is.EqualTo(0L));
        }
        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);

        }
        public static void assertWaitForWithDelayOf(int 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);
        }
Exemple #6
0
        public static void AssertWaitForWithDelayOf(int sleepTimeMillis, IWaitStrategy waitStrategy)
        {
            var sequenceUpdater = new SequenceUpdater(sleepTimeMillis, waitStrategy);

            Task.Run(() => sequenceUpdater.Run());
            sequenceUpdater.WaitForStartup();
            var cursor   = new Sequence(0);
            var sequence = waitStrategy.WaitFor(0, cursor, sequenceUpdater.sequence, new DummySequenceBarrier());

            Assert.Equal(0L, sequence);
        }
        public static void AssertWaitForWithDelayOf(long sleepTimeMillis, IWaitStrategy waitStrategy)
        {
            var sequenceUpdater = new SequenceUpdater(sleepTimeMillis, waitStrategy);

            Task.Factory.StartNew(sequenceUpdater.Run);
            sequenceUpdater.WaitForStartup();
            var cursor   = new Sequence(0);
            var sequence = waitStrategy.WaitFor(0, cursor, sequenceUpdater.Sequence, new DummySequenceBarrier());

            Assert.That(sequence, Is.EqualTo(0L));
        }
        public void ShouldTimeoutWaitFor()
        {
            var startUtc = DateTime.UtcNow;

            Assert.Throws <TimeoutException>(() => _strategy.WaitFor(6, _cursor, _dependent, _barrier));

            var endUtc      = DateTime.UtcNow;
            var timeWaiting = endUtc.Subtract(startUtc).Ticks;

            Assert.True(timeWaiting >= TimeoutMilliseconds);
        }
        public long WaitFor(long sequence)
        {
            CheckAlert();

            var availableSequence = waitStrategy.WaitFor(sequence, cursorSequence, dependentSequence, this);

            if (availableSequence < sequence)
            {
                return(availableSequence);
            }

            return(sequencer.GetHighestPublishedSequence(sequence, availableSequence));
        }
Exemple #10
0
        protected long WaitForAvailable(long waitingPosition)
        {
            long lastBarrierPosition = long.MaxValue;

            foreach (var dependency in _dependencies)
            {
                IWaitStrategy waitStrategy = dependency.WaitStrategy;

                long position = waitStrategy.WaitFor(waitingPosition + 1, dependency.Cursor);
                if (position < lastBarrierPosition)
                {
                    lastBarrierPosition = position;
                }
            }

            return(lastBarrierPosition - 1);
        }
        public long WaitFor(
            long sequence,
            ISequence cursor,
            ISequence dependentSequence,
            ISequenceBarrier barrier)
        {
            long startTime = 0;
            var  counter   = SpinTries;

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

                if (0 == --counter)
                {
                    if (0 == startTime)
                    {
                        startTime = DateTime.Now.Ticks;
                    }
                    else
                    {
                        var timeDelta = DateTime.Now.Ticks - startTime;
                        if (timeDelta > _yieldTimeoutTicks)
                        {
                            return(_fallbackStrategy.WaitFor(sequence, cursor, dependentSequence, barrier));
                        }
                        else if (timeDelta > _spinTimeoutTicks)
                        {
                            Thread.Yield();
                        }
                    }

                    counter = SpinTries;
                }
            } while (true);
        }
Exemple #12
0
        /// <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)
                        {
#if NETSTANDARD2_0
                            Thread.Yield();
#else
                            Thread.Sleep(0);
#endif
                        }
                    }
                    counter = _spinTries;
                }
            }while (true);
        }
    public SequenceWaitResult WaitFor(long sequence, DependentSequenceGroup dependentSequences, CancellationToken cancellationToken)
    {
        long startTime = 0;
        int  counter   = _spinTries;

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

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

                    if (timeDelta > _spinTimeoutTicks)
                    {
                        Thread.Yield();
                    }
                }

                counter = _spinTries;
            }
        }while (true);
    }
Exemple #14
0
        public long WaitFor(long sequence)
        {
            CheckAlert();

            return(_waitStrategy.WaitFor(sequence, _cursorSequence, _dependentSequences, this));
        }
Exemple #15
0
 private SequenceWaitResult InvokeWaitStrategy(long sequence)
 {
     return(_waitStrategy.WaitFor(sequence, _dependentSequences, _cancellationTokenSource.Token));
 }
Exemple #16
0
 public WaitForResult WaitFor(long sequence)
 {
     return(_waitStrategy.WaitFor(_consumers, _ringBuffer, this, sequence));
 }
 public void Should_Timeout_WaitFor()
 {
     Assert.Throws <TimeoutException>(() => _strategy.WaitFor(6, _cursor, _dependent, _barrier));
 }