-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrinter.java
More file actions
46 lines (38 loc) · 1.42 KB
/
Printer.java
File metadata and controls
46 lines (38 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
public class Printer extends Thread {
private final SharedQueue sharedQueue;
private int PrinterID;
public Printer(SharedQueue sharedQueue, int ID) {
this.sharedQueue = sharedQueue;
this.PrinterID = ID;
}
public int GetID() {
return PrinterID;
}
public static void checkType(String type) throws TypeNotSupportedException {
if (type.equalsIgnoreCase("pdf"))
return;
throw new TypeNotSupportedException("This file is not support");
}
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try {
PrintJob job = sharedQueue.dequeue(this.PrinterID);
try {
checkType(job.getFileType());
Thread.sleep(2000);
System.out.println("printer " + this.GetID() + " ---> Processing ---> " + job.getJobId());
} catch (TypeNotSupportedException e) {
System.out.println(e);
System.out.println("!!!!" + job.getJobId() + " file is not supported " + "!!!!");
System.out.println();
} catch (Exception ex) {
ex.printStackTrace();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt(); // Properly handle interruption
break;
}
}
}
}