Beispiel #1
0
            public AllSubscriptionFiltered(IPublisher bus,
                                           Position?startPosition,
                                           bool resolveLinks,
                                           IEventFilter eventFilter,
                                           ClaimsPrincipal user,
                                           bool requiresLeader,
                                           IReadIndex readIndex,
                                           uint?maxSearchWindow,
                                           uint checkpointIntervalMultiplier,
                                           Func <Position, Task> checkpointReached,
                                           CancellationToken cancellationToken)
            {
                if (bus == null)
                {
                    throw new ArgumentNullException(nameof(bus));
                }

                if (eventFilter == null)
                {
                    throw new ArgumentNullException(nameof(eventFilter));
                }

                if (readIndex == null)
                {
                    throw new ArgumentNullException(nameof(readIndex));
                }

                if (checkpointReached == null)
                {
                    throw new ArgumentNullException(nameof(checkpointReached));
                }

                if (checkpointIntervalMultiplier == 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(checkpointIntervalMultiplier));
                }

                _subscriptionId  = Guid.NewGuid();
                _bus             = bus;
                _resolveLinks    = resolveLinks;
                _eventFilter     = eventFilter;
                _user            = user;
                _requiresLeader  = requiresLeader;
                _readIndex       = readIndex;
                _maxSearchWindow = maxSearchWindow;
                _checkpointIntervalMultiplier = checkpointIntervalMultiplier;
                _checkpointReached            = checkpointReached;
                _cancellationToken            = cancellationToken;
                _subscriptionStarted          = new TaskCompletionSource <bool>();
                _subscriptionStarted.SetResult(true);

                _inner = startPosition == Position.End
                                        ? (IStreamSubscription) new LiveStreamSubscription(_subscriptionId, _bus,
                                                                                           Position.FromInt64(_readIndex.LastIndexedPosition, _readIndex.LastIndexedPosition),
                                                                                           _resolveLinks, _eventFilter, _user, _requiresLeader, _maxSearchWindow,
                                                                                           _checkpointIntervalMultiplier, checkpointReached, _cancellationToken)
                                        : new CatchupAllSubscription(_subscriptionId, bus, startPosition ?? Position.Start, resolveLinks,
                                                                     _eventFilter, user, _requiresLeader, readIndex, _maxSearchWindow, _checkpointIntervalMultiplier, checkpointReached,
                                                                     cancellationToken);
            }
Beispiel #2
0
                public CatchupAllSubscription(Guid subscriptionId,
                                              IPublisher bus,
                                              Position position,
                                              bool resolveLinks,
                                              IEventFilter eventFilter,
                                              ClaimsPrincipal user,
                                              bool requiresLeader,
                                              IReadIndex readIndex,
                                              uint?maxWindowSize,
                                              uint checkpointIntervalMultiplier,
                                              Func <Position, Task> checkpointReached,
                                              CancellationToken cancellationToken)
                {
                    if (bus == null)
                    {
                        throw new ArgumentNullException(nameof(bus));
                    }

                    if (eventFilter == null)
                    {
                        throw new ArgumentNullException(nameof(eventFilter));
                    }

                    if (readIndex == null)
                    {
                        throw new ArgumentNullException(nameof(readIndex));
                    }

                    if (checkpointReached == null)
                    {
                        throw new ArgumentNullException(nameof(checkpointReached));
                    }

                    if (checkpointIntervalMultiplier == 0)
                    {
                        throw new ArgumentOutOfRangeException(nameof(checkpointIntervalMultiplier));
                    }

                    _subscriptionId = subscriptionId;
                    _bus            = bus;
                    _nextPosition   = position == Position.End
                                                ? Position.FromInt64(readIndex.LastIndexedPosition, readIndex.LastIndexedPosition)
                                                : position;
                    _startPosition       = position == Position.End ? Position.Start : position;
                    _resolveLinks        = resolveLinks;
                    _eventFilter         = eventFilter;
                    _user                = user;
                    _requiresLeader      = requiresLeader;
                    _checkpointReached   = checkpointReached;
                    _maxWindowSize       = maxWindowSize ?? ReadBatchSize;
                    _checkpointInterval  = checkpointIntervalMultiplier * _maxWindowSize;
                    _disposedTokenSource = new CancellationTokenSource();
                    _buffer              = new ConcurrentQueueWrapper <(ResolvedEvent, Position?)>();

                    _tokenRegistration         = cancellationToken.Register(_disposedTokenSource.Dispose);
                    _currentPosition           = _startPosition;
                    _checkpointIntervalCounter = 0;
                    Log.Information("Catch-up subscription {subscriptionId} to $all:{eventFilter} running...",
                                    _subscriptionId, _eventFilter);
                }
Beispiel #3
0
            public AllSubscriptionFiltered(IPublisher bus,
                                           Position?startPosition,
                                           bool resolveLinks,
                                           IEventFilter eventFilter,
                                           ClaimsPrincipal user,
                                           bool requiresLeader,
                                           IReadIndex readIndex,
                                           uint?maxSearchWindow,
                                           uint checkpointIntervalMultiplier,
                                           ReadReq.Types.Options.Types.UUIDOption uuidOption,
                                           CancellationToken cancellationToken)
            {
                if (bus == null)
                {
                    throw new ArgumentNullException(nameof(bus));
                }

                if (eventFilter == null)
                {
                    throw new ArgumentNullException(nameof(eventFilter));
                }

                if (readIndex == null)
                {
                    throw new ArgumentNullException(nameof(readIndex));
                }

                if (checkpointIntervalMultiplier == 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(checkpointIntervalMultiplier));
                }

                _subscriptionId      = Guid.NewGuid();
                _bus                 = bus;
                _resolveLinks        = resolveLinks;
                _eventFilter         = eventFilter;
                _user                = user;
                _requiresLeader      = requiresLeader;
                _readIndex           = readIndex;
                _maxSearchWindow     = maxSearchWindow ?? ReadBatchSize;
                _uuidOption          = uuidOption;
                _cancellationToken   = cancellationToken;
                _subscriptionStarted = 0;
                _channel             = Channel.CreateBounded <ReadResp>(BoundedChannelOptions);
                _checkpointInterval  = checkpointIntervalMultiplier * _maxSearchWindow;
                _semaphore           = new SemaphoreSlim(1, 1);

                SubscriptionId = _subscriptionId.ToString();

                _currentPosition = null;

                Subscribe(startPosition);
            }
            public ReadAllForwardsFiltered(IPublisher bus,
                                           Position position,
                                           ulong maxCount,
                                           bool resolveLinks,
                                           IEventFilter eventFilter,
                                           ClaimsPrincipal user,
                                           bool requiresLeader,
                                           IReadIndex readIndex,
                                           uint?maxSearchWindow,
                                           DateTime deadline,
                                           ReadReq.Types.Options.Types.UUIDOption uuidOption,
                                           CancellationToken cancellationToken)
            {
                if (bus == null)
                {
                    throw new ArgumentNullException(nameof(bus));
                }

                if (eventFilter == null)
                {
                    throw new ArgumentNullException(nameof(eventFilter));
                }

                if (readIndex == null)
                {
                    throw new ArgumentNullException(nameof(readIndex));
                }

                _bus               = bus;
                _maxCount          = maxCount;
                _resolveLinks      = resolveLinks;
                _eventFilter       = eventFilter;
                _user              = user;
                _requiresLeader    = requiresLeader;
                _readIndex         = readIndex;
                _maxSearchWindow   = maxSearchWindow ?? ReadBatchSize;
                _deadline          = deadline;
                _uuidOption        = uuidOption;
                _cancellationToken = cancellationToken;
                _semaphore         = new SemaphoreSlim(1, 1);
                _channel           = Channel.CreateBounded <ReadResp>(BoundedChannelOptions);

                ReadPage(position);
            }
            public AllSubscriptionFiltered(IPublisher bus,
                                           Position?startPosition,
                                           bool resolveLinks,
                                           IEventFilter eventFilter,
                                           ClaimsPrincipal user,
                                           bool requiresLeader,
                                           IReadIndex readIndex,
                                           uint?maxSearchWindow,
                                           uint checkpointIntervalMultiplier,
                                           Func <Position, Task> checkpointReached,
                                           CancellationToken cancellationToken)
            {
                if (bus == null)
                {
                    throw new ArgumentNullException(nameof(bus));
                }

                if (eventFilter == null)
                {
                    throw new ArgumentNullException(nameof(eventFilter));
                }

                if (readIndex == null)
                {
                    throw new ArgumentNullException(nameof(readIndex));
                }

                if (checkpointReached == null)
                {
                    throw new ArgumentNullException(nameof(checkpointReached));
                }

                if (checkpointIntervalMultiplier == 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(checkpointIntervalMultiplier));
                }

                _subscriptionId      = Guid.NewGuid();
                _bus                 = bus;
                _resolveLinks        = resolveLinks;
                _eventFilter         = eventFilter;
                _user                = user;
                _requiresLeader      = requiresLeader;
                _maxSearchWindow     = maxSearchWindow ?? ReadBatchSize;
                _checkpointReached   = checkpointReached;
                _cancellationToken   = cancellationToken;
                _subscriptionStarted = new TaskCompletionSource <bool>();
                _channel             = Channel.CreateBounded <(ResolvedEvent?, Position?)>(BoundedChannelOptions);
                _checkpointInterval  = checkpointIntervalMultiplier * _maxSearchWindow;
                _semaphore           = new SemaphoreSlim(1, 1);
                _lastCheckpoint      = Position.Start;

                SubscriptionId = _subscriptionId.ToString();

                var lastIndexedPosition    = readIndex.LastIndexedPosition;
                var startPositionExclusive = startPosition == Position.End
                                        ? Position.FromInt64(lastIndexedPosition, lastIndexedPosition)
                                        : startPosition ?? Position.Start;

                _startPositionExclusive = new TFPos((long)startPositionExclusive.CommitPosition,
                                                    (long)startPositionExclusive.PreparePosition);

                Subscribe(startPositionExclusive, startPosition != Position.End);
            }