Ejemplo n.º 1
0
        private void Cancel(IUntypedPublisher target, TimeSpan timeout)
        {
            var typedTarget = UntypedPublisher.ToTyped <T>(target);

            if (
                typedTarget.GetType()
                .GetInterfaces()
                .Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IProcessor <,>)))
            {
                if (Log.IsDebugEnabled)
                {
                    Log.Debug(
                        $"Cancelling {typedTarget} Processor's publisher and subscriber sides (after {timeout.TotalMilliseconds} ms)");
                }
                HandleSubscriptionTimeout(target, new SubscriptionTimeoutException(
                                              $"Publisher was not attached to upstream within deadline {timeout.TotalMilliseconds} ms"));
            }
            else
            if (Log.IsDebugEnabled)
            {
                Log.Debug(
                    $"Cancelling {typedTarget} (after {timeout.TotalMilliseconds} ms)");
            }
            HandleSubscriptionTimeout(target, new SubscriptionTimeoutException(
                                          $"Publisher {typedTarget} you are trying to subscribe to has been shut-down because exceeing its subscription timeout"));
        }
Ejemplo n.º 2
0
        IUntypedPublisher ISourceModule.Create(MaterializationContext context, out object materializer)
        {
            TMat m;
            var  result = Create(context, out m);

            materializer = m;
            return(UntypedPublisher.FromTyped(result));
        }
Ejemplo n.º 3
0
        private void Warn(IUntypedPublisher target, TimeSpan timeout)
        {
            var typedTarget = UntypedPublisher.ToTyped <T>(target);

            Log.Warning(
                "Timed out {0} detected (after {1})! You should investigate if you either cancel or consume all {2} instances",
                typedTarget, timeout, typedTarget.GetType().Name);
        }
Ejemplo n.º 4
0
            protected override object MaterializeAtomic(AtomicModule atomic, Attributes effectiveAttributes,
                                                        IDictionary <IModule, object> materializedValues)
            {
                if (IsDebug)
                {
                    Console.WriteLine($"materializing {atomic}");
                }

                if (atomic is ISinkModule)
                {
                    var    sink = (ISinkModule)atomic;
                    object materialized;
                    var    subscriber = sink.Create(CreateMaterializationContext(effectiveAttributes), out materialized);
                    AssignPort(sink.Shape.Inlets.First(), subscriber);
                    materializedValues.Add(atomic, materialized);
                }
                else if (atomic is ISourceModule)
                {
                    var    source = (ISourceModule)atomic;
                    object materialized;
                    var    publisher = source.Create(CreateMaterializationContext(effectiveAttributes), out materialized);
                    AssignPort(source.Shape.Outlets.First(), publisher);
                    materializedValues.Add(atomic, materialized);
                }
                else if (atomic is IStageModule)
                {
                    // FIXME: Remove this, only stream-of-stream ops need it
                    var stage = (IStageModule)atomic;
                    // assumes BaseType is StageModule<>
                    var methodInfo = ProcessorForMethod.MakeGenericMethod(atomic.GetType().BaseType.GenericTypeArguments);
                    var parameters = new object[]
                    { stage, effectiveAttributes, _materializer.EffectiveSettings(effectiveAttributes), null };
                    var    processor    = methodInfo.Invoke(this, parameters);
                    object materialized = parameters[3];
                    AssignPort(stage.In, UntypedSubscriber.FromTyped(processor));
                    AssignPort(stage.Out, UntypedPublisher.FromTyped(processor));
                    materializedValues.Add(atomic, materialized);
                }
                //else if (atomic is TlsModule)
                //{
                //})
                else if (atomic is GraphModule)
                {
                    var graph = (GraphModule)atomic;
                    MaterializeGraph(graph, effectiveAttributes, materializedValues);
                }
                else if (atomic is GraphStageModule)
                {
                    var stage = (GraphStageModule)atomic;
                    var graph =
                        new GraphModule(
                            GraphAssembly.Create(stage.Shape.Inlets, stage.Shape.Outlets, new[] { stage.Stage }),
                            stage.Shape, stage.Attributes, new IModule[] { stage });
                    MaterializeGraph(graph, effectiveAttributes, materializedValues);
                }

                return(NotUsed.Instance);
            }
Ejemplo n.º 5
0
        /// <summary>
        /// Callback that should ensure that the target is canceled with the given cause.
        /// </summary>
        public void HandleSubscriptionTimeout(IUntypedPublisher target, Exception cause)
        {
            SubstreamOutput output;

            if ((output = UntypedPublisher.ToTyped <T>(target) as SubstreamOutput) != null)
            {
                output.Error(cause);
                output.AttachSubscriber(CancelingSubscriber <T> .Instance);
            }
        }
Ejemplo n.º 6
0
            protected override object MaterializeAtomic(AtomicModule atomic, Attributes effectiveAttributes,
                                                        IDictionary <IModule, object> materializedValues)
            {
                if (IsDebug)
                {
                    Console.WriteLine($"materializing {atomic}");
                }

                if (atomic is ISinkModule)
                {
                    var    sink = (ISinkModule)atomic;
                    object materialized;
                    var    subscriber = sink.Create(CreateMaterializationContext(effectiveAttributes), out materialized);
                    AssignPort(sink.Shape.Inlets.First(), subscriber);
                    materializedValues.Add(atomic, materialized);
                }
                else if (atomic is ISourceModule)
                {
                    var    source = (ISourceModule)atomic;
                    object materialized;
                    var    publisher = source.Create(CreateMaterializationContext(effectiveAttributes), out materialized);
                    AssignPort(source.Shape.Outlets.First(), publisher);
                    materializedValues.Add(atomic, materialized);
                }
                else if (atomic is IProcessorModule)
                {
                    var stage        = atomic as IProcessorModule;
                    var t            = stage.CreateProcessor();
                    var processor    = t.Item1;
                    var materialized = t.Item2;

                    AssignPort(stage.In, UntypedSubscriber.FromTyped(processor));
                    AssignPort(stage.Out, UntypedPublisher.FromTyped(processor));
                    materializedValues.Add(atomic, materialized);
                }
                //else if (atomic is TlsModule)
                //{
                //})
                else if (atomic is GraphModule)
                {
                    var graph = (GraphModule)atomic;
                    MaterializeGraph(graph, effectiveAttributes, materializedValues);
                }
                else if (atomic is GraphStageModule)
                {
                    var stage = (GraphStageModule)atomic;
                    var graph =
                        new GraphModule(
                            GraphAssembly.Create(stage.Shape.Inlets, stage.Shape.Outlets, new[] { stage.Stage }),
                            stage.Shape, stage.Attributes, new IModule[] { stage });
                    MaterializeGraph(graph, effectiveAttributes, materializedValues);
                }

                return(NotUsed.Instance);
            }
Ejemplo n.º 7
0
            protected override object MaterializeAtomic(AtomicModule atomic, Attributes effectiveAttributes, IDictionary <IModule, object> materializedValues)
            {
                foreach (var inPort in atomic.InPorts)
                {
                    var subscriber = new TestSubscriber(atomic, inPort);
                    Subscribers = Subscribers.Add(subscriber);
                    AssignPort(inPort, UntypedSubscriber.FromTyped(subscriber));
                }
                foreach (var outPort in atomic.OutPorts)
                {
                    var publisher = new TestPublisher(atomic, outPort);
                    Publishers = Publishers.Add(publisher);
                    AssignPort(outPort, UntypedPublisher.FromTyped(publisher));
                }

                return(NotUsed.Instance);
            }
Ejemplo n.º 8
0
 public bool OutputSubstreamManagement(object message)
 {
     return(message.Match()
            .With <SubstreamRequestMore>(request =>
     {
         SubstreamOutput output;
         if (_substreamOutputs.TryGetValue(request.Substream, out output))
         {
             if (request.Demand < 1)
             {
                 output.Error(ReactiveStreamsCompliance.NumberOfElementsInRequestMustBePositiveException);
             }
             else
             {
                 output.EnqueueOutputDemand(request.Demand);
             }
         }
     })
            .With <SubstreamSubscribe>(subscribe =>
     {
         SubstreamOutput output;
         if (_substreamOutputs.TryGetValue(subscribe.Substream, out output))
         {
             output.AttachSubscriber(subscribe.Subscriber);
         }
     })
            .With <SubstreamSubscriptionTimeout>(timeout =>
     {
         SubstreamOutput output;
         if (_substreamOutputs.TryGetValue(timeout.Substream, out output) && !output.IsAttached)
         {
             SubscriptionTimedOut(UntypedPublisher.FromTyped(output));
         }
     })
            .With <SubstreamCancel>(cancel => InvalidateSubstreamOutput(cancel.Substream))
            .WasHandled);
 }