Class MessageCatcher

java.lang.Object
eu.bandm.tools.message.SingleSender<Message>
eu.bandm.tools.message.MessageCatcher
All Implemented Interfaces:
Runnable

public class MessageCatcher extends SingleSender<Message> implements Runnable
Executes payload code and sends the first exception caught to its given message drain.

The execution ends with the programmed end of the payload code, or when a exception is caught. Then execution can be restarted. The code must either be defined (1) as a Runnable and given as constructor argument, or (2) by re-defining code() in a derived class. Then run() can be called to start its execution.

A caught MessageException is unwrapped and sent directly to the given MessageReceiver. All other exceptions are wrapped into a SimpleMessage of kind failure.

Errors are not caught, only Exceptions.

  • Field Details

    • caught

      @Opt protected @Opt Exception caught
      local cache for the caught exception.
    • runnable

      @Opt protected final @Opt Runnable runnable
      The payload code to execute
    • running

      protected boolean running
      Whether currently running.
  • Constructor Details

  • Method Details

    • isRunning

      public boolean isRunning()
      Returns whether currently running.
      Returns:
      whether currently running.
    • getCaught

      @Opt public @Opt Exception getCaught()
      Returns the last exception caught, if any.
      Returns:
      the last exception caught, if any.
    • code

      protected void code()
      Override this method to define the payload code, or set the value of runnable via constructor call. Otherwise trying to run() this instace will crash intentionally.
    • run

      public void run()
      Start the execution of the given payload code.
      Specified by:
      run in interface Runnable
      Throws:
      IllegalStateException - if called when currently running.