62 lines
1.3 KiB
Java
62 lines
1.3 KiB
Java
public class P2_PrinterHead{
|
|
|
|
private char mode = 'M';
|
|
private boolean inUse=false;
|
|
private String jobId;
|
|
private int timeRemaining = 0;
|
|
|
|
public P2_PrinterHead()
|
|
{
|
|
//Nothing to set up.
|
|
}
|
|
|
|
public synchronized int print(P2_Jobs jobInput, int[] time)
|
|
{
|
|
//Set the details of the current job
|
|
jobId = jobInput.getId();
|
|
mode = jobInput.getJobType();
|
|
inUse = true;
|
|
timeRemaining = jobInput.getPages();
|
|
int startTime = time[0];
|
|
|
|
//Wait (and delay the thread) one second per page of the job
|
|
for(int i = 0; i<jobInput.getPages(); i++)
|
|
{
|
|
try
|
|
{
|
|
Thread.sleep(1000);
|
|
timeRemaining--;
|
|
time[0]++;
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
//Don't actually care
|
|
}
|
|
}
|
|
|
|
//Head is now available for another activity
|
|
inUse = false;
|
|
return startTime;
|
|
}
|
|
|
|
//Getters
|
|
public String getJobId()
|
|
{
|
|
return jobId;
|
|
}
|
|
|
|
public boolean getInUse()
|
|
{
|
|
return inUse;
|
|
}
|
|
|
|
public char getMode()
|
|
{
|
|
return mode;
|
|
}
|
|
|
|
public int getTimeRemaining()
|
|
{
|
|
return timeRemaining;
|
|
}
|
|
} |