Class ThrowableCause

All Implemented Interfaces:
Serializable, Cause

public class ThrowableCause extends AxonException implements Cause
An implementation of Cause taking in a Throwable.
Since:
4.6.0
Author:
Steven van Beelen, Mitchel Herrijgers
See Also:
  • Field Details

  • Constructor Details

    • ThrowableCause

      public ThrowableCause(Throwable throwable)
      Construct a cause based on the given throwable. Uses the fully qualified class name as the type and the Throwable.getMessage() as the message.
      Parameters:
      throwable - The throwable to base this cause on.
    • ThrowableCause

      public ThrowableCause(String type, String message)
      Constructs a cause based on the give type and message.
      Parameters:
      type - The type of this cause.
      message - The message of this cause.
  • Method Details

    • asCause

      public static ThrowableCause asCause(Throwable cause)
      Return the given cause as a ThrowableCause.

      If the given cause is an instance of ThrowableCause it is returned as is. Otherwise, this method constructs a new instance through ThrowableCause(Throwable).

      Parameters:
      cause - The Throwable to map to a ThrowableCause.
      Returns:
      A ThrowableCause based on the given cause, or the cause as-is if it is an instance of ThrowableCause.
    • truncated

      public static ThrowableCause truncated(Throwable throwable)
      Construct a ThrowableCause based on the given throwable, truncating the message to a maximum size of TRUNCATED_MESSAGE_SIZE.

      Should be used to ensure the Cause fits in the desired dead-letter storage solution.

      Parameters:
      throwable - The Throwable to adjust to a ThrowableCause.
      Returns:
      A ThrowableCause based on the given throwable for which the message is truncated to TRUNCATED_MESSAGE_SIZE.
    • truncated

      public static ThrowableCause truncated(Throwable throwable, int messageSize)
      Construct a ThrowableCause based on the given throwable, truncating the message to the given messageSize.

      Should be used to ensure the Cause fits in the desired dead-letter storage solution.

      Parameters:
      throwable - The Throwable to adjust to a ThrowableCause.
      messageSize - The size to truncate the Throwable.getMessage() to, to be able to fit in databases.
      Returns:
      A ThrowableCause based on the given throwable for which the message is truncated to given messageSize.
    • type

      public String type()
      Description copied from interface: Cause
      Returns the type of dead lettering cause. The type can, for example, reflect the fully qualified class name of a Throwable.
      Specified by:
      type in interface Cause
      Returns:
      The type of this dead lettering cause.
    • message

      public String message()
      Description copied from interface: Cause
      A message describing a cause for dead lettering. The message() can, for example, reflect the message of a Throwable.
      Specified by:
      message in interface Cause
      Returns:
      The message describing this cause's reason for dead lettering.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Throwable