public InMemoryStreamStore(GetUtcNow getUtcNow = null, string logName = null)
     : base(TimeSpan.FromMinutes(1), 10000, getUtcNow, logName ?? nameof(InMemoryStreamStore))
 {
     _getUtcNow = getUtcNow ?? SystemClock.GetUtcNow;
     _allStream.AddFirst(new InMemoryStreamMessage(
                             "<in-memory-root-message>",
                             Guid.NewGuid(),
                             -1,
                             -1,
                             _getUtcNow(),
                             null,
                             null,
                             null));
     _onStreamAppended = () =>
     {
         if (_signallingToSubscribers.CompareExchange(true, false) == false)
         {
             Task.Run(() =>
             {
                 _subscriptions.OnNext(Unit.Default);
                 _signallingToSubscribers.Set(false);
             });
         }
     };
 }
 private void Fetch()
 {
     if (_isFetching.CompareExchange(true, false))
     {
         return;
     }
     Task.Run(async() =>
     {
         try
         {
             bool isEnd = false;
             while (_shouldFetch.CompareExchange(false, true) || !isEnd)
             {
                 isEnd = await DoFetch();
             }
         }
         catch (Exception ex)
         {
             // Drop subscription
         }
         finally
         {
             _isFetching.Set(false);
         }
     }, IsDisposed);
 }
Exemplo n.º 3
0
 private void Push()
 {
     if (_isPushing.CompareExchange(true, false))
     {
         return;
     }
     Task.Run(async() =>
     {
         ICommit commit;
         while (_commits.TryDequeue(out commit))
         {
             try
             {
                 await _onCommit(commit);
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.ToString());
             }
             if (_commits.Count < _threshold)
             {
                 _onThreashold();
             }
         }
         _isPushing.Set(false);
     });
 }
Exemplo n.º 4
0
        public void CompareExchange_false_was_true_compare_with_true()
        {
            var interlockedBoolean = new InterlockedBoolean(true);
            var oldValue           = interlockedBoolean.CompareExchange(false, true);

            Assert.IsFalse(interlockedBoolean.Value);
            Assert.IsTrue(oldValue);
        }
        public void CompareExchange_false_was_false_compare_with_true()
        {
            var interlockedBoolean = new InterlockedBoolean();
            var oldValue = interlockedBoolean.CompareExchange(false, true);

            Assert.IsFalse(interlockedBoolean.Value);
            Assert.IsFalse(oldValue);
        }
        public void CompareExchange_true_was_true_compare_with_false()
        {
            var interlockedBoolean = new InterlockedBoolean(true);
            var oldValue = interlockedBoolean.CompareExchange(true, false);

            Assert.IsTrue(interlockedBoolean.Value);
            Assert.IsTrue(oldValue);
        }
Exemplo n.º 7
0
 protected void Fetch()
 {
     if (_isFetching.CompareExchange(true, false))
     {
         return;
     }
     Task.Run(async() =>
     {
         bool isEnd = false;
         while (!isEnd || _shouldFetch.CompareExchange(false, true))
         {
             isEnd = await DoFetch();
         }
         _isFetching.Set(false);
     }, IsDisposed);
 }
Exemplo n.º 8
0
 private void NotifySubscriptionDropped(SubscriptionDroppedReason reason, Exception exception = null)
 {
     if (_notificationRaised.CompareExchange(true, false))
     {
         return;
     }
     try
     {
         s_logger.InfoException($"All stream subscription dropped {Name}. Reason: {reason}", exception);
         _subscriptionDropped.Invoke(this, reason, exception);
     }
     catch (Exception ex)
     {
         s_logger.ErrorException(
             $"Error notifying subscriber that subscription has been dropped ({Name}).",
             ex);
     }
 }
Exemplo n.º 9
0
 private void Push()
 {
     if (_isPushing.CompareExchange(true, false))
     {
         return;
     }
     Task.Run(async() =>
     {
         ResolvedEvent resolvedEvent;
         while (!_token.IsCancellationRequested && _events.TryDequeue(out resolvedEvent))
         {
             try
             {
                 await _onResolvedEvent(resolvedEvent, _token);
             }
             catch (Exception ex)
             {
                 s_logger.ErrorException(ex.Message, ex);
             }
         }
         _isPushing.Set(false);
     }, _token);
 }
Exemplo n.º 10
0
 public static bool EnsureCalledOnce(this InterlockedBoolean interlockedBoolean)
 {
     return(interlockedBoolean.CompareExchange(true, false));
 }