Class MessageCatcher

  • All Implemented Interfaces:

    public class MessageCatcher
    extends SingleSender<Message>
    implements java.lang.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 Detail

      • caught

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

        protected final @Opt java.lang.Runnable runnable
        The code to execute
    • Constructor Detail

      • MessageCatcher

        public MessageCatcher​(java.lang.Runnable c,
                              MessageReceiver<Message> rec)
        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 Detail

      • getCaught

        public @Opt java.lang.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 java.lang.Runnable