Class ThrownStore

java.lang.Object
org.apache.juneau.rest.stats.ThrownStore

public class ThrownStore extends Object
An in-memory cache of thrown exceptions.

Used for preventing duplication of stack traces in log files and replacing them with small hashes.

See Also:
  • Field Details

    • GLOBAL

      public static final ThrownStore GLOBAL
      Identifies a single global store for the entire JVM.
  • Constructor Details

  • Method Details

    • create

      public static ThrownStore.Builder create(BeanStore beanStore)
      Static creator.
      Parameters:
      beanStore - The bean store to use for creating beans.
      Returns:
      A new builder for this object.
    • create

      public static ThrownStore.Builder create()
      Static creator.
      Returns:
      A new builder for this object.
    • add

      Adds the specified thrown exception to this database.
      Parameters:
      e - The exception to add.
      Returns:
      This object.
    • getStats

      Retrieves the stats for the specified thrown exception.
      Parameters:
      e - The exception.
      Returns:
      A clone of the stats, never null.
    • getStats

      public Optional<ThrownStats> getStats(long hash)
      Retrieves the stack trace information for the exception with the specified hash as calculated by hash(Throwable).
      Parameters:
      hash - The hash of the exception.
      Returns:
      A clone of the stack trace info, never null.
    • getStats

      Returns the list of all stack traces in this database.
      Returns:
      The list of all stack traces in this database, cloned and sorted by count descending.
    • reset

      public void reset()
      Clears out the stack trace cache.
    • hash

      protected long hash(Throwable t)
      Calculates a 32-bit hash for the specified throwable based on the stack trace generated by createStackTrace(Throwable).

      Subclasses can override this method to provide their own implementation.

      Parameters:
      t - The throwable to calculate the stack trace on.
      Returns:
      A calculated hash.
    • createStackTrace

      Converts the stack trace for the specified throwable into a simple list of strings.

      The stack trace elements for the throwable are sent through normalize(StackTraceElement) to convert them to simple strings.

      Parameters:
      t - The throwable to create the stack trace for.
      Returns:
      A modifiable list of strings.
    • include

      protected boolean include(StackTraceElement e)
      Returns true if the specified stack trace element should be included in createStackTrace(Throwable).
      Parameters:
      e - The stack trace element.
      Returns:
      true if the specified stack trace element should be included in createStackTrace(Throwable).
    • normalize

      Converts the specified stack trace element into a normalized string.

      The default implementation simply replaces "\\$.*" with "..." which should take care of stuff like stack trace elements of lambda expressions.

      Parameters:
      e - The stack trace element to convert.
      Returns:
      The converted stack trace element.