protected Inlet<int> RightValueIs(int value) { Inlet<int> rhs = new Inlet<int>("right", mockPatchContainer, ActivationMode.ActivateOnMessage); Expect.Once.On(mockPatchContainer).Method("AddInlet").With("right").Will(Return.Value(rhs)); rhs.Value = value; return rhs; }
/// <summary> /// TBD /// </summary> /// <param name="inlet">TBD</param> /// <exception cref="ArgumentNullException"> /// This exception is thrown when the specified <paramref name="inlet"/> is undefined. /// </exception> public SinkShape(Inlet <TIn> inlet) { Inlet = inlet ?? throw new ArgumentNullException(nameof(inlet), "SinkShape expected non-null inlet"); Inlets = ImmutableArray.Create <Inlet>(inlet); }
/// <summary> /// TBD /// </summary> /// <returns>TBD</returns> public override Shape DeepCopy() => new FlowShape <TIn, TOut>((Inlet <TIn>)Inlet.CarbonCopy(), (Outlet <TOut>)Outlet.CarbonCopy());
public void Init(IPatchContainer container) { input = container.AddInlet <int>("Number"); output = container.AddOutlet <int>("Number"); }
/// <summary> /// Transform a set of GraphStageModules into a single GraphModule. This is done /// by performing a traversal of all their Inlets, sorting them into those without /// internal connections(the exposed inlets) and those with internal connections /// (where the corresponding Outlet is recorded in a map so that it will be wired /// to the same slot number in the GraphAssembly). Then all Outlets are traversed, /// completing internal connections using the aforementioned maps and appending /// the others to the list of exposed Outlets. /// </summary> private static GraphModule FuseGroup(BuildStructuralInfo info, ISet <IModule> group) { var stages = new IGraphStageWithMaterializedValue <Shape, object> [group.Count]; var materializedValueIds = new IModule[group.Count]; var attributes = new Attributes[group.Count]; /* * The overall GraphAssembly arrays are constructed in three parts: * - 1) exposed inputs (ins) * - 2) connections (ins and outs) * - 3) exposed outputs (outs) */ var insB1 = new List <Inlet>(); var insB2 = new List <Inlet>(); var outsB3 = new List <Outlet>(); var inOwnersB1 = new List <int>(); var inOwnersB2 = new List <int>(); var outOwnersB3 = new List <int>(); // for the shape of the GraphModule var inlets = ImmutableArray.CreateBuilder <Inlet>(2); var outlets = ImmutableArray.CreateBuilder <Outlet>(2); // connection slots are allocated from the inputs side, outs find their place by this map var outConns = new Dictionary <OutPort, int>(); /* * First traverse all Inlets and sort them into exposed and internal, * taking note of their partner Outlets where appropriate. */ var pos = 0; var enumerator = group.GetEnumerator(); var ups = info.Upstreams; var downs = info.Downstreams; var outGroup = info.OutGroups; while (enumerator.MoveNext()) { CopiedModule copy; GraphStageModule graphStageModule; if ((copy = enumerator.Current as CopiedModule) != null && (graphStageModule = copy.CopyOf as GraphStageModule) != null) { stages[pos] = graphStageModule.Stage; materializedValueIds[pos] = copy; attributes[pos] = copy.Attributes.And(graphStageModule.Attributes); var copyInlets = copy.Shape.Inlets.GetEnumerator(); var originalInlets = graphStageModule.Shape.Inlets.GetEnumerator(); while (copyInlets.MoveNext() && originalInlets.MoveNext()) { var copyInlet = copyInlets.Current; var originalInlet = originalInlets.Current; OutPort outport; ISet <IModule> g; var isInternal = ups.TryGetValue(copyInlet, out outport) && outGroup.TryGetValue(outport, out g) && g == group; if (isInternal) { ups.Remove(copyInlet); downs.Remove(outport); outConns[outport] = insB2.Count; insB2.Add(originalInlet); inOwnersB2.Add(pos); } else { insB1.Add(originalInlet); inOwnersB1.Add(pos); inlets.Add(copyInlet); } } } pos++; } var outsB2 = new Outlet[insB2.Count]; var outOwnersB2 = new int[insB2.Count]; /* * Then traverse all Outlets and complete connections. */ pos = 0; enumerator = group.GetEnumerator(); while (enumerator.MoveNext()) { CopiedModule copy; GraphStageModule graphStageModule; if ((copy = enumerator.Current as CopiedModule) != null && (graphStageModule = copy.CopyOf as GraphStageModule) != null) { var copyOutlets = copy.Shape.Outlets.GetEnumerator(); var originalOutlets = graphStageModule.Shape.Outlets.GetEnumerator(); while (copyOutlets.MoveNext() && originalOutlets.MoveNext()) { var copyOutlet = copyOutlets.Current; var originalOutlet = originalOutlets.Current; int idx; if (outConns.TryGetValue(copyOutlet, out idx)) { outConns.Remove(copyOutlet); outsB2[idx] = originalOutlet; outOwnersB2[idx] = pos; } else { outsB3.Add(originalOutlet); outOwnersB3.Add(pos); outlets.Add(copyOutlet); } } } pos++; } /* * Now mechanically gather together the GraphAssembly arrays from their various pieces. */ var shape = new AmorphousShape(inlets.ToImmutable(), outlets.ToImmutable()); var connStart = insB1.Count; var conns = insB2.Count; var outStart = connStart + conns; var count = outStart + outsB3.Count; var ins = new Inlet[count]; insB1.CopyTo(ins, 0); insB2.CopyTo(ins, insB1.Count); var inOwners = new int[count]; inOwnersB1.CopyTo(inOwners, 0); inOwnersB2.CopyTo(inOwners, inOwnersB1.Count); for (int i = inOwnersB1.Count + inOwnersB2.Count; i < inOwners.Length; i++) { inOwners[i] = -1; } var outs = new Outlet[count]; Array.Copy(outsB2, 0, outs, connStart, conns); outsB3.CopyTo(outs, outStart); var outOwners = new int[count]; for (int i = 0; i < connStart; i++) { outOwners[i] = -1; } Array.Copy(outOwnersB2, 0, outOwners, connStart, conns); outOwnersB3.CopyTo(outOwners, outStart); var firstModule = group.First(); var asyncAttrs = IsAsync((CopiedModule)firstModule) ? new Attributes(Attributes.AsyncBoundary.Instance) : Attributes.None; var dispatcher = GetDispatcher(firstModule); var dispatcherAttrs = dispatcher == null ? Attributes.None : new Attributes(dispatcher); var attr = asyncAttrs.And(dispatcherAttrs); return(new GraphModule(new GraphAssembly(stages, attributes, ins, inOwners, outs, outOwners), shape, attr, materializedValueIds)); }
public AssemblyBuilder Connect <T>(GraphInterpreter.UpstreamBoundaryStageLogic upstream, Inlet <T> inlet) { _upstreams.Add(new Tuple <GraphInterpreter.UpstreamBoundaryStageLogic, Inlet>(upstream, inlet)); return(this); }
public void Init(IPatchContainer container) { input = container.AddInlet<int>("Number"); output = container.AddOutlet<int>("Number"); }
/// <summary> /// TBD /// </summary> /// <typeparam name="TIn">TBD</typeparam> /// <param name="inlet">TBD</param> /// <returns>TBD</returns> public ReverseOps <TIn, T> To <TIn>(Inlet <TIn> inlet) { return(new ReverseOps <TIn, T>(this, inlet)); }
public AmqpSinkStage(IAmqpSinkSettings <T> amqpSourceSettings) { In = new Inlet <T>("AmqpSink.in"); Shape = new SinkShape <T>(In); AmqpSourceSettings = amqpSourceSettings; }
public FanOutShape(Inlet <TIn> inlet, Outlet <T0> out0, Outlet <T1> out1) : this(new InitPorts(inlet, new Outlet[] { out0, out1 })) { }
private Inlet<int> Inlet() { Inlet<int> inlet = new Inlet<int>("Number", mockPatchContainer, ActivationMode.ActivateOnChange); Expect.Once.On(mockPatchContainer).Method("AddInlet").With("Number").Will(Return.Value(inlet)); return inlet; }
protected Inlet<string> ExpectInletToBeConnectedWith(string name, string value) { Inlet<string> inlet = new Inlet<string>("Arguments", mockPatchContainer, ActivationMode.ActivateOnMessage); Expect.Once.On(mockPatchContainer).Method("AddInlet").With(name).Will(Return.Value(inlet)); inlet.Value = value; return inlet; }
/// <summary> /// TBD /// </summary> /// <typeparam name="TIn">TBD</typeparam> /// <typeparam name="TOut">TBD</typeparam> /// <typeparam name="TMat">TBD</typeparam> /// <param name="ops">TBD</param> /// <param name="inlet">TBD</param> /// <returns>TBD</returns> public static GraphDsl.Builder <TMat> To <TIn, TOut, TMat>(this GraphDsl.ForwardOps <TOut, TMat> ops, Inlet <TIn> inlet) where TIn : TOut { ops.Builder.AddEdge(ops.Out, inlet); return(ops.Builder); }
/// <summary> /// TBD /// </summary> /// <typeparam name="T1">TBD</typeparam> /// <typeparam name="T2">TBD</typeparam> /// <param name="from">TBD</param> /// <param name="to">TBD</param> internal void AddEdge <T1, T2>(Outlet <T1> from, Inlet <T2> to) where T2 : T1 { _moduleInProgress = _moduleInProgress.Wire(from, to); }
/// <summary> /// TBD /// </summary> /// <param name="builder">TBD</param> /// <param name="inlet">TBD</param> public ReverseOps(Builder <TMat> builder, Inlet <TIn> inlet) { Builder = builder; In = inlet; }
/// <summary> /// TBD /// </summary> /// <returns>TBD</returns> public override IModule CarbonCopy() => NewInstance(new SinkShape <TIn>(Inlet.Create <TIn>(_shape.Inlet.CarbonCopy())));
/// <summary> /// TBD /// </summary> /// <typeparam name="TIn2">TBD</typeparam> /// <typeparam name="TOut2">TBD</typeparam> /// <typeparam name="TMat2">TBD</typeparam> /// <typeparam name="TMatRes">TBD</typeparam> /// <param name="bidi">TBD</param> /// <param name="combine">TBD</param> /// <returns>TBD</returns> public Flow <TIn2, TOut2, TMatRes> JoinMaterialized <TIn2, TOut2, TMat2, TMatRes>(IGraph <BidiShape <TOut, TOut2, TIn2, TIn>, TMat2> bidi, Func <TMat, TMat2, TMatRes> combine) { var copy = bidi.Module.CarbonCopy(); var ins = copy.Shape.Inlets.ToArray(); var outs = copy.Shape.Outlets.ToArray(); return(new Flow <TIn2, TOut2, TMatRes>(Module.Compose(copy, combine) .Wire(Shape.Outlet, ins[0]) .Wire(outs[1], Shape.Inlet) .ReplaceShape(new FlowShape <TIn2, TOut2>(Inlet.Create <TIn2>(ins[1]), Outlet.Create <TOut2>(outs[0]))))); }
public TcpStreamLogic(FlowShape <ByteString, ByteString> shape, ITcpRole role, EndPoint remoteAddress) : base(shape) { _role = role; _remoteAddress = remoteAddress; _bytesIn = shape.Inlet; _bytesOut = shape.Outlet; _readHandler = new LambdaOutHandler( onPull: () => _connection.Tell(Tcp.ResumeReading.Instance, StageActorRef), onDownstreamFinish: () => { if (!IsClosed(_bytesIn)) { _connection.Tell(Tcp.ResumeReading.Instance, StageActorRef); } else { _connection.Tell(Tcp.Abort.Instance, StageActorRef); CompleteStage(); } }); // No reading until role have been decided SetHandler(_bytesOut, onPull: DoNothing); SetHandler(_bytesIn, onPush: () => { var elem = Grab(_bytesIn); ReactiveStreamsCompliance.RequireNonNullElement(elem); _connection.Tell(Tcp.Write.Create(elem, WriteAck.Instance), StageActorRef); }, onUpstreamFinish: () => { // Reading has stopped before, either because of cancel, or PeerClosed, so just Close now // (or half-close is turned off) if (IsClosed(_bytesOut) || !_role.HalfClose) { _connection.Tell(Tcp.Close.Instance, StageActorRef); } // We still read, so we only close the write side else if (_connection != null) { _connection.Tell(Tcp.ConfirmedClose.Instance, StageActorRef); } else { CompleteStage(); } }, onUpstreamFailure: ex => { if (_connection != null) { if (Interpreter.Log.IsDebugEnabled) { Interpreter.Log.Debug( $"Aborting tcp connection to {_remoteAddress} because of upstream failure: {ex.Message}\n{ex.StackTrace}"); } _connection.Tell(Tcp.Abort.Instance, StageActorRef); } else { FailStage(ex); } }); }
public void Init(IPatchContainer container) { left = container.AddInlet<int> ("left"); right = container.AddInlet<int> ("right"); result = container.AddOutlet<int> ("result"); }
public void Init(IPatchContainer container) { input = container.AddInlet<int>("InPort"); }
public void Init(IPatchContainer container) { left = container.AddInlet <int> ("left"); right = container.AddInlet <int> ("right"); result = container.AddOutlet <int> ("result"); }
public AssemblyBuilder Connect <T>(Outlet <T> outlet, Inlet <T> inlet) { _connections.Add(new Tuple <Outlet, Inlet>(outlet, inlet)); return(this); }