Ejemplo n.º 1
0
        IUntypedSubscriber ISinkModule.Create(MaterializationContext context, out object materializer)
        {
            TMat m;
            var  result = Create(context, out m);

            materializer = m;
            return(UntypedSubscriber.FromTyped(result));
        }
Ejemplo n.º 2
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.º 3
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.º 4
0
 public void AttachSubscriber(ISubscriber <T> subscriber)
 {
     if (Subscriber == null)
     {
         Subscriber = UntypedSubscriber.FromTyped(subscriber);
         ReactiveStreamsCompliance.TryOnSubscribe(subscriber, _subscription);
     }
     else
     {
         ReactiveStreamsCompliance.RejectAdditionalSubscriber(subscriber, "Substream publisher");
     }
 }
Ejemplo n.º 5
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.º 6
0
            private void MaterializeGraph(GraphModule graph, Attributes effectiveAttributes, IDictionary <IModule, object> materializedValues)
            {
                var calculatedSettings = _materializer.EffectiveSettings(effectiveAttributes);
                var t           = graph.Assembly.Materialize(effectiveAttributes, graph.MaterializedValueIds, materializedValues, RegisterSource);
                var inHandlers  = t.Item1;
                var outHandlers = t.Item2;
                var logics      = t.Item3;

                var shell = new GraphInterpreterShell(graph.Assembly, inHandlers, outHandlers, logics, graph.Shape, calculatedSettings, _materializer);
                var impl  = _subflowFuser != null && !effectiveAttributes.Contains(Attributes.AsyncBoundary.Instance)
                    ? _subflowFuser(shell)
                    : _materializer.ActorOf(ActorGraphInterpreter.Props(shell), StageName(effectiveAttributes), calculatedSettings.Dispatcher);

                var i = 0;
                var inletsEnumerator = graph.Shape.Inlets.GetEnumerator();

                while (inletsEnumerator.MoveNext())
                {
                    var inlet       = inletsEnumerator.Current;
                    var elementType = inlet.GetType().GetGenericArguments().First();
                    var subscriber  = typeof(ActorGraphInterpreter.BoundarySubscriber <>).Instantiate(elementType, impl, shell, i);
                    AssignPort(inlet, UntypedSubscriber.FromTyped(subscriber));
                    i++;
                }

                i = 0;
                var outletsEnumerator = graph.Shape.Outlets.GetEnumerator();

                while (outletsEnumerator.MoveNext())
                {
                    var outlet      = outletsEnumerator.Current;
                    var elementType = outlet.GetType().GetGenericArguments().First();
                    var publisher   = typeof(ActorGraphInterpreter.BoundaryPublisher <>).Instantiate(elementType, impl, shell, i);
                    var message     = new ActorGraphInterpreter.ExposedPublisher(shell, i, (IActorPublisher)publisher);
                    impl.Tell(message);
                    AssignPort(outletsEnumerator.Current, (IUntypedPublisher)publisher);
                    i++;
                }
            }
Ejemplo n.º 7
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="cause">TBD</param>
 /// <param name="message">TBD</param>
 public override void AroundPreRestart(Exception cause, object message)
 {
     // some state must survive restart
     _state.Set(Self, new ActorPublisherState.State(UntypedSubscriber.FromTyped(_subscriber), _demand, _lifecycleState));
     base.AroundPreRestart(cause, message);
 }