Esempio n. 1
0
        /// <summary>
        /// Shard a streamable
        /// </summary>
        /// <typeparam name="TPayload">The event payload type</typeparam>
        /// <param name="source">The stream to shard</param>
        /// <param name="shardArity">The number of shards to create</param>
        /// <returns>A sharded stream across <paramref name="shardArity"/> shards</returns>
        public static IShardedStreamable <Empty, TPayload> Shard <TPayload>(this IStreamable <Empty, TPayload> source, int shardArity = -1)
        {
            if (shardArity == -1)
            {
                shardArity = Config.StreamScheduler.scheduler.MapArity;
            }

            var spray = new SprayGroupImportStreamable <Empty, TPayload>(source, shardArity, false, null);

            var streamables = new IStreamable <Empty, TPayload> [shardArity];

            for (int i = 0; i < shardArity; i++)
            {
                streamables[i] = new PassthroughStreamable <Empty, TPayload>(spray);
            }

            return(new ShardedStreamable <Empty, TPayload>(streamables));
        }
Esempio n. 2
0
        /// <summary>
        /// Broadcast operation on a sharded streamable
        /// </summary>
        /// <param name="newLocation">Assign an optional new location descriptor</param>
        /// <returns>A new sharded streamable post-broadcast</returns>
        public IShardedStreamable <TKey, TPayload> Broadcast(ILocationDescriptor newLocation = null)
        {
            int newShardArity = (newLocation != null && (int)newLocation.GetLocation() > 0) ? (int)newLocation.GetLocation() : this.Streamables.Length;

            var broadcastResults = new SprayGroupImportStreamable <TKey, TPayload> [this.Streamables.Length];

            for (int i = 0; i < this.Streamables.Length; i++)
            {
                broadcastResults[i] = new SprayGroupImportStreamable <TKey, TPayload>(this.Streamables[i], newShardArity, true);
            }

            var unionResults = new IStreamable <TKey, TPayload> [newShardArity];

            for (int i = 0; i < newShardArity; i++)
            {
                unionResults[i] = new MultiUnionStreamable <TKey, TPayload>(broadcastResults);
            }

            return(new ShardedStreamable <TKey, TPayload>(unionResults));
        }