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 exceptions 025 * 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 periodically 028 * check by calling {@link #rethrowException()}. If any foreign exceptions have been received, the 029 * 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, the 034 * notification state is bound to a Thread. Using this, applications receive Exceptions in the 035 * 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 no 043 * exception this is a no-op all exceptions from remote sources are procedure exceptions 044 */ 045 void rethrowException() throws ForeignException; 046 047 /** 048 * Non-exceptional form of {@link #rethrowException()}. Checks to see if any process to which the 049 * exception checkers is bound has created an error that would cause a failure. 050 * @return <tt>true</tt> if there has been an error,<tt>false</tt> otherwise 051 */ 052 boolean hasException(); 053 054 /** 055 * Get the value of the captured exception. 056 * @return the captured foreign exception or null if no exception captured. 057 */ 058 ForeignException getException(); 059}