1. Description of Individual Processes

The requirements & design of the individual FSP processes is as follows:

(a)Printer Process

The maximum number of sheets of paper the printer can contain, is 3. All documents take just 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 a document.

3.To print a document:

1.a user must take mutually exclusive control of the printer,
2.the document is then printed,
3.the user releases mutually exclusive control of the printer,
4.the number of sheets of paper in the printer is reduced by 1 & the printer is then ready to print another document.

4.When the printer has run out of paper, a user can not use it to print a document.

5.When the printer has run out of paper, the technician can then refill it with the maximum amount of paper, i.e. 3 sheets.

The printer must not suffer from "data corruption & interference". That is each user must have mutually exclusive access to the printer while it is being used.

(b)Student Process

All of the documents the student wants to print, are short & take only one sheet of paper to print. A student's behaviour is as follows:

1.It is initialized with the number of documents it is to print.

2.For each document:

1.it takes mutually exclusive control of the printer,
2.prints the document &
3.then releases control of the printer.

3.When it has finished printing all its documents it terminates.

(c)Technician Process

Its 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 of sheets it can take, i.e. 3.

(d)Printing System

This combines instances of the above processes in parallel. It must ensure mutual exclusive 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 Model

A 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. The Printing System's Java classes should implement the behaviour of the equivalent FSP process.

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 documents

Each technician only does one job, i.e. one only refills the paper tray & the other only replaces the toner cartridge.

You will need to develop Java classes to model: the printer, a student, a paper technician, a toner 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 for the two technicians.

You must then develop the following Java classes.

2.2.1 Description of Individual Java Components

The requirements & design of the Java classes is as following:

1. A Shared Laser Printer class

Define 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 and technicians.

Use the Document class. Instances of this class are used to represent a "document" that students request the printer 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 number of documents printed.

A single constructor that initializes the printer.

A toString() method that returns a String representation of the current state of the printer. For example: [ PrinterID: lp-CG.24, Paper Level: 35, Toner Level: 310, Documents Printed: 4 ]

LaserPrinter Behaviour

An 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 the document.

Assume that to print one page of a document you need 1 sheet of paper and 1 unit of toner.

Example: the printer can print a 10 page document provided both the paper and toner 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 be printed 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 250 sheets 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 251 sheets, and the technician should wait. But he or she is only prepared to wait for 5 seconds before checking if it can be refilled it again.

Allow the toner technician to replace the toner cartridge using the replaceTonerCartridge( ) method, provided it needs to be replaced, i.e. has a toner 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 be replaced.

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 seconds before checking if it can be replaced it again.

The printer status must be a correct record of its available resources and printing history & must not suffer from "data corruption & interference".

Each user must have "mutual exclusive" access to the printer while he/she operates on it.

Allow any user of the printer, including itself, to call the toString( ) method, to get a String representation of its status.

2.Student class

Define 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 the printer to be printed.

To create five instances of this class to represent five "documents" that the student request the printer to print.

For example, Joe Bloggs wants to print his 20 page CWK2 document then he would do 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. the thread group he/she is in; his/her printer; his/her name.

A single constructor that initializes his/her information, including placing the student in 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.

3.Paper Technician class

Define a class to represent a paper technician that can refill the printer's paper trays, called PaperTechnician. 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. the thread group he/she is in; his/her printer; his/her name.

A single constructor that initializes his/her information, including placing the technician in the "technician" thread group.

Paper Technician's behaviour is to:

Attempt to refill the printer's paper trays three times, using the printer's refillPaper( ) method.

He/she should "sleep" for a random amount of time between each attempt to refill the paper.

When he/she has finished trying to refill the paper, print out a message.

4.Toner Technician class

Define a class to represent a technician that replaces the printer's toner cartridge, called TonerTechnician.

This class is very similar to the paper technician class, except it attempts to replace the toner three times, using the printer's replaceTonerCartridge( ) method.

5. Printing System class

Define 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 of the above objects & threads in parallel. Note that this class is not a thread.

The PrintingSystem class creates and coordinates the following objects, threads and thread 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 students & one for the 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 via its constructor and started.

The main program waits until all 6 threads have terminated. At which point it prints out the final status of the printer.

In addition it must print out reports of what it is doing and when it has finished creating the threads and other objects, etc.

Printint System: see image.

Java Interface.

Document.java

class Document
{
private final String userID ;
private final String documentName ;
private final int numberOfPages ;


public Document( String UID, String name, int length )
{
this.userID = UID ;
this.documentName = name ;
this.numberOfPages = length ;
}


public String getUserID( ) { return userID ; }

public String getDocumentName( ) { return documentName ; }

public int getNumberOfPages( ) { return numberOfPages ; }


public String toString( )
{
return new String( "Document[ " +
"UserID: " + userID + ", " +
"Name: " + documentName + ", " +
"Pages: " + numberOfPages +
"]" ) ;
}

} // Document

Printer.java

public interface Printer
{

// print the "document"
public void printDocument( Document document ) ;

} // Printer

ServicePrinter.java

public interface ServicePrinter extends Printer
{

// from Printer:
// public void printDocument( Document document ) ;

// Printer constants

public final int Full_Paper_Tray = 250 ;
public final int Full_Toner_Level = 500 ;

public final int Minimum_Toner_Level = 10 ;

public final int SheetsPerPack = 50 ;

public final int PagesPerTonerCartridge = 500 ;


// Technician methods

public void replaceTonerCartridge( ) ;

public void refillPaper( ) ;

} // ServicePrinter
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.