/// <summary> /// Initializes a new instance of the <see cref="StreamProcessor"/> class. /// </summary> /// <param name="streamProcessorId">The <see cref="StreamProcessorId" />.</param> /// <param name="onAllTenants">The <see cref="IPerformActionOnAllTenants" />.</param> /// <param name="streamDefinition">The <see cref="IStreamDefinition" />.</param> /// <param name="getEventProcessor">The <see cref="Func{TResult}" /> that returns an <see cref="IEventProcessor" />.</param> /// <param name="unregister">An <see cref="Action" /> that unregisters the <see cref="ScopedStreamProcessor" />.</param> /// <param name="getScopedStreamProcessorsCreator">The <see cref="ICreateScopedStreamProcessors" />.</param> /// <param name="executionContextManager">The <see cref="IExecutionContextManager" />.</param> /// <param name="logger">The <see cref="ILogger" />.</param> /// <param name="cancellationToken">The <see cref="CancellationToken" />.</param> public StreamProcessor( StreamProcessorId streamProcessorId, IPerformActionOnAllTenants onAllTenants, IStreamDefinition streamDefinition, Func <IEventProcessor> getEventProcessor, Action unregister, FactoryFor <ICreateScopedStreamProcessors> getScopedStreamProcessorsCreator, IExecutionContextManager executionContextManager, ILogger <StreamProcessor> logger, CancellationToken cancellationToken) { _identifier = streamProcessorId; _onAllTenants = onAllTenants; _streamDefinition = streamDefinition; _getEventProcessor = getEventProcessor; _unregister = unregister; _getScopedStreamProcessorsCreator = getScopedStreamProcessorsCreator; _executionContextManager = executionContextManager; _logger = logger; _internalCancellationTokenSource = new CancellationTokenSource(); _externalCancellationToken = cancellationToken; _unregisterTokenRegistration = _externalCancellationToken.Register(_unregister); }
/// <inheritdoc /> public bool TryRegister( ScopeId scopeId, EventProcessorId eventProcessorId, IStreamDefinition streamDefinition, Func <IEventProcessor> getEventProcessor, CancellationToken cancellationToken, out StreamProcessor streamProcessor) { streamProcessor = default; var streamProcessorId = new StreamProcessorId(scopeId, eventProcessorId, streamDefinition.StreamId); if (_streamProcessors.ContainsKey(streamProcessorId)) { _logger.Warning("Stream Processor with Id: '{streamProcessorId}' already registered", streamProcessorId); return(false); } streamProcessor = new StreamProcessor( streamProcessorId, _onAllTenants, streamDefinition, getEventProcessor, () => Unregister(streamProcessorId), _getScopedStreamProcessorsCreator, _executionContextManager, _loggerManager.CreateLogger <StreamProcessor>(), cancellationToken); if (!_streamProcessors.TryAdd(streamProcessorId, streamProcessor)) { _logger.Warning("Stream Processor with Id: '{StreamProcessorId}' already registered", streamProcessorId); streamProcessor = default; return(false); } _logger.Trace("Stream Processor with Id: '{StreamProcessorId}' registered", streamProcessorId); return(true); }
void Unregister(StreamProcessorId id) { _logger.Debug("Unregistering Stream Processor: {streamProcessorId}", id); _streamProcessors.TryRemove(id, out var _); }