Package org.refcodes.controlflow
Interface ExceptionWatchdog<E extends java.lang.Exception>
-
- Type Parameters:
E
- the element type
- All Superinterfaces:
org.refcodes.mixin.Disposable
,org.refcodes.exception.Exceptional<E>
,org.refcodes.mixin.Releaseable
- All Known Implementing Classes:
ExceptionWatchdogImpl
public interface ExceptionWatchdog<E extends java.lang.Exception> extends org.refcodes.exception.Exceptional<E>, org.refcodes.mixin.Disposable, org.refcodes.mixin.Releaseable
TheExceptionWatchdog
allows any number of threads to wait (sleep) when callingcatchException()
till theExceptionWatchdog
is fed with a nextException
withthrowException(Exception)
or till all waiting threads are released by callingReleaseable.releaseAll()
.Depending in the implementation, either just the current exception is passed to the
catchException()
method or a FIFO queue may be used passing all queuedException
instances to thecatchException()
method as soon as a thread is awaiting anException
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
catchException()
This methods awaits anException
.E
lastException()
Returns the last exception which was pushed viathrowException(Exception)
.void
throwException(E aException)
Passes an exception to theExceptionWatchdog
notifying all awaiting threads inside thecatchException()
method to be provided with thatException
.
-
-
-
Method Detail
-
catchException
void catchException() throws E extends java.lang.Exception
This methods awaits anException
. It waits (sleeps) until anException
arises viathrowException(Exception)
which is then thrown by thiscatchException()
method. In caseReleaseable.releaseAll()
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 java.lang.Exception>
- Throws:
E
- Thrown when a next exception has been provided viathrowException(Exception)
;E extends java.lang.Exception
-
lastException
E 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 java.lang.Exception>
- Returns:
- The last exception being pushed via
throwException(Exception)
;
-
throwException
void throwException(E aException)
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.
-
-