コード例 #1
0
ファイル: Ref.cs プロジェクト: zloom/Orleankka
        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);
        }
コード例 #2
0
ファイル: ActorSystem.cs プロジェクト: zloom/Orleankka
        public StreamRef StreamOf(StreamPath path)
        {
            if (path == StreamPath.Empty)
                throw new ArgumentException("Stream path is empty", nameof(path));

            return StreamRef.Deserialize(path);
        }
コード例 #3
0
ファイル: ActorSystem.cs プロジェクト: mbernard/Orleankka
        public StreamRef StreamOf(StreamPath path)
        {
            if (path == StreamPath.Empty)
            {
                throw new ArgumentException("Stream path is empty", "path");
            }

            return(StreamRef.Deserialize(path));
        }
コード例 #4
0
 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);
コード例 #5
0
ファイル: StreamExtensions.cs プロジェクト: rikace/Orleankka
        /// <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;
            }));
        }
コード例 #6
0
 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);
コード例 #7
0
        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)));
        }
コード例 #8
0
        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)));
        }
コード例 #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));
        }
コード例 #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);
        }
コード例 #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));
        }
コード例 #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();
        }
コード例 #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);
        }
コード例 #14
0
 public static Task Publish <TItem>(this StreamRef <TItem> stream, IEnumerable <TItem> batch, StreamSequenceToken token = null) =>
 stream.Publish(new NextItemBatch <TItem>(batch, token));
コード例 #15
0
ファイル: StreamExtensions.cs プロジェクト: rikace/Orleankka
        /// <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)));
        }
コード例 #16
0
 public static Task Resume <TItem>(this StreamRef <TItem> stream, ActorGrain actor) =>
 stream.Resume(actor, new ResumeReceiveItem());
コード例 #17
0
 protected internal StreamSubscription(StreamRef <TItem> stream, StreamSubscriptionHandle <TItem> handle, Guid?id = null)
 {
     this.handle = handle;
     Stream      = stream;
     Id          = id ?? handle.HandleId;
 }
コード例 #18
0
 public static Task Subscribe <TItem>(this StreamRef <TItem> stream, ActorGrain actor) =>
 stream.Subscribe(actor, new SubscribeReceiveItem());
コード例 #19
0
 public static Task Publish <TItem>(this StreamRef <TItem> stream, TItem item, StreamSequenceToken token = null) =>
 stream.Publish(new NextItem <TItem>(item, token));