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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
This methods awaits anException
.void
dispose()
Returns the last exception which was pushed viathrowException(Exception)
.void
void
throwException
(E aException) Passes an exception to theExceptionWatchdog
notifying 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 anException
arises 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:
catchException
in 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 upException
instances till allException
instances have been processed.- Specified by:
lastException
in interfaceorg.refcodes.exception.Exceptional<E extends Exception>
- Returns:
- The last exception being pushed via
throwException(Exception)
;
-
throwException
Passes an exception to theExceptionWatchdog
notifying all awaiting threads inside thecatchException()
method to be provided with thatException
.- Parameters:
aException
- TheException
to be passed to the awaiting threads inside thecatchException()
method.
-
releaseAll
public void releaseAll()- Specified by:
releaseAll
in interfaceorg.refcodes.mixin.Releaseable
-
dispose
public void dispose()- Specified by:
dispose
in interfaceorg.refcodes.mixin.Disposable
-