Ejemplo n.º 1
0
 public static IHostBuilder CreateHostBuilder(string[] args, Queues queues) =>
 Host.CreateDefaultBuilder(args)
 .ConfigureServices(services =>
 {
     services.AddSingleton(queues);
 })
 .ConfigureWebHostDefaults(webBuilder =>
 {
     webBuilder
     .UseStartup <Startup>()
     .UseUrls("http://localhost:5001/");
 });
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            var valueProposer = new Func <string>(() => new Random().Next(2).ToString());

            var queues = new Queues();

            var proposerNames = new[] { "proposer1" }.ToList();
            var learnerNames = new[] { "learner1" }.ToList();
            var acceptorNames = Enumerable.Range(0, 3).Select(i => $"acceptor{i}").ToList();

            foreach (var name in proposerNames)
            {
                var queue = new ConcurrentQueue <Promised>();
                queues.ProposerQueues[name] = queue;
                // ReSharper disable once ImplicitlyCapturedClosure
                Task.Run(() => RunTaskAfterDelay(new Proposer(name, acceptorNames, queue, valueProposer)));
            }

            foreach (var name in learnerNames)
            {
                var queue = new ConcurrentQueue <Accepted>();
                queues.LearnerQueues[name] = queue;
                Task.Run(() => RunTaskAfterDelay(new Learner(name, queue)));
            }

            foreach (var name in acceptorNames)
            {
                var queue = new ConcurrentQueue <AcceptorReceived>();
                queues.AcceptorQueues[name] = queue;
                // ReSharper disable once ImplicitlyCapturedClosure
                Task.Run(() => RunTaskAfterDelay(new Acceptor(name, learnerNames, queue)));
            }

            // ReSharper disable once ImplicitlyCapturedClosure
            Task.Run(() => RunTaskAfterDelay(new Nag(proposerNames, acceptorNames)));

            CreateHostBuilder(args, queues).Build().Run();
        }
Ejemplo n.º 3
0
 public MessageReceiver(Queues queues)
 {
     _queues = queues;
 }