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.yetus.audience.InterfaceAudience;
024
025/**
026 * 
027 * This class stores the Operation status code and the exception message
028 * that occurs in case of failure of operations like put, delete, etc.
029 * This class is added with a purpose of adding more details or info regarding
030 * the operation status in future.
031 *
032 */
033@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
034public class OperationStatus {
035
036  /** Singleton for successful operations.  */
037  public static final OperationStatus SUCCESS = new OperationStatus(OperationStatusCode.SUCCESS);
038
039  /** Singleton for failed operations.  */
040  public static final OperationStatus FAILURE = new OperationStatus(OperationStatusCode.FAILURE);
041
042  /** Singleton for operations not yet run.  */
043  public static final OperationStatus NOT_RUN = new OperationStatus(OperationStatusCode.NOT_RUN);
044
045  private final OperationStatusCode code;
046
047  private final String exceptionMsg;
048
049  public OperationStatus(OperationStatusCode code) {
050    this(code, "");
051  }
052
053  public OperationStatus(OperationStatusCode code, String exceptionMsg) {
054    this.code = code;
055    this.exceptionMsg = exceptionMsg;
056  }
057
058  public OperationStatus(OperationStatusCode code, Exception e) {
059    this.code = code;
060    this.exceptionMsg = (e == null) ? "" : e.getClass().getName() + ": " + e.getMessage();
061  }
062
063  /**
064   * @return OperationStatusCode
065   */
066  public OperationStatusCode getOperationStatusCode() {
067    return code;
068  }
069
070  /**
071   * @return ExceptionMessge
072   */
073  public String getExceptionMsg() {
074    return exceptionMsg;
075  }
076}