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.errorhandling; 019 020import org.apache.yetus.audience.InterfaceAudience; 021 022/** 023 * Exception for timeout of a task. 024 * @see TimeoutExceptionInjector 025 */ 026@InterfaceAudience.Public 027@SuppressWarnings("serial") 028public class TimeoutException extends Exception { 029 030 private final String sourceName; 031 private final long start; 032 private final long end; 033 private final long expected; 034 035 /** 036 * Exception indicating that an operation attempt has timed out 037 * @param start time the operation started (ms since epoch) 038 * @param end time the timeout was triggered (ms since epoch) 039 * @param expected expected amount of time for the operation to complete (ms) 040 * (ideally, expected <= end-start) 041 */ 042 public TimeoutException(String sourceName, long start, long end, long expected) { 043 super("Timeout elapsed! Source:" + sourceName + " Start:" + start + ", End:" + end 044 + ", diff:" + (end - start) + ", max:" + expected + " ms"); 045 this.sourceName = sourceName; 046 this.start = start; 047 this.end = end; 048 this.expected = expected; 049 } 050 051 public long getStart() { 052 return start; 053 } 054 055 public long getEnd() { 056 return end; 057 } 058 059 public long getMaxAllowedOperationTime() { 060 return expected; 061 } 062 063 public String getSourceName() { 064 return sourceName; 065 } 066}