Example #1
0
        public static Ref Deserialize(string path, Type type)
        {
            if (type == typeof(ClientRef))
            {
                return(ClientRef.Deserialize(path));
            }

            if (type == typeof(ActorRef))
            {
                return(ActorRef.Deserialize(path));
            }

            if (type == typeof(StreamRef))
            {
                return(StreamRef.Deserialize(path));
            }

            var deserializer = deserializers.Find(type);

            if (deserializer != null)
            {
                return(deserializer(path));
            }

            throw new InvalidOperationException("Unknown ref type: " + type);
        }
Example #2
0
        public StreamRef StreamOf(StreamPath path)
        {
            if (path == StreamPath.Empty)
                throw new ArgumentException("Stream path is empty", nameof(path));

            return StreamRef.Deserialize(path);
        }
Example #3
0
        public StreamRef StreamOf(StreamPath path)
        {
            if (path == StreamPath.Empty)
            {
                throw new ArgumentException("Stream path is empty", "path");
            }

            return(StreamRef.Deserialize(path));
        }
 public static Task <StreamSubscription <TItem> > Subscribe <TItem>(
     this StreamRef <TItem> stream,
     Action <IList <SequentialItem <TItem> > > callback,
     StreamSequenceToken token = null) =>
 stream.Subscribe(b =>
 {
     callback(b);
     return(Task.CompletedTask);
 },
                  token);
Example #5
0
        /// <summary>
        /// Subscribe a consumer to this stream reference using strongly-typed delegate.
        /// </summary>
        /// <typeparam name="T">The type of the items produced by the stream.</typeparam>
        /// <param name="stream">The stream reference.</param>
        /// <param name="callback">Strongly-typed version of callback delegate.</param>
        /// <returns>
        /// A promise for a StreamSubscription that represents the subscription.
        /// The consumer may unsubscribe by using this object.
        /// The subscription remains active for as long as it is not explicitely unsubscribed.
        /// </returns>
        public static Task <StreamSubscription> Subscribe <T>(this StreamRef stream, Action <T> callback)
        {
            Requires.NotNull(callback, nameof(callback));

            return(stream.Subscribe((source, item) =>
            {
                callback((T)item);
                return TaskDone.Done;
            }));
        }
 public static Task <StreamSubscription <TItem> > Subscribe <TItem>(
     this StreamRef <TItem> stream,
     Action <TItem, StreamSequenceToken> callback,
     StreamFilter filter       = null,
     StreamSequenceToken token = null) =>
 stream.Subscribe((i, t) =>
 {
     callback(i, t);
     return(Task.CompletedTask);
 },
                  filter, token);
        public static Task <StreamSubscription <TItem> > Subscribe <TItem>(
            this StreamRef <TItem> stream,
            Func <IList <SequentialItem <TItem> >, Task> callback,
            StreamSequenceToken token = null)
        {
            Task Handler(StreamMessage message) =>
            message is StreamItemBatch <TItem> x
                    ? callback(x.Items)
                    : Task.CompletedTask;

            return(stream.Subscribe(Handler, new SubscribeReceiveBatch(token)));
        }
        public static Task <StreamSubscription <TItem> > Subscribe <TItem>(
            this StreamRef <TItem> stream,
            Func <TItem, StreamSequenceToken, Task> callback,
            StreamFilter filter       = null,
            StreamSequenceToken token = null)
        {
            Task Handler(StreamMessage message) =>
            message is StreamItem <TItem> x
                    ? callback(x.Item, x.Token)
                    : Task.CompletedTask;

            return(stream.Subscribe(Handler, new SubscribeReceiveItem(filter, token)));
        }
Example #9
0
        public static async Task Subscribe(this StreamRef stream, Actor actor, StreamFilter filter = null)
        {
            Requires.NotNull(actor, nameof(actor));

            var subscriptions = await stream.Subscriptions();

            if (subscriptions.Count == 1)
            {
                return;
            }

            Debug.Assert(subscriptions.Count == 0,
                         "We should keep only one active subscription per-stream per-actor");

            await stream.Subscribe(x => actor.Host.Receive(x), filter ?? DeclaredHandlerOnlyFilter(actor));
        }
Example #10
0
        public static async Task Subscribe(this StreamRef stream, ActorGrain actor, StreamFilter filter = null)
        {
            Requires.NotNull(actor, nameof(actor));

            var subscriptions = await stream.Subscriptions();

            if (subscriptions.Count == 1)
            {
                return;
            }

            Debug.Assert(subscriptions.Count == 0,
                         "We should keep only one active subscription per-stream per-actor");

            await stream.Subscribe(actor.ReceiveRequest, filter);
        }
Example #11
0
        public static async Task Resume(this StreamRef stream, Actor actor)
        {
            Requires.NotNull(actor, nameof(actor));

            var subscriptions = await stream.Subscriptions();

            if (subscriptions.Count == 0)
            {
                return;
            }

            Debug.Assert(subscriptions.Count == 1,
                         "We should keep only one active subscription per-stream per-actor");

            await subscriptions[0].Resume(x => actor.Host.Receive(x));
        }
Example #12
0
        public static async Task Unsubscribe <TItem>(this StreamRef <TItem> stream, ActorGrain actor)
        {
            Requires.NotNull(actor, nameof(actor));

            var subscriptions = await stream.Subscriptions();

            if (subscriptions.Count == 0)
            {
                return;
            }

            Debug.Assert(subscriptions.Count == 1,
                         "We should keep only one active subscription per-stream per-actor");

            await subscriptions[0].Unsubscribe();
        }
Example #13
0
        public static async Task Resume <TItem, TOptions>(this StreamRef <TItem> stream, ActorGrain actor, TOptions options)
            where TOptions : ResumeOptions
        {
            Requires.NotNull(actor, nameof(actor));

            var subscriptions = await stream.Subscriptions();

            if (subscriptions.Count == 0)
            {
                return;
            }

            Debug.Assert(subscriptions.Count == 1,
                         "We should keep only one active subscription per-stream per-actor");

            await subscriptions[0].Resume(actor.ReceiveRequest, options);
        }
Example #14
0
 public static Task Publish <TItem>(this StreamRef <TItem> stream, IEnumerable <TItem> batch, StreamSequenceToken token = null) =>
 stream.Publish(new NextItemBatch <TItem>(batch, token));
Example #15
0
        /// <summary>
        /// Subscribe a consumer to this stream reference using strongly-typed delegate.
        /// </summary>
        /// <typeparam name="T">The type of the items produced by the stream.</typeparam>
        /// <param name="stream">The stream reference.</param>
        /// <param name="callback">Strongly-typed version of callback delegate.</param>
        /// <returns>
        /// A promise for a StreamSubscription that represents the subscription.
        /// The consumer may unsubscribe by using this object.
        /// The subscription remains active for as long as it is not explicitely unsubscribed.
        /// </returns>
        public static Task <StreamSubscription> Subscribe <T>(this StreamRef stream, Func <T, Task> callback)
        {
            Requires.NotNull(callback, nameof(callback));

            return(stream.Subscribe((source, item) => callback((T)item)));
        }
Example #16
0
 public static Task Resume <TItem>(this StreamRef <TItem> stream, ActorGrain actor) =>
 stream.Resume(actor, new ResumeReceiveItem());
 protected internal StreamSubscription(StreamRef <TItem> stream, StreamSubscriptionHandle <TItem> handle, Guid?id = null)
 {
     this.handle = handle;
     Stream      = stream;
     Id          = id ?? handle.HandleId;
 }
Example #18
0
 public static Task Subscribe <TItem>(this StreamRef <TItem> stream, ActorGrain actor) =>
 stream.Subscribe(actor, new SubscribeReceiveItem());
Example #19
0
 public static Task Publish <TItem>(this StreamRef <TItem> stream, TItem item, StreamSequenceToken token = null) =>
 stream.Publish(new NextItem <TItem>(item, token));