-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rebalance.java
49 lines (43 loc) · 1.45 KB
/
Rebalance.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
import javax.naming.ldap.Control;
import java.time.LocalDateTime;
public class Rebalance extends Thread {
private int period;
private static Controller controller;
public Rebalance(Controller controller, int period){
this.controller = controller;
this.period = period;
}
@Override
public void run() {
super.run();
try {
start_rebalancing();
} catch (InterruptedException e) {
System.out.println(Controller.RED+"New dstore interrupted current rebalancing"+Controller.WHITE);
controller.rebalance_finished();
//e.printStackTrace();
}
}
private void start_rebalancing() throws InterruptedException {
int i=0;
while(true){
//Busy wait
if(controller.pendingOperations.size()>0 || controller.storage.keySet().size()==0) {
if (LocalDateTime.now().getSecond() % 10 == 0) {
if (i == 1) {
System.out.println(controller.pendingOperations.size());
i = 0;
}
} else {
i = 1;
}
}
else{
controller.rebalance();
System.out.println(controller.CYAN+"DOING REBALANCING STUFF"+controller.WHITE);
controller.rebalance_finished();
Thread.sleep(period);
}
}
}
}