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 Details

    • ExceptionWatchdog

      public ExceptionWatchdog()
  • Method Details

    • catchException

      public void catchException() throws E
      This methods awaits an Exception. It waits (sleeps) until an Exception arises via throwException(Exception) which is then thrown by this catchException() method. In case releaseAll() is being called, then all waiting threads are continued without throwing any exception. ------------------------------------------------------------------------- ATTENTION: In case waiting (sleeping) threads are released without throwing an Exception, 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 interface org.refcodes.exception.Exceptional<E extends Exception>
      Throws:
      E - Thrown when a next exception has been provided via throwException(Exception);
    • lastException

      public E lastException()
      Returns the last exception which was pushed via throwException(Exception). THis might not be the same as being retrieved by catchException(), as catchException() might provide queued up Exception instances till all Exception instances have been processed.
      Specified by:
      lastException in interface org.refcodes.exception.Exceptional<E extends Exception>
      Returns:
      The last exception being pushed via throwException(Exception);
    • throwException

      public void throwException(E aException)
      Passes an exception to the ExceptionWatchdog notifying all awaiting threads inside the catchException() method to be provided with that Exception.
      Parameters:
      aException - The Exception to be passed to the awaiting threads inside the catchException() method.
    • releaseAll

      public void releaseAll()
      Specified by:
      releaseAll in interface org.refcodes.mixin.Releaseable
    • dispose

      public void dispose()
      Specified by:
      dispose in interface org.refcodes.mixin.Disposable