public static IReaderStrategy Create(int phase, IQuerySources sources, ITimeProvider timeProvider, bool stopOnEof, IPrincipal runAs)
        {
            if (!sources.AllStreams && !sources.HasCategories() && !sources.HasStreams()
                && string.IsNullOrEmpty(sources.CatalogStream))
                throw new InvalidOperationException("None of streams and categories are included");
            if (!sources.AllEvents && !sources.HasEvents())
                throw new InvalidOperationException("None of events are included");
            if (sources.HasStreams() && sources.HasCategories())
                throw new InvalidOperationException(
                    "Streams and categories cannot be included in a filter at the same time");
            if (sources.AllStreams && (sources.HasCategories() || sources.HasStreams()))
                throw new InvalidOperationException("Both FromAll and specific categories/streams cannot be set");
            if (sources.AllEvents && sources.HasEvents())
                throw new InvalidOperationException("Both AllEvents and specific event filters cannot be set");

            if (sources.ByStreams && sources.HasStreams())
                throw new InvalidOperationException("foreachStream projections are not supported on stream based sources");

            if ((sources.HasStreams() || sources.AllStreams) && !string.IsNullOrEmpty(sources.CatalogStream))
                throw new InvalidOperationException("catalogStream cannot be used with streams or allStreams");

            if (!string.IsNullOrEmpty(sources.CatalogStream) && !sources.ByStreams)
                throw new InvalidOperationException("catalogStream is only supported in the byStream mode");

            if (!string.IsNullOrEmpty(sources.CatalogStream) && !stopOnEof)
                throw new InvalidOperationException("catalogStream is not supported in the projections mode");

            if (sources.ReorderEventsOption)
            {
                if (!string.IsNullOrEmpty(sources.CatalogStream))
                    throw new InvalidOperationException("Event reordering cannot be used with stream catalogs");
                if (sources.AllStreams)
                    throw new InvalidOperationException("Event reordering cannot be used with fromAll()");
                if (!(sources.HasStreams() && sources.Streams.Length > 1))
                {
                    throw new InvalidOperationException(
                        "Event reordering is only available in fromStreams([]) projections");
                }
                if (sources.ProcessingLagOption < 50)
                    throw new InvalidOperationException("Event reordering requires processing lag at least of 50ms");
            }

            if (sources.HandlesDeletedNotifications && !sources.ByStreams)
                throw new InvalidOperationException(
                    "Deleted stream notifications are only supported with foreachStream()");

            var readerStrategy = new ReaderStrategy(
                phase, sources.AllStreams, sources.Categories, sources.Streams, sources.AllEvents,
                sources.IncludeLinksOption, sources.Events, sources.HandlesDeletedNotifications, sources.CatalogStream,
                sources.ProcessingLagOption, sources.ReorderEventsOption, runAs, timeProvider);
            return readerStrategy;
        }
Пример #2
0
        public ParallelQueryProcessingStrategy(
            string name,
            ProjectionVersion projectionVersion,
            IProjectionStateHandler stateHandler,
            ProjectionConfig projectionConfig,
            IQuerySources sourceDefinition,
            string handlerType,
            string query,
            ProjectionNamesBuilder namesBuilder,
            ILogger logger,
            SpooledStreamReadingDispatcher spoolProcessingResponseDispatcher,
            ReaderSubscriptionDispatcher subscriptionDispatcher)
            : base(name, projectionVersion, projectionConfig, sourceDefinition, logger, subscriptionDispatcher)
        {
            if (string.IsNullOrEmpty(handlerType))
            {
                throw new ArgumentNullException("handlerType");
            }
            if (string.IsNullOrEmpty(query))
            {
                throw new ArgumentNullException("query");
            }

            _stateHandler     = stateHandler;
            _projectionConfig = projectionConfig;
            _sourceDefinition = sourceDefinition;
            _handlerType      = handlerType;
            _query            = query;
            _namesBuilder     = namesBuilder;
            _spoolProcessingResponseDispatcher = spoolProcessingResponseDispatcher;
            if (_sourceDefinition.CatalogStream == SystemStreams.AllStream)
            {
                _catalogStreamName = SystemStreams.AllStream;
            }
            else if (_sourceDefinition.HasCategories())
            {
                _catalogStreamName = _namesBuilder.GetCategoryCatalogStreamName(_sourceDefinition.Categories[0]);
            }
            else
            {
                _catalogStreamName = _sourceDefinition.CatalogStream;
            }
        }
        public ParallelQueryProcessingStrategy(
            string name,
            ProjectionVersion projectionVersion,
            IProjectionStateHandler stateHandler,
            ProjectionConfig projectionConfig,
            IQuerySources sourceDefinition,
            string handlerType,
            string query,
            ProjectionNamesBuilder namesBuilder,
            ILogger logger,
            SpooledStreamReadingDispatcher spoolProcessingResponseDispatcher,
            ReaderSubscriptionDispatcher subscriptionDispatcher)
            : base(name, projectionVersion, projectionConfig, sourceDefinition, logger, subscriptionDispatcher)
        {
            if (string.IsNullOrEmpty(handlerType)) throw new ArgumentNullException("handlerType");
            if (string.IsNullOrEmpty(query)) throw new ArgumentNullException("query");

            _stateHandler = stateHandler;
            _projectionConfig = projectionConfig;
            _sourceDefinition = sourceDefinition;
            _handlerType = handlerType;
            _query = query;
            _namesBuilder = namesBuilder;
            _spoolProcessingResponseDispatcher = spoolProcessingResponseDispatcher;
            if (_sourceDefinition.CatalogStream == SystemStreams.AllStream)
            {
                _catalogStreamName = SystemStreams.AllStream;
            }
            else if (_sourceDefinition.HasCategories())
            {
                _catalogStreamName = _namesBuilder.GetCategoryCatalogStreamName(_sourceDefinition.Categories[0]);
            }
            else
            {
                _catalogStreamName = _sourceDefinition.CatalogStream;
            }
        }
Пример #4
0
        public ProjectionProcessingStrategy CreateProjectionProcessingStrategy(
            string name,
            ProjectionVersion projectionVersion,
            ProjectionNamesBuilder namesBuilder,
            IQuerySources sourceDefinition,
            ProjectionConfig projectionConfig,
            IProjectionStateHandler stateHandler, string handlerType, string query)
        {
            if (!sourceDefinition.DisableParallelismOption && projectionConfig.StopOnEof && sourceDefinition.ByStreams &&
                sourceDefinition.DefinesFold && !string.IsNullOrEmpty(sourceDefinition.CatalogStream))
            {
                return(new ParallelQueryProcessingStrategy(
                           name,
                           projectionVersion,
                           stateHandler,
                           projectionConfig,
                           sourceDefinition,
                           handlerType,
                           query,
                           namesBuilder,
                           _logger,
                           _spoolProcessingResponseDispatcher,
                           _subscriptionDispatcher));
            }

            if (!sourceDefinition.DisableParallelismOption && projectionConfig.StopOnEof && sourceDefinition.ByStreams &&
                sourceDefinition.DefinesFold && sourceDefinition.HasCategories())
            {
                return(new ParallelQueryProcessingStrategy(
                           name,
                           projectionVersion,
                           stateHandler,
                           projectionConfig,
                           sourceDefinition,
                           handlerType,
                           query,
                           namesBuilder,
                           _logger,
                           _spoolProcessingResponseDispatcher,
                           _subscriptionDispatcher));
            }

            return(projectionConfig.StopOnEof
                                ? (ProjectionProcessingStrategy)
                   new QueryProcessingStrategy(
                       name,
                       projectionVersion,
                       stateHandler,
                       projectionConfig,
                       sourceDefinition,
                       _logger,
                       _subscriptionDispatcher)
                                : new ContinuousProjectionProcessingStrategy(
                       name,
                       projectionVersion,
                       stateHandler,
                       projectionConfig,
                       sourceDefinition,
                       _logger,
                       _subscriptionDispatcher));
        }
Пример #5
0
        public static IReaderStrategy Create(
            string tag,
            int phase,
            IQuerySources sources,
            ITimeProvider timeProvider,
            bool stopOnEof,
            IPrincipal runAs)
        {
            if (!sources.AllStreams && !sources.HasCategories() && !sources.HasStreams() &&
                string.IsNullOrEmpty(sources.CatalogStream))
            {
                throw new InvalidOperationException("None of streams and categories are included");
            }
            if (!sources.AllEvents && !sources.HasEvents())
            {
                throw new InvalidOperationException("None of events are included");
            }
            if (sources.HasStreams() && sources.HasCategories())
            {
                throw new InvalidOperationException(
                          "Streams and categories cannot be included in a filter at the same time");
            }
            if (sources.AllStreams && (sources.HasCategories() || sources.HasStreams()))
            {
                throw new InvalidOperationException("Both FromAll and specific categories/streams cannot be set");
            }
            if (sources.AllEvents && sources.HasEvents())
            {
                throw new InvalidOperationException("Both AllEvents and specific event filters cannot be set");
            }

            if (sources.ByStreams && sources.HasStreams())
            {
                throw new InvalidOperationException(
                          "foreachStream projections are not supported on stream based sources");
            }

            if ((sources.HasStreams() || sources.AllStreams) && !string.IsNullOrEmpty(sources.CatalogStream))
            {
                throw new InvalidOperationException("catalogStream cannot be used with streams or allStreams");
            }

            if (!string.IsNullOrEmpty(sources.CatalogStream) && !sources.ByStreams)
            {
                throw new InvalidOperationException("catalogStream is only supported in the byStream mode");
            }

            if (!string.IsNullOrEmpty(sources.CatalogStream) && !stopOnEof)
            {
                throw new InvalidOperationException("catalogStream is not supported in the projections mode");
            }

            if (sources.ReorderEventsOption)
            {
                if (!string.IsNullOrEmpty(sources.CatalogStream))
                {
                    throw new InvalidOperationException("Event reordering cannot be used with stream catalogs");
                }
                if (sources.AllStreams)
                {
                    throw new InvalidOperationException("Event reordering cannot be used with fromAll()");
                }
                if (!(sources.HasStreams() && sources.Streams.Length > 1))
                {
                    throw new InvalidOperationException(
                              "Event reordering is only available in fromStreams([]) projections");
                }
                if (sources.ProcessingLagOption < 50)
                {
                    throw new InvalidOperationException("Event reordering requires processing lag at least of 50ms");
                }
            }

            if (sources.HandlesDeletedNotifications && !sources.ByStreams)
            {
                throw new InvalidOperationException(
                          "Deleted stream notifications are only supported with foreachStream()");
            }

            var readerStrategy = new ReaderStrategy(
                tag,
                phase,
                sources.AllStreams,
                sources.Categories,
                sources.Streams,
                sources.AllEvents,
                sources.IncludeLinksOption,
                sources.Events,
                sources.HandlesDeletedNotifications,
                sources.CatalogStream,
                sources.ProcessingLagOption,
                sources.ReorderEventsOption,
                runAs,
                timeProvider);

            return(readerStrategy);
        }
        public ProjectionProcessingStrategy CreateProjectionProcessingStrategy(
            string name,
            ProjectionVersion projectionVersion,
            ProjectionNamesBuilder namesBuilder,
            IQuerySources sourceDefinition,
            ProjectionConfig projectionConfig,
            IProjectionStateHandler stateHandler, string handlerType, string query)
        {

            if (!sourceDefinition.DisableParallelismOption && projectionConfig.StopOnEof && sourceDefinition.ByStreams
                && sourceDefinition.DefinesFold && !string.IsNullOrEmpty(sourceDefinition.CatalogStream))
            {
                return new ParallelQueryProcessingStrategy(
                    name,
                    projectionVersion,
                    stateHandler,
                    projectionConfig,
                    sourceDefinition,
                    handlerType,
                    query,
                    namesBuilder,
                    _logger,
                    _spoolProcessingResponseDispatcher,
                    _subscriptionDispatcher);
            }

            if (!sourceDefinition.DisableParallelismOption && projectionConfig.StopOnEof && sourceDefinition.ByStreams
                && sourceDefinition.DefinesFold && sourceDefinition.HasCategories())
            {
                return new ParallelQueryProcessingStrategy(
                    name,
                    projectionVersion,
                    stateHandler,
                    projectionConfig,
                    sourceDefinition,
                    handlerType,
                    query,
                    namesBuilder,
                    _logger,
                    _spoolProcessingResponseDispatcher,
                    _subscriptionDispatcher);
            }

            return projectionConfig.StopOnEof
                ? (ProjectionProcessingStrategy)
                    new QueryProcessingStrategy(
                        name,
                        projectionVersion,
                        stateHandler,
                        projectionConfig,
                        sourceDefinition,
                        _logger,
                        _subscriptionDispatcher)
                : new ContinuousProjectionProcessingStrategy(
                    name,
                    projectionVersion,
                    stateHandler,
                    projectionConfig,
                    sourceDefinition,
                    _logger,
                    _subscriptionDispatcher);
        }