Module org.refcodes.controlflow
Package org.refcodes.controlflow
Class ExceptionWatchdog<E extends Exception>
java.lang.Object
org.refcodes.controlflow.ExceptionWatchdog<E>
- Type Parameters:
E- the element type
- All Implemented Interfaces:
org.refcodes.exception.Exceptional<E>,org.refcodes.mixin.Disposable,org.refcodes.mixin.Releaseable
public class ExceptionWatchdog<E extends Exception>
extends Object
implements org.refcodes.exception.Exceptional<E>, org.refcodes.mixin.Disposable, org.refcodes.mixin.Releaseable
The
ExceptionWatchdog implements a plain ExceptionWatchdog
not queuing any Exception instances. Just the Exception
instances thrown via throwException(Exception) are caught in case
there is an awaiting thread inside the catchException() method.
ATTENTION: This implementation is not 100% reliable whether very fast
sequenced Exception instances fed to
throwException(Exception) are all caught by threads awaiting the
catchException() method calls! In cases you expect one exception and
then "its over", this class does its job.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThis methods awaits anException.voiddispose()Returns the last exception which was pushed viathrowException(Exception).voidvoidthrowException(E aException) Passes an exception to theExceptionWatchdognotifying all awaiting threads inside thecatchException()method to be provided with thatException.
-
Constructor Details
-
ExceptionWatchdog
public ExceptionWatchdog()
-
-
Method Details
-
catchException
This methods awaits anException. It waits (sleeps) until anExceptionarises viathrowException(Exception)which is then thrown by thiscatchException()method. In casereleaseAll()is being called, then all waiting threads are continued without throwing any exception. ------------------------------------------------------------------------- ATTENTION: In case waiting (sleeping) threads are released without throwing anException, then this means that the using instances intends to shut down so that in such as case, no more calls to this method are to be performed (are to be prevented), such looping threads would lead to endless looping and cause consumption of calculation power.- Specified by:
catchExceptionin interfaceorg.refcodes.exception.Exceptional<E extends Exception>- Throws:
E- Thrown when a next exception has been provided viathrowException(Exception);
-
lastException
Returns the last exception which was pushed viathrowException(Exception). THis might not be the same as being retrieved bycatchException(), ascatchException()might provide queued upExceptioninstances till allExceptioninstances have been processed.- Specified by:
lastExceptionin interfaceorg.refcodes.exception.Exceptional<E extends Exception>- Returns:
- The last exception being pushed via
throwException(Exception);
-
throwException
Passes an exception to theExceptionWatchdognotifying all awaiting threads inside thecatchException()method to be provided with thatException.- Parameters:
aException- TheExceptionto be passed to the awaiting threads inside thecatchException()method.
-
releaseAll
public void releaseAll()- Specified by:
releaseAllin interfaceorg.refcodes.mixin.Releaseable
-
dispose
public void dispose()- Specified by:
disposein interfaceorg.refcodes.mixin.Disposable
-