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 some code (given explicitly as argument) and sends the first exception caught to its message drain.

The code can either be defined (1) as a Runnable and given as constructor argument, or (2) be re-defining code() in a derived class.
Then call run() to start execution.

Caught throwables which are Messages are sent directly to the MessageReceiver in SingleSender.receiver. All other Exception are wrapped into a SimpleMessageof kind failure.
Errors are not caught, only Exceptions.
  • Field Details

  • Constructor Details

    • MessageCatcher

      public MessageCatcher(Runnable c, MessageReceiver<Message> rec)
      Evident.
      Parameters:
      c - the code to execute
      rec - the essage receiver
    • MessageCatcher

      public MessageCatcher(MessageReceiver<Message> rec)
      When using this constructor, you have to re-define the method code(). Otherwise code will crash intentionally.
  • Method Details

    • getCaught

      @Opt public @Opt Exception getCaught()
      returns the last throwable caught, if any.
    • code

      protected void code()
      Redefine this method, or set the value of runnable via constructor call. Otherwise code will crash intentionally.
    • run

      public void run()
      Specified by:
      run in interface Runnable