コード例 #1
0
        public void A_separate_thread_trying_read_a_write_locked_object_should_timeout()
        {
            Thread lockThread = new Thread(() =>
            {
                _value.WriteLock(x =>
                {
                    Thread.Sleep(3.Seconds());
                    return(x);
                });
            });

            lockThread.Start();

            Thread.Sleep(500.Milliseconds());

            string value = string.Empty;

            bool locked = _value.ReadLock(1.Seconds(), x => { value = x; });

            lockThread.Join();

            Assert.IsFalse(locked);
            //Assert.That(locked, Is.False);

            Assert.AreEqual(string.Empty, value);
            //Assert.That(value, Is.EqualTo(string.Empty));
        }
コード例 #2
0
        public void IncrementRetryCount(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return;
            }

            _messages.WriteLock(x => { x[id] = x.ContainsKey(id) ? x[id] + 1 : 1; });
        }
コード例 #3
0
 public void Viewed(T item)
 {
     _messages.UpgradeableReadLock(x =>
     {
         if (!x.Contains(item))
         {
             _messages.WriteLock(y => y.Add(item));
         }
     });
 }
コード例 #4
0
        public UnregisterAction Register(T item)
        {
            _items.WriteLock(x => x.Insert(0, item));

            return(() =>
            {
                bool removed = false;

                _items.WriteLock(x => { removed = x.Remove(item); });

                return removed;
            });
        }
コード例 #5
0
        public void RegisterTransport(Type transportType)
        {
            _transportTypes.WriteLock(x =>
            {
                if (x.Contains(transportType))
                {
                    return;
                }

                x.Add(transportType);
            });
        }
コード例 #6
0
        /// <summary>
        /// Connects a message sink to the router
        /// </summary>
        /// <param name="sink">The sink to be connected</param>
        /// <returns>A function to disconnect the sink from the router</returns>
        public UnsubscribeAction Connect(IPipelineSink <TMessage> sink)
        {
            _sinks.WriteLock(sinks => sinks.Add(sink));

            return(() => _sinks.WriteLock(sinks => sinks.Remove(sink)));
        }
コード例 #7
0
 public void IncrementRetryCount(string id)
 {
     _messages.WriteLock(x => { x[id] = x.ContainsKey(id) ? x[id] + 1 : 1; });
 }
コード例 #8
0
        public UnsubscribeAction Connect(IPipelineSink <Batch <TMessage, TBatchId> > sink)
        {
            _consumerSinks.WriteLock(sinks => sinks.Add(sink));

            return(() => _consumerSinks.WriteLock(sinks => sinks.Remove(sink)));
        }
コード例 #9
0
 public void Consume(TMessage message)
 {
     _messages.WriteLock(x => x.Enqueue(message));
     _messageWaiting.Release();
 }
コード例 #10
0
 public override void Dispose()
 {
     _storage.WriteLock(x => x.Clear());
     _storage.Dispose();
 }