diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/src/main/java/org/apache/drill/common/exceptions/DrillRuntimeException.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/common/src/main/java/org/apache/drill/common/exceptions/DrillRuntimeException.java b/common/src/main/java/org/apache/drill/common/exceptions/DrillRuntimeException.java index 98b1a9d03..b6ced84d0 100644 --- a/common/src/main/java/org/apache/drill/common/exceptions/DrillRuntimeException.java +++ b/common/src/main/java/org/apache/drill/common/exceptions/DrillRuntimeException.java @@ -48,4 +48,22 @@ public class DrillRuntimeException extends RuntimeException { public static void format(Throwable cause, String format, Object...args) { throw new DrillRuntimeException(String.format(format, args), cause); } + + /** + * This method can be called within loops to check whether the current thread has been + * interrupted; it ensures that operator implementation can respond to query cancellation + * in a timely manner. + * + * <p>Calling this method will result in the following behavior: + * <ul> + * <li>Throws a runtime exception if current thread interrupt flag has been set + * <li>Clears current thread interrupt flag + * </ul> + */ + public static void checkInterrupted() { + if (Thread.interrupted()) { + // This exception will ensure the control layer will immediately get back control + throw new DrillRuntimeException("Interrupt received; aborting current operation"); + } + } } |