forked from Saurabh-Bhavsar/ATCSimulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gate1.java
42 lines (40 loc) · 1.7 KB
/
Gate1.java
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
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.*;
import java.util.concurrent.locks.ReentrantLock;
public class Gate1 {
public static final ReentrantLock lockG = new ReentrantLock();
// This class is for Gate Resource 1
public void accessGate(int time) throws InterruptedException {
// The boarding/deboarding time is random for threads hence, we get this
// parameter from the runway class
int AirplaneObjectId = Integer.parseInt(Thread.currentThread().getName());
// we check which is the current running thread
Airplane workOn = Main.tracker[AirplaneObjectId];
lockG.lock();
workOn.setCurrentState(3);
// SwingUI.model.setValueAt(workOn.getCurrentStateName(workOn.getCurrentState()),
// AirplaneObjectId, 1);
SwingUI.updateGUIState(workOn.getCurrentStateName(workOn.getCurrentState()),
workOn.getCurrentStateName(workOn.getCurrentState() + 1), AirplaneObjectId);
// System.out.println("In GATE RESOURCE 1");
SwingUI.updateResourceUsedBy("G1", AirplaneObjectId);
try {
// System.out.println("G1 - " +time);
Thread.sleep(time * 1000);
} finally {
/*
* System.out.println(" IN GATE RESOURCE 1, Thread -- " + workOn.getName() +
* ", State -- " + workOn.getCurrentStateName(workOn.getCurrentState()));
*/
lockG.unlock();
SwingUI.resetResourceTable(1);
workOn.setCurrentState(4);
// SwingUI.model.setValueAt(workOn.getCurrentStateName(workOn.getCurrentState()),
// AirplaneObjectId, 1);
SwingUI.updateGUIState(workOn.getCurrentStateName(workOn.getCurrentState()),
workOn.getCurrentStateName(workOn.getCurrentState() + 1), AirplaneObjectId);
Airplane.rw.accessRunway();
}
}
}