Esempio n. 1
0
        /// <summary>
        /// Creates a multiple-stream catchup.
        /// </summary>
        /// <typeparam name="TData">The type of the stream's data.</typeparam>
        /// <typeparam name="TUpstreamCursor">The type of the upstream cursor.</typeparam>
        /// <typeparam name="TDownstreamCursor">The type of the downstream cursor.</typeparam>
        /// <param name="stream">The stream.</param>
        /// <param name="cursor">The initial cursor position for the catchup.</param>
        /// <param name="batchSize">The number of items to retrieve from the stream per batch.</param>
        public static IStreamCatchup <TData, TUpstreamCursor> All <TData, TUpstreamCursor, TDownstreamCursor>(
            IStream <IStream <TData, TDownstreamCursor>, TUpstreamCursor> stream,
            ICursor <TUpstreamCursor> cursor = null,
            int?batchSize = null)
        {
            var upstreamCatchup = new SingleStreamCatchup <IStream <TData, TDownstreamCursor>, TUpstreamCursor>(stream, batchSize: batchSize);

            return(new MultiStreamCatchup <TData, TUpstreamCursor, TDownstreamCursor>(
                       upstreamCatchup,
                       cursor ?? stream.NewCursor()));
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a multiple-stream catchup.
        /// </summary>
        /// <typeparam name="TData">The type of the stream's data.</typeparam>
        /// <typeparam name="TUpstreamCursor">The type of the upstream cursor.</typeparam>
        /// <typeparam name="TDownstreamCursor">The type of the downstream cursor.</typeparam>
        /// <param name="stream">The stream.</param>
        /// <param name="batchSize">The number of items to retrieve from the stream per batch.</param>
        public static IStreamCatchup <TData, TUpstreamCursor> All <TData, TUpstreamCursor, TDownstreamCursor>(
            IStream <IStream <TData, TDownstreamCursor>, TUpstreamCursor> stream,
            FetchAndSaveProjection <ICursor <TUpstreamCursor> > manageCursor,
            int?batchSize = null)
        {
            var upstreamCatchup = new SingleStreamCatchup <IStream <TData, TDownstreamCursor>, TUpstreamCursor>(stream, batchSize: batchSize);

            return(new MultiStreamCatchup <TData, TUpstreamCursor, TDownstreamCursor>(
                       upstreamCatchup,
                       manageCursor));
        }
        public DistributedStreamCatchup(
            IPartitionedStream <TData, TCursor, TPartition> partitionedStream,
            IEnumerable <IStreamQueryPartition <TPartition> > partitions,
            int?batchSize = null,
            FetchAndSaveProjection <ICursor <TCursor> > manageCursor       = null,
            IDistributor <IStreamQueryPartition <TPartition> > distributor = null) : base(batchSize)
        {
            if (partitionedStream == null)
            {
                throw new ArgumentNullException("partitionedStream");
            }
            if (partitions == null)
            {
                throw new ArgumentNullException("partitions");
            }

            this.partitionedStream = partitionedStream;

            this.distributor = distributor ?? partitions.DistributeQueriesInProcess();

            manageCursor = manageCursor ?? ((id, aggregate) => aggregate(null));

            this.distributor
#if DEBUG
            .Trace()     // TODO: (DistributedStreamCatchup) figure out a way to let people Trace this distributor
#endif
            .OnReceive(async lease =>
            {
                await manageCursor(lease.ResourceName, async cursor =>
                {
                    var catchup = new SingleStreamCatchup <TData, TCursor>(
                        await partitionedStream.GetStream(lease.Resource),
                        initialCursor: cursor,
                        batchSize: batchSize,
                        subscriptions: new ConcurrentDictionary <Type, IAggregatorSubscription>(aggregatorSubscriptions));

                    return(await catchup.RunSingleBatch());
                });
            });
        }