async Task <Partitioned.ScopedStreamProcessor> CreatePartitionedScopedStreamProcessor( IStreamProcessorId streamProcessorId, IEventProcessor eventProcessor, ICanFetchEventsFromPartitionedStream eventsFromStreamsFetcher, CancellationToken cancellationToken) { var tryGetStreamProcessorState = await _streamProcessorStates.TryGetFor(streamProcessorId, cancellationToken).ConfigureAwait(false); if (!tryGetStreamProcessorState.Success) { tryGetStreamProcessorState = Partitioned.StreamProcessorState.New; await _streamProcessorStates.Persist(streamProcessorId, tryGetStreamProcessorState.Result, cancellationToken).ConfigureAwait(false); } if (!tryGetStreamProcessorState.Result.Partitioned) { throw new ExpectedPartitionedStreamProcessorState(streamProcessorId); } return(new Partitioned.ScopedStreamProcessor( _tenant, streamProcessorId, tryGetStreamProcessorState.Result as Partitioned.StreamProcessorState, eventProcessor, _streamProcessorStates, eventsFromStreamsFetcher, new Partitioned.FailingPartitions(_streamProcessorStates, eventProcessor, eventsFromStreamsFetcher, _eventsFetcherPolicy, _loggerManager.CreateLogger <Partitioned.FailingPartitions>()), _eventsFetcherPolicy, _loggerManager.CreateLogger <Partitioned.ScopedStreamProcessor>())); }
/// <summary> /// Initializes a new instance of the <see cref="FailingPartitions"/> class. /// </summary> /// <param name="streamProcessorStates">The <see cref="IResilientStreamProcessorStateRepository" />.</param> /// <param name="eventProcessor">The <see cref="IEventProcessor" />.</param> /// <param name="eventsFromStreamsFetcher">The <see cref="ICanFetchEventsFromPartitionedStream" />.</param> /// <param name="eventsFetcherPolicy">The <see cref="IAsyncPolicyFor{T}" /> <see cref="ICanFetchEventsFromStream" />.</param> /// <param name="logger">The <see cref="ILogger" />.</param> public FailingPartitions( IResilientStreamProcessorStateRepository streamProcessorStates, IEventProcessor eventProcessor, ICanFetchEventsFromPartitionedStream eventsFromStreamsFetcher, IAsyncPolicyFor <ICanFetchEventsFromStream> eventsFetcherPolicy, ILogger <FailingPartitions> logger) { _streamProcessorStates = streamProcessorStates; _eventProcessor = eventProcessor; _eventsFromStreamsFetcher = eventsFromStreamsFetcher; _eventsFetcherPolicy = eventsFetcherPolicy; _logger = logger; }
/// <summary> /// Initializes a new instance of the <see cref="FailingPartitions"/> class. /// </summary> /// <param name="streamProcessorStates">The <see cref="IResilientStreamProcessorStateRepository" />.</param> /// <param name="eventProcessor">The <see cref="IEventProcessor" />.</param> /// <param name="eventsFromStreamsFetcher">The <see cref="ICanFetchEventsFromPartitionedStream" />.</param> /// <param name="createExecutionContextForEvent">The factory to use to create execution contexts for event processing.</param> /// <param name="eventFetcherPolicies">The policies to use for fetching events.</param> public FailingPartitions( IResilientStreamProcessorStateRepository streamProcessorStates, IEventProcessor eventProcessor, ICanFetchEventsFromPartitionedStream eventsFromStreamsFetcher, Func <StreamEvent, ExecutionContext> createExecutionContextForEvent, //TODO: Oh man, here we go again. IEventFetcherPolicies eventFetcherPolicies) { _streamProcessorStates = streamProcessorStates; _eventProcessor = eventProcessor; _eventsFromStreamsFetcher = eventsFromStreamsFetcher; _createExecutionContextForEvent = createExecutionContextForEvent; _eventFetcherPolicies = eventFetcherPolicies; }
/// <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="failingPartitions">The <see cref="IFailingPartitions" />.</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, ICanFetchEventsFromPartitionedStream eventsFromStreamsFetcher, IFailingPartitions failingPartitions, IAsyncPolicyFor <ICanFetchEventsFromStream> eventsFetcherPolicy, ILogger <ScopedStreamProcessor> logger) : base(tenantId, streamProcessorId, initialState, processor, eventsFromStreamsFetcher, eventsFetcherPolicy, logger) { _streamProcessorStates = streamProcessorStates; _failingPartitions = failingPartitions; }
/// <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="StreamDefinition" />.</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="failingPartitionsFactory">The factory to use to create the <see cref="IFailingPartitions" />.</param> /// <param name="eventFetcherPolicies">The policies to use while fetching events.</param> /// <param name="streamWatcher">The <see cref="IStreamEventWatcher" />.</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, ICanFetchEventsFromPartitionedStream eventsFromStreamsFetcher, ExecutionContext executionContext, Func <IEventProcessor, ICanFetchEventsFromPartitionedStream, Func <StreamEvent, ExecutionContext>, IFailingPartitions> failingPartitionsFactory, IEventFetcherPolicies eventFetcherPolicies, IStreamEventWatcher streamWatcher, ICanGetTimeToRetryFor <StreamProcessorState> timeToRetryGetter, ILogger logger) : base(tenantId, streamProcessorId, sourceStreamDefinition, initialState, processor, eventsFromStreamsFetcher, executionContext, eventFetcherPolicies, streamWatcher, logger) { _streamProcessorStates = streamProcessorStates; _failingPartitions = failingPartitionsFactory(processor, eventsFromStreamsFetcher, GetExecutionContextForEvent); _timeToRetryGetter = timeToRetryGetter; }