1 /*
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 package org.apache.hadoop.hbase.regionserver;
20
21 import org.apache.hadoop.hbase.classification.InterfaceAudience;
22 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
23 import org.apache.hadoop.hbase.HConstants.OperationStatusCode;
24
25 /**
26 *
27 * This class stores the Operation status code and the exception message
28 * that occurs in case of failure of operations like put, delete, etc.
29 * This class is added with a purpose of adding more details or info regarding
30 * the operation status in future.
31 *
32 */
33 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
34 public class OperationStatus {
35
36 /** Singleton for successful operations. */
37 public static final OperationStatus SUCCESS = new OperationStatus(OperationStatusCode.SUCCESS);
38
39 /** Singleton for failed operations. */
40 public static final OperationStatus FAILURE = new OperationStatus(OperationStatusCode.FAILURE);
41
42 /** Singleton for operations not yet run. */
43 public static final OperationStatus NOT_RUN = new OperationStatus(OperationStatusCode.NOT_RUN);
44
45 private final OperationStatusCode code;
46
47 private final String exceptionMsg;
48
49 public OperationStatus(OperationStatusCode code) {
50 this(code, "");
51 }
52
53 public OperationStatus(OperationStatusCode code, String exceptionMsg) {
54 this.code = code;
55 this.exceptionMsg = exceptionMsg;
56 }
57
58 public OperationStatus(OperationStatusCode code, Exception e) {
59 this.code = code;
60 this.exceptionMsg = (e == null) ? "" : e.getClass().getName() + ": " + e.getMessage();
61 }
62
63 /**
64 * @return OperationStatusCode
65 */
66 public OperationStatusCode getOperationStatusCode() {
67 return code;
68 }
69
70 /**
71 * @return ExceptionMessge
72 */
73 public String getExceptionMsg() {
74 return exceptionMsg;
75 }
76 }