-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCluster.java
More file actions
67 lines (52 loc) · 1.63 KB
/
Copy pathCluster.java
File metadata and controls
67 lines (52 loc) · 1.63 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
56
57
58
59
60
61
62
63
64
65
66
67
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class Cluster implements Serializable {
private static final long serialVersionUID = -299482035708790407L;
private static Cluster cluster = null;
private List<Node> nodes = new ArrayList<Node>();
//For singleton object
public static Cluster getInstance(){
if(cluster == null){
cluster = new Cluster();
}
return cluster;
}
public synchronized void addNode(Node node){
this.nodes.add(node);
Logger.logMsg("Node added into the cluster " + node);
}
public synchronized void updateNodesList(Cluster cluster){
this.nodes = cluster.getNodes();
Logger.logMsg("List of nodes in cluster is updated");
}
public synchronized boolean removeNode(Node node, ServiceHandler handler){
Node removedNode = null;
for(Node n: nodes){
if(n.equals(node)){
removedNode = n;
}
}
if(removedNode != null && this.nodes.remove(removedNode)){
Logger.logMsg("Node removed from the cluster " + node);
// handler.sendClusterUpdateRequest(this);
return true;
}
return false;
}
public static Cluster getCluster() {
return cluster;
}
public static void setCluster(Cluster cluster) {
Cluster.cluster = cluster;
}
public List<Node> getNodes() {
return nodes;
}
public void setNodes(List<Node> nodes) {
this.nodes = nodes;
}
public int getNumOfNodes(){
return this.nodes.size();
}
}