001/* 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019package org.apache.hadoop.hbase.regionserver; 020 021import org.apache.hadoop.hbase.HBaseInterfaceAudience; 022import org.apache.hadoop.hbase.HConstants.OperationStatusCode; 023import org.apache.hadoop.hbase.client.Result; 024import org.apache.yetus.audience.InterfaceAudience; 025 026/** 027 * 028 * This class stores the Operation status code and the exception message 029 * that occurs in case of failure of operations like put, delete, etc. 030 * This class is added with a purpose of adding more details or info regarding 031 * the operation status in future. 032 * 033 */ 034@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC) 035public class OperationStatus { 036 037 /** Singleton for successful operations. */ 038 public static final OperationStatus SUCCESS = new OperationStatus(OperationStatusCode.SUCCESS); 039 040 /** Singleton for failed operations. */ 041 public static final OperationStatus FAILURE = new OperationStatus(OperationStatusCode.FAILURE); 042 043 /** Singleton for operations not yet run. */ 044 public static final OperationStatus NOT_RUN = new OperationStatus(OperationStatusCode.NOT_RUN); 045 046 private final OperationStatusCode code; 047 private final Result result; 048 private final String exceptionMsg; 049 050 public OperationStatus(OperationStatusCode code) { 051 this(code, null, ""); 052 } 053 054 public OperationStatus(OperationStatusCode code, Result result) { 055 this(code, result, ""); 056 } 057 058 public OperationStatus(OperationStatusCode code, String exceptionMsg) { 059 this(code, null, exceptionMsg); 060 } 061 062 public OperationStatus(OperationStatusCode code, Exception e) { 063 this(code, null, (e == null) ? "" : e.getClass().getName() + ": " + e.getMessage()); 064 } 065 066 private OperationStatus(OperationStatusCode code, Result result, String exceptionMsg) { 067 this.code = code; 068 this.result = result; 069 this.exceptionMsg = exceptionMsg; 070 } 071 072 /** 073 * @return OperationStatusCode 074 */ 075 public OperationStatusCode getOperationStatusCode() { 076 return code; 077 } 078 079 /** 080 * @return result 081 */ 082 public Result getResult() { 083 return result; 084 } 085 086 /** 087 * @return ExceptionMessge 088 */ 089 public String getExceptionMsg() { 090 return exceptionMsg; 091 } 092}