Ejemplo n.º 1
0
 public void Cancel()
 {
     _downstreamCanceled = true;
     if (!_upstreamCompleted)
     {
         _upstreamCompleted = true;
         if (!ReferenceEquals(_upstream, null))
         {
             ReactiveStreamsCompliance.TryCancel(_upstream);
         }
         Clear();
     }
 }
Ejemplo n.º 2
0
 public void OnSubscribe(ISubscription subscription)
 {
     if (subscription == null)
     {
         throw new ArgumentException("Subscription cannot be null");
     }
     if (_upstreamCompleted)
     {
         ReactiveStreamsCompliance.TryCancel(subscription);
     }
     else if (_downstreamCanceled)
     {
         _upstreamCompleted = true;
         ReactiveStreamsCompliance.TryCancel(subscription);
     }
     else
     {
         _upstream = subscription;
         // prefetch
         ReactiveStreamsCompliance.TryRequest(_upstream, _inputBuffer.Length);
     }
 }
Ejemplo n.º 3
0
 public void Receive(ActorGraphInterpreter.IBoundaryEvent e)
 {
     if (_waitingForShutdown)
     {
         if (e is ActorGraphInterpreter.ExposedPublisher)
         {
             var exposedPublisher = (ActorGraphInterpreter.ExposedPublisher)e;
             _outputs[exposedPublisher.Id].ExposedPublisher(exposedPublisher.Publisher);
             _publishersPending--;
             if (CanShutdown)
             {
                 IsTerminated = true;
             }
         }
         else if (e is ActorGraphInterpreter.OnSubscribe)
         {
             var onSubscribe = (ActorGraphInterpreter.OnSubscribe)e;
             ReactiveStreamsCompliance.TryCancel(onSubscribe.Subscription);
             _subscribersPending--;
             if (CanShutdown)
             {
                 IsTerminated = true;
             }
         }
         else if (e is ActorGraphInterpreter.Abort)
         {
             TryAbort(new TimeoutException(
                          $"Streaming actor has been already stopped processing (normally), but not all of its inputs or outputs have been subscribed in [{_settings.SubscriptionTimeoutSettings.Timeout}]. Aborting actor now."));
         }
     }
     else
     {
         // Cases that are most likely on the hot path, in decreasing order of frequency
         if (e is ActorGraphInterpreter.OnNext)
         {
             var onNext = (ActorGraphInterpreter.OnNext)e;
             if (GraphInterpreter.IsDebug)
             {
                 Console.WriteLine($"{Interpreter.Name}  OnNext {onNext.Event} id={onNext.Id}");
             }
             _inputs[onNext.Id].OnNext(onNext.Event);
             RunBatch();
         }
         else if (e is ActorGraphInterpreter.RequestMore)
         {
             var requestMore = (ActorGraphInterpreter.RequestMore)e;
             if (GraphInterpreter.IsDebug)
             {
                 Console.WriteLine($"{Interpreter.Name}  Request {requestMore.Demand} id={requestMore.Id}");
             }
             _outputs[requestMore.Id].RequestMore(requestMore.Demand);
             RunBatch();
         }
         else if (e is ActorGraphInterpreter.Resume)
         {
             if (GraphInterpreter.IsDebug)
             {
                 Console.WriteLine($"{Interpreter.Name}  Resume");
             }
             _resumeScheduled = false;
             if (Interpreter.IsSuspended)
             {
                 RunBatch();
             }
         }
         else if (e is ActorGraphInterpreter.AsyncInput)
         {
             var asyncInput = (ActorGraphInterpreter.AsyncInput)e;
             Interpreter.RunAsyncInput(asyncInput.Logic, asyncInput.Event, asyncInput.Handler);
             RunBatch();
         }
         // Initialization and completion messages
         else if (e is ActorGraphInterpreter.OnError)
         {
             var onError = (ActorGraphInterpreter.OnError)e;
             if (GraphInterpreter.IsDebug)
             {
                 Console.WriteLine($"{Interpreter.Name}  OnError id={onError.Id}");
             }
             _inputs[onError.Id].OnError(onError.Cause);
             RunBatch();
         }
         else if (e is ActorGraphInterpreter.OnComplete)
         {
             var onComplete = (ActorGraphInterpreter.OnComplete)e;
             if (GraphInterpreter.IsDebug)
             {
                 Console.WriteLine($"{Interpreter.Name}  OnComplete id={onComplete.Id}");
             }
             _inputs[onComplete.Id].OnComplete();
             RunBatch();
         }
         else if (e is ActorGraphInterpreter.OnSubscribe)
         {
             var onSubscribe = (ActorGraphInterpreter.OnSubscribe)e;
             if (GraphInterpreter.IsDebug)
             {
                 Console.WriteLine($"{Interpreter.Name}  OnSubscribe id={onSubscribe.Id}");
             }
             _subscribersPending--;
             _inputs[onSubscribe.Id].OnSubscribe(onSubscribe.Subscription);
             RunBatch();
         }
         else if (e is ActorGraphInterpreter.Cancel)
         {
             var cancel = (ActorGraphInterpreter.Cancel)e;
             if (GraphInterpreter.IsDebug)
             {
                 Console.WriteLine($"{Interpreter.Name}  Cancel id={cancel.Id}");
             }
             _outputs[cancel.Id].Cancel();
             RunBatch();
         }
         else if (e is ActorGraphInterpreter.SubscribePending)
         {
             var subscribePending = (ActorGraphInterpreter.SubscribePending)e;
             _outputs[subscribePending.Id].SubscribePending();
         }
         else if (e is ActorGraphInterpreter.ExposedPublisher)
         {
             var exposedPublisher = (ActorGraphInterpreter.ExposedPublisher)e;
             _publishersPending--;
             _outputs[exposedPublisher.Id].ExposedPublisher(exposedPublisher.Publisher);
         }
     }
 }