Exemplo n.º 1
0
            public void Handle(Message msg)
            {
                // receive message with PID: passenger ID
                // and value if passenger is missionary
                if (CONDITION_AddPassengerToBoat)
                {
                    PassengersInBoat.Add(msg);
                }
                else
                {
                    PassengerRequests.Add(msg);
                }

                // we collect passenger requests and put them into boat if there is room
            }
Exemplo n.º 2
0
        private bool ProcessPassengers()
        {
            // after 4 seconds, check if CONDITION_CrossRiver
            if (CONDITION_CrossRiver)
            {
                List <String> temp = new List <string>();
                foreach (var p in PassengersInBoat)
                {
                    temp.Add(pre + p.PID);
                }

                var tempBus = new BusBuilder()
                              .WithLogging(new ConsoleLogger())
                              .DefineErrorQueue("Boat.errors")
                              .DefineWriteQueues(temp.ToArray())
                              .CreateLocalQueuesAutomatically()
                              .JsonSerialization()
                              .CreateBus();


                // send it to all passengers in boat that crossed the river (:
                tempBus.Send(true);

                PassengersInBoat.Clear();
                // transfer passengers from waiting list to boat
                var removeList = new List <int>();
                foreach (var pr in PassengerRequests)
                {
                    if (CONDITION_AddPassengerToBoat)
                    {
                        PassengersInBoat.Add(pr);
                        removeList.Add(pr.PID);
                    }
                }
                PassengerRequests.RemoveAll(r => removeList.Any(a => a == r.PID));

                return(true); // keep going
            }

            // die
            return(false);
        }