Fix NPEs on switch disconnect in cluster mode
[controller.git] / opendaylight / web / root / src / main / java / org / opendaylight / controller / web / ClusterNodeBean.java
1 package org.opendaylight.controller.web;
2
3 import java.net.InetAddress;
4
5 /**
6  * Information about a clustered controller to send to the UI frontend
7  * @author andrekim
8  */
9 public class ClusterNodeBean {
10     private final byte[] address;
11     private final String name;
12     private final Boolean me;
13     private final Boolean coordinator;
14     private final Integer numConnectedNodes;
15
16     public static class Builder {
17         // required params
18         private final byte[] address;
19         private final String name;
20
21         // optional params
22         private Boolean me = null;
23         private Boolean coordinator = null;
24         private Integer numConnectedNodes = null;
25
26         public Builder(InetAddress address) {
27             this.address = address.getAddress();
28             this.name = address.getHostAddress();
29         }
30
31         public Builder highlightMe() {
32             this.me = true;
33             return this;
34         }
35
36         public Builder iAmCoordinator() {
37             this.coordinator = true;
38             return this;
39         }
40
41         public Builder nodesConnected(int numNodes) {
42             this.numConnectedNodes = numNodes;
43             return this;
44         }
45
46         public ClusterNodeBean build() {
47             return new ClusterNodeBean(this);
48         }
49     }
50
51     private ClusterNodeBean(Builder builder) {
52         this.address = builder.address;
53         this.name = builder.name;
54         this.me = builder.me;
55         this.coordinator = builder.coordinator;
56         this.numConnectedNodes = builder.numConnectedNodes;
57     }
58 }