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 * This is an interface for a cooperative exception throwing mechanism. Implementations are 024 * containers that holds an exception from a separate thread. This can be used to receive 025 * exceptions from 'foreign' threads or from separate 'foreign' processes. 026 * <p> 027 * To use, one would pass an implementation of this object to a long running method and 028 * periodically check by calling {@link #rethrowException()}. If any foreign exceptions have 029 * been received, the calling thread is then responsible for handling the rethrown exception. 030 * <p> 031 * One could use the boolean {@link #hasException()} to determine if there is an exceptoin as well. 032 * <p> 033 * NOTE: This is very similar to the InterruptedException/interrupt/interrupted pattern. There, 034 * the notification state is bound to a Thread. Using this, applications receive Exceptions in 035 * the snare. The snare is referenced and checked by multiple threads which enables exception 036 * notification in all the involved threads/processes. 037 */ 038@InterfaceAudience.Private 039public interface ForeignExceptionSnare { 040 041 /** 042 * Rethrow an exception currently held by the {@link ForeignExceptionSnare}. If there is 043 * no exception this is a no-op 044 * 045 * @throws ForeignException 046 * all exceptions from remote sources are procedure exceptions 047 */ 048 void rethrowException() throws ForeignException; 049 050 /** 051 * Non-exceptional form of {@link #rethrowException()}. Checks to see if any 052 * process to which the exception checkers is bound has created an error that 053 * would cause a failure. 054 * 055 * @return <tt>true</tt> if there has been an error,<tt>false</tt> otherwise 056 */ 057 boolean hasException(); 058 059 /** 060 * Get the value of the captured exception. 061 * 062 * @return the captured foreign exception or null if no exception captured. 063 */ 064 ForeignException getException(); 065}