Ejemplo n.º 1
0
        public static void hotelSupplierFunc()
        {
            /*************************
            *
            * changed function so that it only continues if there has been 10 or less price cuts
            *
            * ***********************/

            while (p <= 10)
            {
                lock (lock2)
                {
                    Thread.Sleep(500);

                    Int32 newPrice = rng.Next(30, 100);


                    // Take the order from the queue of the orders;


                    // Decide the price based on the orders

                    // Console.WriteLine("New Price is {0}", p);

                    HotelSupplier.pricingModel(newPrice);
                }
                if (!Program.mb.isEmpty())
                {
                    readFromBuffer();
                }
            }
        }
Ejemplo n.º 2
0
        /*
         * TravelAgency1 through TravelAgencyN, each travel agency is a thread
         * instantiated from the same class (or the same method) in a class.
         * The travel agency’s actions are event-driven. Each travel agency
         * contains a call-back method (event handler) for the HotelSuppliers
         * to call when a price-cut event occurs. The travel agency will
         * calculate the number of rooms to order, for example, based on the
         * need and the difference between the previous price and the current
         * price. The thread will terminate after the HotelSupplier thread has
         * terminated. Each order is an OrderClass object. The object is sent
         * to the Encoder for encoding. The encoded string is sent back to the
         * travel agency. Then, the travel agency will send the order in String
         * format to the MultiCellBuffer. Before sending the order to the
         * MultiCellBuffer, a time stamp must be saved. When the confirmation of
         * order completion is received, the time of the order will be calculated
         * and saved (or printed). You can set N = 5 in your implementation.
         */


        /*********************************
         *
         * This thread uses the agency thread(s) while the function below this
         * one uses the hotel thread(s) this is a problem for output
         *
         **********************************/
        public static void travelAgencyFunc()
        {
            //Console.WriteLine("agency thread started");
            HotelSupplier hotel = new HotelSupplier();

            /****************************
             *
             * Below lines keep track of when the hotelSupplier threads finish
             * Once it finishes the travelAgency threads should finish too
             *
             *****************************/
            int priceCuts = hotel.getPriceCuts();

            while (priceCuts < 10)
            //for (Int32 i = 0; i < 10; i++)
            {
                //CALLS FUNCTION TO ADD ORDER OBJECTS TO BUFFER
                //addtoBuffer();

                Thread.Sleep(1000);

                Int32 price = hotel.getPrice();

                Console.WriteLine("{0} has everyday low price: ${1} each", Thread.CurrentThread.Name, price); // Thread.CurrentThread.Name prints thread name
                priceCuts = hotel.getPriceCuts();
            }
        }