Exemplo n.º 1
0
        async Task <ScopedStreamProcessor> CreateUnpartitionedScopedStreamProcessor(
            IStreamProcessorId streamProcessorId,
            IEventProcessor eventProcessor,
            ICanFetchEventsFromStream eventsFromStreamsFetcher,
            CancellationToken cancellationToken)
        {
            var tryGetStreamProcessorState = await _streamProcessorStates.TryGetFor(streamProcessorId, cancellationToken).ConfigureAwait(false);

            if (!tryGetStreamProcessorState.Success)
            {
                tryGetStreamProcessorState = StreamProcessorState.New;
                await _streamProcessorStates.Persist(streamProcessorId, tryGetStreamProcessorState.Result, cancellationToken).ConfigureAwait(false);
            }

            if (tryGetStreamProcessorState.Result.Partitioned)
            {
                throw new ExpectedUnpartitionedStreamProcessorState(streamProcessorId);
            }
            return(new ScopedStreamProcessor(
                       _tenant,
                       streamProcessorId,
                       tryGetStreamProcessorState.Result as StreamProcessorState,
                       eventProcessor,
                       _streamProcessorStates,
                       eventsFromStreamsFetcher,
                       _eventsFetcherPolicy,
                       _loggerManager.CreateLogger <ScopedStreamProcessor>()));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScopedStreamProcessor"/> class.
 /// </summary>
 /// <param name="tenantId">The <see cref="TenantId"/>.</param>
 /// <param name="streamProcessorId">The <see cref="IStreamProcessorId" />.</param>
 /// <param name="initialState">The <see cref="StreamProcessorState" />.</param>
 /// <param name="processor">An <see cref="IEventProcessor" /> to process the event.</param>
 /// <param name="streamProcessorStates">The <see cref="IResilientStreamProcessorStateRepository" />.</param>
 /// <param name="eventsFromStreamsFetcher">The<see cref="ICanFetchEventsFromStream" />.</param>
 /// <param name="eventsFetcherPolicy">The <see cref="IAsyncPolicyFor{T}" /> <see cref="ICanFetchEventsFromStream" />.</param>
 /// <param name="logger">An <see cref="ILogger" /> to log messages.</param>
 public ScopedStreamProcessor(
     TenantId tenantId,
     IStreamProcessorId streamProcessorId,
     StreamProcessorState initialState,
     IEventProcessor processor,
     IResilientStreamProcessorStateRepository streamProcessorStates,
     ICanFetchEventsFromStream eventsFromStreamsFetcher,
     IAsyncPolicyFor <ICanFetchEventsFromStream> eventsFetcherPolicy,
     ILogger <ScopedStreamProcessor> logger)
     : base(tenantId, streamProcessorId, initialState, processor, eventsFromStreamsFetcher, eventsFetcherPolicy, logger)
 {
     _streamProcessorStates = streamProcessorStates;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AbstractScopedStreamProcessor"/> class.
 /// </summary>
 /// <param name="tenantId">The <see cref="TenantId"/>.</param>
 /// <param name="streamProcessorId">The <see cref="IStreamProcessorId" />.</param>
 /// <param name="initialState">The initial state of the <see cref="IStreamProcessorState" />.</param>
 /// <param name="processor">An <see cref="IEventProcessor" /> to process the event.</param>
 /// <param name="eventsFetcher">The <see cref="ICanFetchEventsFromStream" />.</param>
 /// <param name="fetchEventsToProcessPolicy">The <see cref="IAsyncPolicyFor{T}" /> <see cref="ICanFetchEventsFromStream" />.</param>
 /// <param name="logger">An <see cref="ILogger" /> to log messages.</param>
 protected AbstractScopedStreamProcessor(
     TenantId tenantId,
     IStreamProcessorId streamProcessorId,
     IStreamProcessorState initialState,
     IEventProcessor processor,
     ICanFetchEventsFromStream eventsFetcher,
     IAsyncPolicyFor <ICanFetchEventsFromStream> fetchEventsToProcessPolicy,
     ILogger logger)
 {
     Identifier                 = streamProcessorId;
     Logger                     = logger;
     _currentState              = initialState;
     _tenantId                  = tenantId;
     _processor                 = processor;
     _eventsFetcher             = eventsFetcher;
     _fetchEventToProcessPolicy = fetchEventsToProcessPolicy;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScopedStreamProcessor"/> class.
 /// </summary>
 /// <param name="tenantId">The <see cref="TenantId"/>.</param>
 /// <param name="streamProcessorId">The <see cref="IStreamProcessorId" />.</param>
 /// <param name="sourceStreamDefinition">The source stream <see cref="IStreamDefinition" />.</param>
 /// <param name="initialState">The <see cref="StreamProcessorState" />.</param>
 /// <param name="processor">An <see cref="IEventProcessor" /> to process the event.</param>
 /// <param name="streamProcessorStates">The <see cref="IResilientStreamProcessorStateRepository" />.</param>
 /// <param name="eventsFromStreamsFetcher">The<see cref="ICanFetchEventsFromStream" />.</param>
 /// <param name="executionContext">The <see cref="ExecutionContext"/> of the stream processor.</param>
 /// <param name="eventFetcherPolicies">The policies to use while fetching events.</param>
 /// <param name="eventWatcher">The <see cref="IStreamEventWatcher" /> to wait for events to be available in stream.</param>
 /// <param name="timeToRetryGetter">The <see cref="ICanGetTimeToRetryFor{T}" /> <see cref="StreamProcessorState" />.</param>
 /// <param name="logger">An <see cref="ILogger" /> to log messages.</param>
 public ScopedStreamProcessor(
     TenantId tenantId,
     IStreamProcessorId streamProcessorId,
     IStreamDefinition sourceStreamDefinition,
     StreamProcessorState initialState,
     IEventProcessor processor,
     IResilientStreamProcessorStateRepository streamProcessorStates,
     ICanFetchEventsFromStream eventsFromStreamsFetcher,
     ExecutionContext executionContext,
     IEventFetcherPolicies eventFetcherPolicies,
     IStreamEventWatcher eventWatcher,
     ICanGetTimeToRetryFor <StreamProcessorState> timeToRetryGetter,
     ILogger logger)
     : base(tenantId, streamProcessorId, sourceStreamDefinition, initialState, processor, eventsFromStreamsFetcher, executionContext, eventFetcherPolicies, eventWatcher, logger)
 {
     _streamProcessorStates = streamProcessorStates;
     _timeToRetryGetter     = timeToRetryGetter;
 }