$29
Objectives: To practice programming an application with multiple threads of execution and synchronizing their access to necessary shared objects.
Description: In this programming assignment you will simulate the package shipping management system for an automated package shipping operation similar to the one depicted here:
conveyor 4 conveyor 0
S0
S4
S1
You have been hired to design a simulator for a new package management system being built with the same design, but possibly fewer/more stations. You are to implement this simulator in Java and have each routing station function in its own thread. A routing station moves packages from one of its connected conveyors to the other. A station’s workload is the number of times that a routing
Page 1
station needs to have exclusive access to the input and output conveyors during the simulation. Once a routing station is granted access to both conveyors it calls its doWork()method during which it will flow packages down each of its connected conveyors (of course it must verify that it has access and isn’t in conflict with another routing station). After the packages-in and packages-out methods are run, the workload of the routing station is reduced by 1 and the routing station will release both of the conveyors and signal waiting routing stations that the conveyors are available. After executing a flow and releasing its conveyors, a routing station should sleep for some random period of time. A routing station’s thread stops running when its workload reaches 0. To prevent deadlock, ensure that each routing station acquires locks on the conveyors it needs in increasing numerical order.
Restrictions:
/*
Class: <name of class goes here>
*/
Input Specification:
Your program must initially read from a text file (config.txt) to gather configuration information for the simulator. The first line of the text file will be the number of routing stations to use during the simulation. Afterwards, there will be one line for each station. These lines will hold the amount of work each station needs to process (i.e, the number of times it needs to move packages down the conveyor system). Only use integers in your configuration file, decimals will not be needed. You can assume that the maximum number of stations will be 10.
Output Specification:
Your simulator must output the following text to let the user know what the simulator is doing in each of these situations:
Routing Station X: input connection is set to conveyor number n
Routing Station X: output connection is set to conveyor number n
Routing Station X: Workload set. Station X has a total of n package groups to move.
Station X: holds lock on input conveyor n
Station X: holds lock on output conveyor n
Station X: unlocks input conveyor n
Station X: unable to lock output conveyor – releasing lock on input conveyor n.
Station X: unlocks output conveyor n
Station X: successfully moves packages into station on input conveyor n.
Station X: successfully moves packages out of station on output conveyor n.
Station X: has n package groups left to move.
Deliverables:
Submit the following items via