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.rsgroup;
22
23 import com.google.common.collect.Sets;
24 import com.google.common.net.HostAndPort;
25
26 import java.util.Collection;
27 import java.util.NavigableSet;
28 import java.util.Set;
29
30 import org.apache.hadoop.hbase.TableName;
31 import org.apache.hadoop.hbase.classification.InterfaceAudience;
32 import org.apache.hadoop.hbase.classification.InterfaceStability;
33
34
35
36
37 @InterfaceAudience.Public
38 @InterfaceStability.Evolving
39 public class RSGroupInfo {
40
41 public static final String DEFAULT_GROUP = "default";
42 public static final String NAMESPACEDESC_PROP_GROUP = "hbase.rsgroup.name";
43
44 private String name;
45 private Set<HostAndPort> servers;
46 private NavigableSet<TableName> tables;
47
48 public RSGroupInfo(String name) {
49 this(name, Sets.<HostAndPort>newHashSet(), Sets.<TableName>newTreeSet());
50 }
51
52 RSGroupInfo(String name,
53 Set<HostAndPort> servers,
54 NavigableSet<TableName> tables) {
55 this.name = name;
56 this.servers = servers;
57 this.tables = tables;
58 }
59
60 public RSGroupInfo(RSGroupInfo src) {
61 name = src.getName();
62 servers = Sets.newHashSet(src.getServers());
63 tables = Sets.newTreeSet(src.getTables());
64 }
65
66
67
68
69
70
71 public String getName() {
72 return name;
73 }
74
75
76
77
78
79
80 public void addServer(HostAndPort hostPort){
81 servers.add(hostPort);
82 }
83
84
85
86
87
88
89 public void addAllServers(Collection<HostAndPort> hostPort){
90 servers.addAll(hostPort);
91 }
92
93
94
95
96
97 public boolean containsServer(HostAndPort hostPort) {
98 return servers.contains(hostPort);
99 }
100
101
102
103
104
105
106 public Set<HostAndPort> getServers() {
107 return servers;
108 }
109
110
111
112
113
114
115 public boolean removeServer(HostAndPort hostPort) {
116 return servers.remove(hostPort);
117 }
118
119
120
121
122
123 public NavigableSet<TableName> getTables() {
124 return tables;
125 }
126
127 public void addTable(TableName table) {
128 tables.add(table);
129 }
130
131 public void addAllTables(Collection<TableName> arg) {
132 tables.addAll(arg);
133 }
134
135 public boolean containsTable(TableName table) {
136 return tables.contains(table);
137 }
138
139 public boolean removeTable(TableName table) {
140 return tables.remove(table);
141 }
142
143 @Override
144 public String toString() {
145 StringBuffer sb = new StringBuffer();
146 sb.append("Name:");
147 sb.append(this.name);
148 sb.append(", ");
149 sb.append(" Servers:");
150 sb.append(this.servers);
151 return sb.toString();
152
153 }
154
155 @Override
156 public boolean equals(Object o) {
157 if (this == o) {
158 return true;
159 }
160 if (o == null || getClass() != o.getClass()) {
161 return false;
162 }
163
164 RSGroupInfo RSGroupInfo = (RSGroupInfo) o;
165
166 if (!name.equals(RSGroupInfo.name)) {
167 return false;
168 }
169 if (!servers.equals(RSGroupInfo.servers)) {
170 return false;
171 }
172 if (!tables.equals(RSGroupInfo.tables)) {
173 return false;
174 }
175
176 return true;
177 }
178
179 @Override
180 public int hashCode() {
181 int result = servers.hashCode();
182 result = 31 * result + tables.hashCode();
183 result = 31 * result + name.hashCode();
184 return result;
185 }
186
187 }