1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.apache.hadoop.hbase.errorhandling; 19 20 import org.apache.hadoop.hbase.classification.InterfaceAudience; 21 22 /** 23 * This is an interface for a cooperative exception throwing mechanism. Implementations are 24 * containers that holds an exception from a separate thread. This can be used to receive 25 * exceptions from 'foreign' threads or from separate 'foreign' processes. 26 * <p> 27 * To use, one would pass an implementation of this object to a long running method and 28 * periodically check by calling {@link #rethrowException()}. If any foreign exceptions have 29 * been received, the calling thread is then responsible for handling the rethrown exception. 30 * <p> 31 * One could use the boolean {@link #hasException()} to determine if there is an exceptoin as well. 32 * <p> 33 * NOTE: This is very similar to the InterruptedException/interrupt/interrupted pattern. There, 34 * the notification state is bound to a Thread. Using this, applications receive Exceptions in 35 * the snare. The snare is referenced and checked by multiple threads which enables exception 36 * notification in all the involved threads/processes. 37 */ 38 @InterfaceAudience.Private 39 public interface ForeignExceptionSnare { 40 41 /** 42 * Rethrow an exception currently held by the {@link ForeignExceptionSnare}. If there is 43 * no exception this is a no-op 44 * 45 * @throws ForeignException 46 * all exceptions from remote sources are procedure exceptions 47 */ 48 void rethrowException() throws ForeignException; 49 50 /** 51 * Non-exceptional form of {@link #rethrowException()}. Checks to see if any 52 * process to which the exception checkers is bound has created an error that 53 * would cause a failure. 54 * 55 * @return <tt>true</tt> if there has been an error,<tt>false</tt> otherwise 56 */ 57 boolean hasException(); 58 59 /** 60 * Get the value of the captured exception. 61 * 62 * @return the captured foreign exception or null if no exception captured. 63 */ 64 ForeignException getException(); 65 }