2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.client
;
20 import org
.apache
.hadoop
.hbase
.shaded
.com
.google
.protobuf
.InvalidProtocolBufferException
;
21 import org
.apache
.hadoop
.hbase
.TableName
;
22 import org
.apache
.hadoop
.hbase
.classification
.InterfaceAudience
;
23 import org
.apache
.hadoop
.hbase
.classification
.InterfaceStability
;
24 import org
.apache
.hadoop
.hbase
.exceptions
.DeserializationException
;
25 import org
.apache
.hadoop
.hbase
.shaded
.protobuf
.generated
.HBaseProtos
;
28 * Represents table state.
30 @InterfaceAudience.Private
31 public class TableState
{
33 @InterfaceAudience.Private
34 @InterfaceStability.Evolving
35 public static enum State
{
42 * Covert from PB version of State
44 * @param state convert from
47 public static State
convert(HBaseProtos
.TableState
.State state
) {
57 ret
= State
.DISABLING
;
63 throw new IllegalStateException(state
.toString());
69 * Covert to PB version of State
73 public HBaseProtos
.TableState
.State
convert() {
74 HBaseProtos
.TableState
.State state
;
77 state
= HBaseProtos
.TableState
.State
.ENABLED
;
80 state
= HBaseProtos
.TableState
.State
.DISABLED
;
83 state
= HBaseProtos
.TableState
.State
.DISABLING
;
86 state
= HBaseProtos
.TableState
.State
.ENABLING
;
89 throw new IllegalStateException(this.toString());
96 private final TableName tableName
;
97 private final State state
;
100 * Create instance of TableState.
101 * @param tableName name of the table
102 * @param state table state
104 public TableState(TableName tableName
, State state
) {
105 this.tableName
= tableName
;
110 * @return table state
112 public State
getState() {
117 * Table name for state
119 * @return milliseconds
121 public TableName
getTableName() {
126 * Check that table in given states
128 * @return true if satisfies
130 public boolean inStates(State state
) {
131 return this.state
.equals(state
);
135 * Check that table in given states
136 * @param states state list
137 * @return true if satisfies
139 public boolean inStates(State
... states
) {
140 for (State s
: states
) {
141 if (s
.equals(this.state
))
149 * Covert to PB version of TableState
152 public HBaseProtos
.TableState
convert() {
153 return HBaseProtos
.TableState
.newBuilder()
154 .setState(this.state
.convert()).build();
158 * Covert from PB version of TableState
160 * @param tableName table this state of
161 * @param tableState convert from
164 public static TableState
convert(TableName tableName
, HBaseProtos
.TableState tableState
) {
165 TableState
.State state
= State
.convert(tableState
.getState());
166 return new TableState(tableName
, state
);
169 public static TableState
parseFrom(TableName tableName
, byte[] bytes
)
170 throws DeserializationException
{
172 return convert(tableName
, HBaseProtos
.TableState
.parseFrom(bytes
));
173 } catch (InvalidProtocolBufferException e
) {
174 throw new DeserializationException(e
);
179 * Static version of state checker
180 * @param state desired
181 * @param target equals to any of
182 * @return true if satisfies
184 public static boolean isInStates(State state
, State
... target
) {
185 for (State tableState
: target
) {
186 if (state
.equals(tableState
))
193 public boolean equals(Object o
) {
194 if (this == o
) return true;
195 if (o
== null || getClass() != o
.getClass()) return false;
197 TableState that
= (TableState
) o
;
199 if (state
!= that
.state
) return false;
200 if (tableName
!= null ?
!tableName
.equals(that
.tableName
) : that
.tableName
!= null)
207 public int hashCode() {
208 int result
= (tableName
!= null ? tableName
.hashCode() : 0);
209 result
= 31 * result
+ (state
!= null ? state
.hashCode() : 0);
214 public String
toString() {
215 return "TableState{" +
216 ", tableName=" + tableName
+