This repository has been archived by the owner on May 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetectConcurrency.java
92 lines (85 loc) · 3.72 KB
/
DetectConcurrency.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import java.util.ArrayList;
/**
* Created by Erfan Rahnemoon on 6/26/17.
*
* detect concurrency Exactly in the same form and algorithm that the book
* (Database System Concepts by Avi Silberschatz, Henry F. Korth, and
* S. Sudarshan) explains with no Optimization.
*/
public class DetectConcurrency {
ArrayList<String> listOfAction ;
int numberOfTransaction;
int [][] matrixDetectConcurrency ;
String [][] transactionTable;
private static boolean isConcurrent = true;
public DetectConcurrency (ArrayList listOfAction, int numberOfTransaction) {
this.listOfAction = listOfAction;
this.numberOfTransaction = numberOfTransaction;
matrixDetectConcurrency = new int [numberOfTransaction][numberOfTransaction];
transactionTable = new String[listOfAction.size()][numberOfTransaction];
createTableTransaction(listOfAction);
findloop(matrixDetectConcurrency);
}
private void createTableTransaction(ArrayList list) {
for(int i=0; i<numberOfTransaction;i++){
for (int j=0;j<listOfAction.size();j++) {
transactionTable[j][i] = "null";
}
}
for(int i=0; i<numberOfTransaction;i++){
for (int j=0;j<listOfAction.size();j++) {
if(listOfAction.get(j).toUpperCase().contains("T"+(i+1))){
transactionTable[j][i] = listOfAction.get(j).split(":")[1].toUpperCase();
}
}
}
for(int i=0; i<transactionTable.length;i++){
for (int j=0;j<transactionTable[0].length;j++) {
if (!transactionTable [i][j].equals("null")) {
findVortex(transactionTable[i][j],j,i);
}
}
}
}
private void findVortex(String regex,int indexTransaction,int lineOfPlan) {
if (regex.contains("R") || regex.contains("LOCK_S")) {
for (int i = lineOfPlan; i < transactionTable.length; i++) {
for (int j = 0; j < transactionTable[0].length; j++) {
if (!transactionTable[i][j].equals("null") && (transactionTable[i][j].equals(regex.replace("R","W")) ||
transactionTable[i][j].equals(regex.replace("LOCK_S","LOCK_X")))) {
matrixDetectConcurrency[indexTransaction][j] = 1;
}
}
}
}else if(regex.contains("W") || regex.contains("LOCK_X")){
for (int i = lineOfPlan; i < transactionTable.length; i++) {
for (int j = 0; j < transactionTable[0].length; j++) {
if (!transactionTable[i][j].equals("null") && transactionTable[i][j].equals(regex)) {
matrixDetectConcurrency[indexTransaction][j] = 1;
}else if (!transactionTable[i][j].equals("null") && (transactionTable[i][j].equals(regex.replace("R","W")) ||
transactionTable[i][j].equals(regex.replace("LOCK_X","LOCK_S")))){
matrixDetectConcurrency[indexTransaction][j] = 1;
}
}
}
}
}
private void findloop(int[][]matrix){
KosarajoAlgoritm graph = new KosarajoAlgoritm(numberOfTransaction);
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[0].length; j++) {
if (matrix[i][j]==1){
graph.addEdge(i,j);
}
}
}
graph.findSCCs();
setIsConcurrent(graph.getNoLoop());
}
public void setIsConcurrent(boolean isConcurrenct) {
DetectConcurrency.isConcurrent = isConcurrenct;
}
public boolean getIsConcurrent (){
return DetectConcurrency.isConcurrent;
}
}