Beispiel #1
0
 /// <summary>
 /// The function passed in may be run by pipes any number of times while resolving where a message
 /// is sent. It should also not rely on the acquisition of any other pipes.
 ///
 /// Generally, this should be a simple stateless function - for the same input it should return the same output.
 /// Try other functions at your own risk
 /// </summary>
 public TransformPipe(ISimpleInlet <TSourceMessage> inlet, ISimpleOutlet <TTargetMessage> outlet, Func <TSourceMessage, TTargetMessage> map)
     : base(new[] { inlet }, new[] { outlet })
 {
     Inlet  = inlet;
     Outlet = outlet;
     Map    = map;
 }
Beispiel #2
0
 protected TwoInletPipe(ISimpleInlet <TMessage> leftInlet, ISimpleInlet <TMessage> rightInlet, ISimpleOutlet <TMessage> outlet)
     : base(new[] { leftInlet, rightInlet }, new[] { outlet })
 {
     LeftInlet  = leftInlet;
     RightInlet = rightInlet;
     Outlet     = outlet;
 }
Beispiel #3
0
 protected TwoOutletPipe(ISimpleInlet <TMessage> inlet, ISimpleOutlet <TMessage> leftOutlet, ISimpleOutlet <TMessage> rightOutlet)
     : base(new[] { inlet }, new[] { leftOutlet, rightOutlet })
 {
     Inlet       = inlet;
     LeftOutlet  = leftOutlet;
     RightOutlet = rightOutlet;
 }
Beispiel #4
0
        public BigEitherInletPipe(IReadOnlyList <ISimpleInlet <TMessage> > inlets, ISimpleOutlet <TMessage> outlet, TTieBreaker tieBreaker)
            : base(inlets, new[] { outlet })
        {
            Inlets = inlets;
            Outlet = outlet;

            TieBreaker = tieBreaker;
        }
        public void SetUp()
        {
            workerThreads = new Thread[NumberOfWorkers];
            sharedMemory = new int[NumberOfWorkers];

            var tree = CreateBinaryTreeOfSplittingPipes(NumberOfWorkers);
            barrierInlet = tree.Item1;
            outlets = tree.Item2;

            for (var i = 0; i < NumberOfWorkers; i++)
            {
                workerThreads[i] = new Thread(CreateWorker(i));
            }
        }
        public void SetUp()
        {
            var splittingPipe = PipeBuilder.New.SplittingPipe<int>().Build();
            var eitherInletPipe = PipeBuilder.New.EitherInletPipe<Either<int, int>>().WithRandomisingTieBreaker().Build();
            var capacityPipe = PipeBuilder.New.CapacityPipe<int>().WithCapacity(1).Build();
            var leftTransformPipe = PipeBuilder.New.TransformPipe<int, Either<int, int>>().WithMap(Either<int, int>.CreateLeft).Build();
            var rightTransformPipe = PipeBuilder.New.TransformPipe<int, Either<int, int>>().WithMap(Either<int, int>.CreateRight).Build();

            capacityPipe.Outlet.ConnectTo(splittingPipe.Inlet);
            splittingPipe.RightOutlet.ConnectTo(leftTransformPipe.Inlet);
            leftTransformPipe.Outlet.ConnectTo(eitherInletPipe.LeftInlet);
            rightTransformPipe.Outlet.ConnectTo(eitherInletPipe.RightInlet);

            externalReceiverOutlet = splittingPipe.LeftOutlet;
            externalSenderInlet = rightTransformPipe.Inlet;
            prepareSendInlet = capacityPipe.Inlet;
            resultOutlet = eitherInletPipe.Outlet;
        }
Beispiel #7
0
        public void SetUp()
        {
            var splittingPipe      = PipeBuilder.New.SplittingPipe <int>().Build();
            var eitherInletPipe    = PipeBuilder.New.EitherInletPipe <Either <int, int> >().WithRandomisingTieBreaker().Build();
            var capacityPipe       = PipeBuilder.New.CapacityPipe <int>().WithCapacity(1).Build();
            var leftTransformPipe  = PipeBuilder.New.TransformPipe <int, Either <int, int> >().WithMap(Either <int, int> .CreateLeft).Build();
            var rightTransformPipe = PipeBuilder.New.TransformPipe <int, Either <int, int> >().WithMap(Either <int, int> .CreateRight).Build();

            capacityPipe.Outlet.ConnectTo(splittingPipe.Inlet);
            splittingPipe.RightOutlet.ConnectTo(leftTransformPipe.Inlet);
            leftTransformPipe.Outlet.ConnectTo(eitherInletPipe.LeftInlet);
            rightTransformPipe.Outlet.ConnectTo(eitherInletPipe.RightInlet);

            externalReceiverOutlet = splittingPipe.LeftOutlet;
            externalSenderInlet    = rightTransformPipe.Inlet;
            prepareSendInlet       = capacityPipe.Inlet;
            resultOutlet           = eitherInletPipe.Outlet;
        }
Beispiel #8
0
        public ValvedPipe(ISimpleInlet <TReceive> inlet, ISimpleOutlet <TSend> outlet, TTieBreaker tieBreaker) : base(new[] { inlet }, new[] { outlet })
        {
            Inlet      = inlet;
            Outlet     = outlet;
            TieBreaker = tieBreaker;

            var preparationCapacityPipe = PipeBuilder.New.CapacityPipe <TSend>().WithCapacity(1).Build();
            var flushEitherOutletPipe   = PipeBuilder.New.EitherOutletPipe <TSend>().Build();
            var splittingPipe           = PipeBuilder.New.SplittingPipe <TSend>().Build();
            var sendTransformPipe       = PipeBuilder.New.TransformPipe <TSend, ReceiveOrSendResult <TReceive, TSend> >().WithMap(m => ReceiveOrSendResult <TReceive, TSend> .CreateSendResult()).Build();
            var receiveTransformPipe    = PipeBuilder.New.TransformPipe <TReceive, ReceiveOrSendResult <TReceive, TSend> >().WithMap(ReceiveOrSendResult <TReceive, TSend> .CreateReceiveResult).Build();
            var eitherInletPipe         = PipeBuilder.New.EitherInletPipe <ReceiveOrSendResult <TReceive, TSend> >().WithTieBreaker(TieBreaker).Build();

            preparationCapacityPipe.Outlet.ConnectTo(flushEitherOutletPipe.Inlet);
            flushEitherOutletPipe.RightOutlet.ConnectTo(splittingPipe.Inlet);
            splittingPipe.RightOutlet.ConnectTo(sendTransformPipe.Inlet);
            sendTransformPipe.Outlet.ConnectTo(eitherInletPipe.LeftInlet);
            receiveTransformPipe.Outlet.ConnectTo(eitherInletPipe.RightInlet);

            CreateAndConnectAdapter(splittingPipe.LeftOutlet, Outlet);
            CreateAndConnectAdapter(receiveTransformPipe.Inlet, Inlet);

            Valve = new Valve <TReceive, TSend>(preparationCapacityPipe.Inlet, flushEitherOutletPipe.LeftOutlet, eitherInletPipe.Outlet);
        }
Beispiel #9
0
 public EitherInletPipe(ISimpleInlet <TMessage> leftInlet, ISimpleInlet <TMessage> rightInlet, ISimpleOutlet <TMessage> outlet, TTieBreaker tieBreaker)
     : base(leftInlet, rightInlet, outlet)
 {
     TieBreaker = tieBreaker;
 }
Beispiel #10
0
 public SplittingPipe(ISimpleInlet <TMessage> inlet, ISimpleOutlet <TMessage> leftOutlet, ISimpleOutlet <TMessage> rightOutlet)
     : base(inlet, leftOutlet, rightOutlet)
 {
 }
Beispiel #11
0
 public CapacityPipe(ISimpleInlet <TMessage> inlet, ISimpleOutlet <TMessage> outlet, int capacity)
     : base(inlet, outlet)
 {
     Capacity       = capacity;
     storedMessages = new Queue <TMessage>();
 }
Beispiel #12
0
 public DummyPipe(ISimpleInlet <int> inlet, ISimpleOutlet <string> outlet)
     : base(new [] { inlet }, new [] { outlet })
 {
     Inlet  = inlet;
     Outlet = outlet;
 }
Beispiel #13
0
 public SourcePipe(ISimpleOutlet <TMessage> outlet, Func <TMessage> messageProducer) : base(new IInlet <TMessage>[] {}, new[] { outlet })
 {
     Outlet          = outlet;
     MessageProducer = messageProducer;
 }
Beispiel #14
0
 public EitherOutletPipe(ISimpleInlet <TMessage> inlet, ISimpleOutlet <TMessage> leftOutlet, ISimpleOutlet <TMessage> rightOutlet, TTieBreaker tieBreaker)
     : base(inlet, leftOutlet, rightOutlet)
 {
     TieBreaker = tieBreaker;
 }
Beispiel #15
0
 public void SetUp()
 {
     pipe        = PipeBuilder.New.BasicPipe <int>().Build();
     simpleInlet = (SimpleInlet <int>)pipe.Inlet;
     outlet      = pipe.Outlet;
 }
Beispiel #16
0
 public BasicPipe(ISimpleInlet <TMessage> inlet, ISimpleOutlet <TMessage> outlet)
     : base(inlet, outlet)
 {
 }
Beispiel #17
0
 /// <summary>
 /// The preparation inlet must accept the message which could be sent. It should only hold one unsent message at a time.
 /// The flush outlet must output and empty the messages prepared to be sent.
 /// The result outlet should return the result - if the message was sent or if we received a message.
 /// </summary>
 public Valve(ISimpleInlet <TSend> preparationInlet, ISimpleOutlet <TSend> flushOutlet, ISimpleOutlet <ReceiveOrSendResult <TReceive, TSend> > resultOutlet)
 {
     this.preparationInlet = preparationInlet;
     this.flushOutlet      = flushOutlet;
     this.resultOutlet     = resultOutlet;
 }
Beispiel #18
0
 protected StraightPipe(ISimpleInlet <TMessage> inlet, ISimpleOutlet <TMessage> outlet)
     : base(new[] { inlet }, new[] { outlet })
 {
     Inlet  = inlet;
     Outlet = outlet;
 }
 public void SetUp()
 {
     pipe = PipeBuilder.New.BasicPipe<int>().Build();
     simpleInlet = (SimpleInlet<int>) pipe.Inlet;
     outlet = pipe.Outlet;
 }