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