// @topic T11808 Multithreading -- Order Queue demo
// @brief class OrderHandler extends Thread

package pckg;

public class OrderHandler extends Thread {
    private OrderQueue orderQueue;

    // constructors
    public OrderHandler( OrderQueue orderQueue )
    {
        this.orderQueue = orderQueue;
    }

    // operations
    @Override
    /**Worker thread task: retrieve and process orders from the queue*/
    public void run()
    {
        Order order;
        // The worker thread runs forever:
        while ( true )
        {
           // get next available order
            order = orderQueue.pullOrder();

            System.out.println(
                "                              " + 
                order.toString() + 
                " processed by " + this.getName()
                );
            try
            {
                Thread.sleep( 2000 );  // delay two seconds
            }
            catch ( InterruptedException ex )
            {
                // ignore interruptions
            }
        }
    }
}//class OrderHandler