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); }
public StreamRef StreamOf(StreamPath path) { if (path == StreamPath.Empty) throw new ArgumentException("Stream path is empty", nameof(path)); return StreamRef.Deserialize(path); }
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);
/// <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))); }
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)); }
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); }
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)); }
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(); }
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); }
public static Task Publish <TItem>(this StreamRef <TItem> stream, IEnumerable <TItem> batch, StreamSequenceToken token = null) => stream.Publish(new NextItemBatch <TItem>(batch, token));
/// <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))); }
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; }
public static Task Subscribe <TItem>(this StreamRef <TItem> stream, ActorGrain actor) => stream.Subscribe(actor, new SubscribeReceiveItem());
public static Task Publish <TItem>(this StreamRef <TItem> stream, TItem item, StreamSequenceToken token = null) => stream.Publish(new NextItem <TItem>(item, token));