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