Exemple #1
0
        public static void Main()
        {
            Console.WriteLine("Subscribing to " + Channel + " on stream Id " + StreamID);

            var ctx = new Aeron.Context()
                      .AvailableImageHandler(SamplesUtil.PrintUnavailableImage)
                      .UnavailableImageHandler(SamplesUtil.PrintUnavailableImage);

            var reporter          = new RateReporter(1000, SamplesUtil.PrintRate);
            var fragmentAssembler = new FragmentAssembler(SamplesUtil.RateReporterHandler(reporter));
            var running           = new AtomicBoolean(true);

            var t      = new Thread(subscription => SamplesUtil.SubscriberLoop(fragmentAssembler.OnFragment, FragmentCountLimit, running)((Subscription)subscription));
            var report = new Thread(reporter.Run);

            using (var aeron = Aeron.Connect(ctx))
                using (var subscription = aeron.AddSubscription(Channel, StreamID))
                {
                    t.Start(subscription);
                    report.Start();

                    Console.ReadLine();
                    Console.WriteLine("Shutting down...");
                    running.Set(false);
                    reporter.Halt();

                    t.Join();
                    report.Join();
                }
        }
Exemple #2
0
 static void Main(string[] args)
 {
     SamplesUtil.InvokeMain(() =>
     {
         var sample = new StorageSample();
         sample.MainFunction(args);
     });
 }
        public static void Main()
        {
            ComputerSpecifications.Dump();


            var reporter            = new RateReporter(1000, PrintRate);
            var rateReporterHandler = SamplesUtil.RateReporterHandler(reporter);
            var context             = new Aeron.Context();

            var running = new AtomicBoolean(true);

            var reportThread    = new Thread(reporter.Run);
            var subscribeThread = new Thread(subscription => SamplesUtil.SubscriberLoop(rateReporterHandler, FragmentCountLimit, running)((Subscription)subscription));

            using (var aeron = Aeron.Connect(context))
                using (var publication = aeron.AddPublication(Channel, StreamID))
                    using (var subscription = aeron.AddSubscription(Channel, StreamID))
                        using (var byteBuffer = BufferUtil.AllocateDirectAligned(MessageLength, BitUtil.CACHE_LINE_LENGTH))
                            using (var buffer = new UnsafeBuffer(byteBuffer))
                            {
                                reportThread.Start();
                                subscribeThread.Start(subscription);

                                do
                                {
                                    Console.WriteLine("Streaming {0:G} messages of size {1:G} bytes to {2} on stream Id {3}", NumberOfMessages, MessageLength, Channel, StreamID);

                                    _printingActive = true;

                                    long backPressureCount = 0;
                                    for (long i = 0; i < NumberOfMessages; i++)
                                    {
                                        buffer.PutLong(0, i);

                                        OfferIdleStrategy.Reset();
                                        while (publication.Offer(buffer, 0, buffer.Capacity) < 0)
                                        {
                                            OfferIdleStrategy.Idle();
                                            backPressureCount++;
                                        }
                                    }

                                    Console.WriteLine("Done streaming. backPressureRatio=" + (double)backPressureCount / NumberOfMessages);

                                    if (0 < LingerTimeoutMs)
                                    {
                                        Console.WriteLine("Lingering for " + LingerTimeoutMs + " milliseconds...");
                                        Thread.Sleep((int)LingerTimeoutMs);
                                    }

                                    _printingActive = false;
                                } while (Console.ReadLine() != "x");

                                reporter.Halt();
                                running.Set(false);

                                if (!subscribeThread.Join(5000))
                                {
                                    Console.WriteLine("Warning: not all tasks completed promptly");
                                }
                            }
        }