1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.rest.model;
22
23 import java.io.Serializable;
24
25 import javax.xml.bind.annotation.XmlAttribute;
26 import javax.xml.bind.annotation.XmlRootElement;
27
28 import org.apache.hadoop.hbase.util.Bytes;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 @XmlRootElement(name="Region")
45 public class TableRegionModel implements Serializable {
46
47 private static final long serialVersionUID = 1L;
48
49 private String table;
50 private long id;
51 private byte[] startKey;
52 private byte[] endKey;
53 private String location;
54
55
56
57
58 public TableRegionModel() {}
59
60
61
62
63
64
65
66
67 public TableRegionModel(String table, long id, byte[] startKey,
68 byte[] endKey) {
69 this(table, id, startKey, endKey, null);
70 }
71
72
73
74
75
76
77
78
79
80 public TableRegionModel(String table, long id, byte[] startKey,
81 byte[] endKey, String location) {
82 this.table = table;
83 this.id = id;
84 this.startKey = startKey;
85 this.endKey = endKey;
86 this.location = location;
87 }
88
89
90
91
92 @XmlAttribute
93 public String getName() {
94 StringBuilder sb = new StringBuilder();
95 sb.append(table);
96 sb.append(',');
97 sb.append(Bytes.toString(startKey));
98 sb.append(',');
99 sb.append(id);
100 return sb.toString();
101 }
102
103
104
105
106 @XmlAttribute
107 public long getId() {
108 return id;
109 }
110
111
112
113
114 @XmlAttribute
115 public byte[] getStartKey() {
116 return startKey;
117 }
118
119
120
121
122 @XmlAttribute
123 public byte[] getEndKey() {
124 return endKey;
125 }
126
127
128
129
130 @XmlAttribute
131 public String getLocation() {
132 return location;
133 }
134
135
136
137
138 public void setName(String name) {
139 String split[] = name.split(",");
140 table = split[0];
141 startKey = Bytes.toBytes(split[1]);
142 id = Long.valueOf(split[2]);
143 }
144
145
146
147
148 public void setId(long id) {
149 this.id = id;
150 }
151
152
153
154
155 public void setStartKey(byte[] startKey) {
156 this.startKey = startKey;
157 }
158
159
160
161
162 public void setEndKey(byte[] endKey) {
163 this.endKey = endKey;
164 }
165
166
167
168
169 public void setLocation(String location) {
170 this.location = location;
171 }
172
173
174
175
176 @Override
177 public String toString() {
178 StringBuilder sb = new StringBuilder();
179 sb.append(getName());
180 sb.append(" [\n id=");
181 sb.append(id);
182 sb.append("\n startKey='");
183 sb.append(Bytes.toString(startKey));
184 sb.append("'\n endKey='");
185 sb.append(Bytes.toString(endKey));
186 if (location != null) {
187 sb.append("'\n location='");
188 sb.append(location);
189 }
190 sb.append("'\n]\n");
191 return sb.toString();
192 }
193 }