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);
            }
Exemple #2
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 connections = t.Item1;
                var logics      = t.Item2;

                var shell = new GraphInterpreterShell(graph.Assembly, connections, 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++;
                }
            }