1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase;
21
22 import java.io.DataInput;
23 import java.io.DataOutput;
24 import java.io.IOException;
25 import java.net.InetSocketAddress;
26
27 import org.apache.hadoop.hbase.regionserver.HRegionServer;
28 import org.apache.hadoop.io.VersionedWritable;
29 import org.apache.hadoop.io.WritableComparable;
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public class HServerInfo extends VersionedWritable
44 implements WritableComparable<HServerInfo> {
45 private static final byte VERSION = 1;
46 private HServerAddress serverAddress = new HServerAddress();
47 private long startCode;
48 private int webuiport;
49
50 public HServerInfo() {
51 super();
52 }
53
54
55
56
57
58
59 public HServerInfo(final HServerAddress serverAddress, final int webuiport) {
60 this(serverAddress, System.currentTimeMillis(), webuiport);
61 }
62
63 public HServerInfo(HServerAddress serverAddress, long startCode,
64 final int webuiport) {
65 this.serverAddress = serverAddress;
66 this.startCode = startCode;
67 this.webuiport = webuiport;
68 }
69
70
71
72
73
74 public HServerInfo(HServerInfo other) {
75 this.serverAddress = new HServerAddress(other.getServerAddress());
76 this.startCode = other.getStartCode();
77 this.webuiport = other.getInfoPort();
78 }
79
80
81 public byte getVersion() {
82 return VERSION;
83 }
84
85 public synchronized HServerAddress getServerAddress() {
86 return new HServerAddress(serverAddress);
87 }
88
89 public synchronized long getStartCode() {
90 return startCode;
91 }
92
93 public int getInfoPort() {
94 return getWebuiPort();
95 }
96
97 public int getWebuiPort() {
98 return this.webuiport;
99 }
100
101 public String getHostname() {
102 return this.serverAddress.getHostname();
103 }
104
105
106
107
108 @Override
109 public synchronized String toString() {
110 return ServerName.getServerName(this.serverAddress.getHostnameAndPort(),
111 this.startCode);
112 }
113
114 @Override
115 public boolean equals(Object obj) {
116 if (this == obj) return true;
117 if (obj == null) return false;
118 if (getClass() != obj.getClass()) return false;
119 return compareTo((HServerInfo)obj) == 0;
120 }
121
122 @Override
123 public int hashCode() {
124 int code = this.serverAddress.hashCode();
125 code ^= this.webuiport;
126 code ^= this.startCode;
127 return code;
128 }
129
130 public void readFields(DataInput in) throws IOException {
131 super.readFields(in);
132 this.serverAddress.readFields(in);
133 this.startCode = in.readLong();
134 this.webuiport = in.readInt();
135 }
136
137 public void write(DataOutput out) throws IOException {
138 super.write(out);
139 this.serverAddress.write(out);
140 out.writeLong(this.startCode);
141 out.writeInt(this.webuiport);
142 }
143
144 public int compareTo(HServerInfo o) {
145 int compare = this.serverAddress.compareTo(o.getServerAddress());
146 if (compare != 0) return compare;
147 if (this.webuiport != o.getInfoPort()) return this.webuiport - o.getInfoPort();
148 if (this.startCode != o.getStartCode()) return (int)(this.startCode - o.getStartCode());
149 return 0;
150 }
151 }