Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

1. IntroductionThe coursework requires you to develop an FSP program to model a system of severalstudents that share a printer to print documents and two

1. IntroductionThe coursework requires you to develop an FSP program to model a system of severalstudents that share a printer to print documents and two technicians. One technician refillsthe paper when it has run out and one technician replaces the toner cartridge when it runsout. In addition, produce a Java implementation of the printing system, using the appropriateJava concurrency features: threads, thread groups and a monitor.The coursework is in three parts:1. Develop FSP processes to model the shared printer.2. This abstract FSP program is then to be translated into a multi-threaded Javaprogram, using appropriate Java concurrency features. The Java program is to bebased on the FSP model of the printing system. You are required to develop Javaclasses to model the FSP processes and the complete system defined in part 1.3. Provide screen shots of the FSP model in the LTSA tool & an example of a sampleoutput from the Java program.Both the FSP and Java programs should conform to the general guidelines given in: FSPProgramming Criteria, Java Programming Criteria and the general style used for both in theLecture notes and example programs.NOTE: that you must use the Java monitor feature. DO NOT USE semaphores,the synchronize statement or some other Java synchronisation mechanism.2. Detailed Description of Coursework Components2.1 FSP Design & ModelYou are required to develop three types of FSP processes to model the following: Printer,Student & Technician.And a parallel composite process to model the complete system.This is to be done by using the: FSP Process Composition Analysis & Design Form for the FSP processcomposition of the complete parallel system. The system should be developed incrementally using the LTSA tool.NOTE: Due to the limits on the number of FSM states that the LTSA tool can draw(approximately 64), the numbers used in the processes below needs to be very small if theFSM diagrams are to be drawn, e.g. in the range 1 to 3.2.1.1 Description of Individual ProcessesThe requirements & design of the individual FSP processes is as follows:(a) Printer ProcessThe maximum number of sheets of paper the printer can contain, is 3. All documents takejust one sheet of paper to print. Its behaviour is as follows:1. It is initialized with 3 sheets of paper.2. Provided the printer has at least one sheet of paper left, it can be used to print adocument.3. To print a document:(i) a user must take mutually exclusive control of the printer,(ii) the document is then printed,(iii) the user releases mutually exclusive control of the printer,(iv) the number of sheets of paper in the printer is reduced by 1 & theprinter is then ready to print another document.4. When the printer has run out of paper, a user cannot use it to print a document.5. When the printer has run out of paper, the technician can then refill it with themaximum amount of paper, i.e. 3 sheets.The printer must not suffer from "data corruption & interference". That is each user musthave mutually exclusive access to the printer while it is being used and it must keep acorrect count of the sheets of paper.(b) Student ProcessAll of the documents the student wants to print, are short & take only one sheet of paper toprint. A student's behaviour is as follows:1. It is initialized with the number of documents it is to print.2. For each document:(i) it takes mutually exclusive control of the printer,(ii) prints the document &(iii) then releases control of the printer.3. When it has finished printing all its documents it terminates.(c) Technician ProcessIts behaviour is as follows:1. Repeatedly, check if the printer is out of paper.2. When the printer is out of paper, it refills the printer with the maximum number ofsheets it can take, i.e. 3.(d) Printing SystemThis combines instances of the above processes in parallel. It must ensure mutualexclusive access is maintained for use of the printer.This combines the following four processes in parallel: One student process that is to print 3 documents. One student process that is to print 2 documents. One technician process that refills the printer with 3 sheets of paper. One printer process that can hold up to 3 sheets of paper.2.2 Java Implementation of the FSP ModelA version of the FSP printing system model as a multi-threaded concurrent Java program,using the appropriate Java concurrency features, e.g. threads, thread groups, monitors. ThePrinting System's Java classes should implement the behaviour of the equivalent FSPprocess.The Java implementation of the system consists of: a shared printer, four students who share it and two technicians who service it.The students each use the printer to print several documentsEach technician only does one job, i.e. one only refills the paper tray & the other onlyreplaces the toner cartridge.You will need to develop Java classes to model: the printer, a student, a paper technician, atoner technician and the whole system.You must use the following Java class and interfaces: Document class: this defines the "document" that students send to the printer. Printer class: this defines the interface to the shared printer for the students. ServicePrinter interface: this defines the interface to the shared printer forthe two technicians.You must then develop the following Java classes.2.2.1 Description of Individual Java ComponentsThe requirements & design of the Java classes is as following:1. A Shared Laser Printer classDefine a class to model a shared printer, called LaserPrinter. Note that this class is a"monitor", NOT a thread.The LaserPrinter class must: Implement the ServicePrinter interface.This interface defines the complete interface to the printer for both students andtechnicians. Use the Document class.Instances of this class are used to represent a "document" that students request theprinter to be printed. Have private data members that hold the information associated with the printer, i.e.the printer's name/id, the current paper level, the current toner level and the numberof documents printed. A single constructor that initializes the printer. A toString() method that returns a String representation of the current state of theprinter. For example:[ PrinterID: lp-CG.24, Paper Level: 35, Toner Level: 310, Documents Printed: 4 ]LaserPrinter BehaviourAn instance of the LaserPrinter class, i.e. a printer, should: Allow students to print "documents" using the printDocument( document)method, provided it has sufficient quantities of paper and toner to be able to print thedocument.Assume that to print one page of a document you need 1 sheet of paper and 1 unit oftoner.Example: the printer can print a 10 page document provided both the paper andtoner are greater than 10; and that printing this document reduces each by 10.If either the paper or toner (or both) are less than 10 then the document cannot beprinted and printing must wait until there is enough of both to print it. Allow the paper technician to refill the paper tray using the refillPaper( )method.Assume there are 50 sheets per pack of paper & the printer can hold up to 250sheets of paper.Example: the printer has 150 sheets of paper, therefore, it can be refilled.But if it has 201 sheets of paper, then it cannot be refilled , as it would result in 251sheets, and the technician should wait. But he or she is only prepared to wait for 5seconds before checking if it can be refilled it again. Allow the toner technician to replace the toner cartridge using thereplaceTonerCartridge( ) method, provided it needs to be replaced, i.e. has atoner level of less than 10. Assume a toner cartridge can print 500 sheets of paper.Example: the printer has a toner level of 9, therefore, the toner cartridge can bereplaced.But if it has a level of 10, then it cannot be replaced, as it would be a waste of toner,and the technician should wait. But he or she is only prepared to wait for 5 secondsbefore checking if it can be replaced it again. The printer status must be a correct record of its available resources and printinghistory & must not suffer from "data corruption & interference". Each user must have "mutual exclusive" access to the printer while he/she operateson it. Allow any user of the printer, including itself, to call the toString( ) method, toget a String representation of its status.2. Student classDefine a class to represent a student that can print several documents called Student.Note that this class is a thread.The Student class must: Use the Document class.Instances of this class are used to represent a "document" that students request theprinter to be printed.To create five instances of this class to represent five "documents" that the studentrequest the printer to print.For example, Joe Bloggs wants to print his 20 page CWK2 document then he woulddo the following:Document CWK2 = new Document( "JoeBloggs", "cwk2", 20 );printer.printDocument( CWK2 ) ; Have private data members that hold the information associated with him/her, i.e. thethread group he/she is in; his/her printer; his/her name. A single constructor that initializes his/her information, including placing the studentin the "student" thread group.Student's behaviour is to: Create and print five documents with different lengths and names. He/she should "sleep" for a random amount of time between each printing request. When he/she has finished printing, print out a message, e.g.Joe Bloggs Finished Printing: 5 Documents, 95 pages3. Paper Technician classDefine a class to represent a paper technician that can refill the printer's paper trays, calledPaperTechnician. Note that this class is a thread.The PaperTechnician class must: Have private data members that hold the information associated with him/her, i.e. thethread group he/she is in; his/her printer; his/her name. A single constructor that initializes his/her information, including placing thetechnician in the "technician" thread group.Paper Technician's behaviour is to: Attempt to refill the printer's paper trays three times, using the printer'srefillPaper() method. He/she should "sleep" for a random amount of time between each attempt to refill thepaper. When he/she has finished trying to refill the paper, print out a message, stating it hasfinished and how many packs of paer it refilled the printer with, e.g.Paper Technician Finished, packs of paper used: 24. Toner Technician classDefine a class to represent a technician that replaces the printer's toner cartridge, calledTonerTechnician.This class is very similar to the paper technician class, except it attempts to replace thetoner three times, using the printer's replaceTonerCartridge( ) method. When he/shehas finished trying to replace the toner cartridge, print out a message, stating it has finishedand how many toner cartridges it replaced, e.g.Toner Technician Finished, cartridges replaced: 25. Printing System classDefine a class to represent the Printing System of all the clients of the printing system,called PrintingSystem. It is the "main" program class for the system & it combines all ofthe above objects & threads in parallel, see Figure 1. Note that this class is not a thread.The PrintingSystem class creates and coordinates the following objects, threads andthread groups: One instance of the LaserPrinter class.This printer object is to be shared by the students & the two technicians. Creates 2 thread groups: one for the 4 students & one for the 2 technicians. Four instance of the Student class, i.e. four different students threads. An instance of the PaperTechnician class. An instance of the TonerTechnician class. Each of the above students and technicians is passed the appropriate information viaits constructor and started, i.e 6 threads in all. The main program waits until all 6 threads have terminated. At which point it printsout the final status of the printer. In addition it must print out reports of what it is doing and when it has finishedcreating the threads and other objects, etc.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions