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.classification.InterfaceAudience;
21 import org.apache.hadoop.classification.InterfaceStability;
22
23 /**
24 * This is an interface for a cooperative exception throwing mechanism. Implementations are
25 * containers that holds an exception from a separate thread. This can be used to receive
26 * exceptions from 'foreign' threads or from separate 'foreign' processes.
27 * <p>
28 * To use, one would pass an implementation of this object to a long running method and
29 * periodically check by calling {@link #rethrowException()}. If any foreign exceptions have
30 * been received, the calling thread is then responsible for handling the rethrown exception.
31 * <p>
32 * One could use the boolean {@link #hasException()} to determine if there is an exceptoin as well.
33 * <p>
34 * NOTE: This is very similar to the InterruptedException/interrupt/interrupted pattern. There,
35 * the notification state is bound to a Thread. Using this, applications receive Exceptions in
36 * the snare. The snare is referenced and checked by multiple threads which enables exception
37 * notification in all the involved threads/processes.
38 */
39 @InterfaceAudience.Public
40 @InterfaceStability.Evolving
41 public interface ForeignExceptionSnare {
42
43 /**
44 * Rethrow an exception currently held by the {@link ForeignExceptionSnare}. If there is
45 * no exception this is a no-op
46 *
47 * @throws ForeignException
48 * all exceptions from remote sources are procedure exceptions
49 */
50 void rethrowException() throws ForeignException;
51
52 /**
53 * Non-exceptional form of {@link #rethrowException()}. Checks to see if any
54 * process to which the exception checkers is bound has created an error that
55 * would cause a failure.
56 *
57 * @return <tt>true</tt> if there has been an error,<tt>false</tt> otherwise
58 */
59 boolean hasException();
60
61 /**
62 * Get the value of the captured exception.
63 *
64 * @return the captured foreign exception or null if no exception captured.
65 */
66 ForeignException getException();
67 }