Repository navigation
Expand file tree
/
Copy pathElection.java
More file actions
55 lines (45 loc) · 1.62 KB
/
Copy pathElection.java
File metadata and controls
55 lines (45 loc) · 1.62 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
47
48
49
50
51
52
53
54
55
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bully;
/**
*
* @author PHANUEL AYUKA
*/
import java.util.concurrent.locks.ReentrantLock;
public class Election {
public static ReentrantLock pingLock = new ReentrantLock();
public static ReentrantLock electionLock = new ReentrantLock();
private static boolean electionFlag = false; //By default no election is going on
private static boolean pingFlag = true; //By default I am allowed to ping
public static Process electionDetector;
public static Process getElectionDetector() {
return electionDetector;
}
public static void setElectionDetector(Process electionDetector) {
Election.electionDetector = electionDetector;
}
public static boolean isPingFlag() {
return pingFlag;
}
public static void setPingFlag(boolean pingFlag) {
Election.pingFlag = pingFlag;
}
public static boolean isElectionFlag() {
return electionFlag;
}
public static void setElectionFlag(boolean electionFlag) {
Election.electionFlag = electionFlag;
}
public static void initialElection(RunningThread[] t) {
Process temp = new Process(-1, -1);
for (int i = 0; i < t.length; i++) {
if (temp.getPriority() < t[i].getProcess().getPriority()) {
temp = t[i].getProcess();
}
}
t[temp.pid - 1].getProcess().CoOrdinatorFlag = true;
}
}