Package org.refcodes.controlflow
Class ExceptionWatchdogImpl<E extends java.lang.Exception>
- java.lang.Object
-
- org.refcodes.controlflow.ExceptionWatchdogImpl<E>
-
- Type Parameters:
E
- the element type
- All Implemented Interfaces:
ExceptionWatchdog<E>
,org.refcodes.exception.Exceptional<E>
,org.refcodes.mixin.Disposable
,org.refcodes.mixin.Releaseable
public class ExceptionWatchdogImpl<E extends java.lang.Exception> extends java.lang.Object implements ExceptionWatchdog<E>
TheExceptionWatchdogImpl
implements a plainExceptionWatchdog
not queuing anyException
instances. Just theException
instances thrown viathrowException(Exception)
are caught in case there is an awaiting thread inside thecatchException()
method.ATTENTION: This implementation is not 100% reliable whether very fast sequenced
Exception
instances fed tothrowException(Exception)
are all caught by threads awaiting thecatchException()
method calls! In cases you expect one exception and then "its over", this class does its job.
-
-
Constructor Summary
Constructors Constructor Description ExceptionWatchdogImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
catchException()
This methods awaits anException
.void
dispose()
E
lastException()
Returns the last exception which was pushed viaExceptionWatchdog.throwException(Exception)
.void
releaseAll()
void
throwException(E aException)
Passes an exception to theExceptionWatchdog
notifying all awaiting threads inside theExceptionWatchdog.catchException()
method to be provided with thatException
.
-
-
-
Method Detail
-
catchException
public void catchException() throws E extends java.lang.Exception
This methods awaits anException
. It waits (sleeps) until anException
arises viaExceptionWatchdog.throwException(Exception)
which is then thrown by thisExceptionWatchdog.catchException()
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>
- Specified by:
catchException
in interfaceExceptionWatchdog<E extends java.lang.Exception>
- Throws:
E
- Thrown when a next exception has been provided viaExceptionWatchdog.throwException(Exception)
;E extends java.lang.Exception
-
lastException
public E lastException()
Returns the last exception which was pushed viaExceptionWatchdog.throwException(Exception)
. THis might not be the same as being retrieved byExceptionWatchdog.catchException()
, asExceptionWatchdog.catchException()
might provide queued upException
instances till allException
instances have been processed.- Specified by:
lastException
in interfaceorg.refcodes.exception.Exceptional<E extends java.lang.Exception>
- Specified by:
lastException
in interfaceExceptionWatchdog<E extends java.lang.Exception>
- Returns:
- The last exception being pushed via
ExceptionWatchdog.throwException(Exception)
;
-
throwException
public void throwException(E aException)
Passes an exception to theExceptionWatchdog
notifying all awaiting threads inside theExceptionWatchdog.catchException()
method to be provided with thatException
.- Specified by:
throwException
in interfaceExceptionWatchdog<E extends java.lang.Exception>
- Parameters:
aException
- TheException
to be passed to the awaiting threads inside theExceptionWatchdog.catchException()
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
-
-