Beispiel #1
0
        private void Ingress(IStreamObserver <TKey, TPayload> observer)
        {
            bool done     = false;
            int  messages = 0;

            try
            {
                var serializer = StreamableSerializer.Create <QueuedMessage <StreamMessage <TKey, TPayload> > >(new SerializerSettings());
                while (!done)
                {
                    var message = serializer.Deserialize(this.stream);
                    if (message.Kind == MessageKind.Completed)
                    {
                        done = true;
                    }
                    observer.OnNext(message.Message);
                    messages++;
                    if (this.numMessages != 0 && messages == this.numMessages)
                    {
                        if (message.Kind != MessageKind.Completed)
                        {
                            observer.OnCompleted();
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                observer.OnError(e);
            }
        }
Beispiel #2
0
        private void Ingress(IStreamObserver <TKey, TPayload> observer)
        {
            int messages = 0;

            try
            {
                var serializer = StreamableSerializer.Create <QueuedMessage <StreamMessage <TKey, TPayload> > >(
                    new SerializerSettings()
                {
                    KnownTypes = StreamMessageManager.GeneratedTypes()
                });
                while (true)
                {
                    var message = serializer.Deserialize(this.stream);
                    if (message.Kind != MessageKind.Completed)
                    {
                        observer.OnNext(message.Message);
                        messages++;
                    }
                    if (message.Kind == MessageKind.Completed ||
                        (this.numMessages != 0 && messages == this.numMessages))
                    {
                        observer.OnCompleted();
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                observer.OnError(e);
            }

            this.onSubscriptionCompleted();
        }
        public IStreamObserver <TK, TP> RegisterStreamObserver <TK, TP>(IStreamObserver <TK, TP> o, Guid?classId = null)
        {
            // Check if already wrapped
            if (o as WrapperStreamObserver <TK, TP> != null)
            {
                return(o);
            }

            var cid = o.ClassId;

            if (this.useCommonSprayPool && (classId != null))
            {
                cid = classId.Value;
            }

            var t = new TaskEntry(cid, m => o.OnNext((StreamMessage <TK, TP>)m), o.OnCompleted, o.OnFlush, o.OnError);

            this.taskTable.TryAdd(cid, t);

            return(new WrapperStreamObserver <TK, TP>(o, this, t));
        }
Beispiel #4
0
        public override IDisposable Subscribe(IStreamObserver <TKey, TPayload> consumer)
        {
            // assign unique ids to each output
            int offset = this.count++;

            void LocalOn(StreamMessage <TKey, TPayload> batch)
            {
                this.pool.Get(out this.batch);
                this.batch.CloneFrom(batch, false);
                consumer.OnNext(this.batch);
            }

            if (offset == 0)
            {
                this.onError          = consumer.OnError;
                this.onFlush          = consumer.OnFlush;
                this.onCompleted      = consumer.OnCompleted;
                this.on               = LocalOn;
                this.checkpoint       = consumer.Checkpoint;
                this.restore          = consumer.Restore;
                this.reset            = consumer.Reset;
                this.produceQueryPlan = consumer.ProduceQueryPlan;
            }
            else
            {
                this.onError          += consumer.OnError;
                this.onFlush          += consumer.OnFlush;
                this.onCompleted      += consumer.OnCompleted;
                this.on               += LocalOn;
                this.checkpoint       += consumer.Checkpoint;
                this.restore          += consumer.Restore;
                this.reset            += consumer.Reset;
                this.produceQueryPlan += consumer.ProduceQueryPlan;
            }

            // TODO: return actual disposable that can be used to dispose the corresponding on calls
            return(Utility.EmptyDisposable);
        }