Class ApplicationError


  • public class ApplicationError
    extends Object
    Defines an application error that you want to save in a data store.

    You can construct an instance using the provided fluent builder, or you can use one of the static factory convenience methods. The id and numTimesOccurred can only be set via the builder, however.

    One thing to note is that the "persistent host information" must be set if any of the factory methods without host, IP, and port are called. This "persistent host information" contains a host, IP, and port that act as the default value for these factory methods.

    NOTE: Currently only the factory methods perform validation in inputs. We assume clients using the builder will set all values, though the exception-related values may be omitted. For practical usage we are assuming most clients will simply use one of the factory methods, as that has been our own general usage pattern.

    • Constructor Detail

      • ApplicationError

        public ApplicationError()
    • Method Detail

      • getCreatedAtMillis

        public Long getCreatedAtMillis()
        Returns:
        the date/time created in milliseconds since the epoch
      • getUpdatedAtMillis

        public Long getUpdatedAtMillis()
        Returns:
        the date/time updated in milliseconds since the epoch
      • setPersistentHostInformation

        public static void setPersistentHostInformation​(String hostName,
                                                        String ipAddress,
                                                        int port)
        Sets the persistent host name, IP address, and port to use when factory methods without host information are used. Once set, new instances will automatically use these values for hostName, ipAddress, and port when created via the static factory methods.

        Please note this is intended to be called only once at initialization (see the "build*" methods in ErrorContextBuilder. Alas Java does not permit a "set only once" semantic to non-final variables. However, this does allow calling more than once for unit testing purposes.

        Parameters:
        hostName - the persistent host name
        ipAddress - the persistent IP address
        port - the persistent port
        Implementation Note:
        This is synchronized even though it is highly unlikely two threads will be initializing persistent host information at the same time., If you rename this method, you must also update the error message in checkPersistentHostState() for the error message to be correct.
      • clearPersistentHostInformation

        public static void clearPersistentHostInformation()
        Clears out (by nullifying) the persistent host name, IP address, and port.

        This is intended only for unit testing purposes.

        Implementation Note:
        This is synchronized even though it is unlikely two threads will be initializing the persistent host information at the same time.
      • getPersistentHostInformation

        public static PersistentHostInformation getPersistentHostInformation()
        Return the currently set persistent host information.
        Returns:
        the persistent host information
        Implementation Note:
        This is intentionally not synchronized, as it is assumed these values are set once (when an application starts on a specific host and port) and is then never changed during the lifetime of the application. If you change this information, you violate this contract and assume personal responsibility, and all bets are off regarding concurrent modifications. This is why we are suppressing the Sonar rule java:S2886: "Getters and setters should be synchronized in pairs".
      • newUnresolvedError

        public static ApplicationError newUnresolvedError​(String description)
        Create a new unresolved error with one occurrence using only the given description. The returned ApplicationError will not have any exception-related information and those values will all be null.
        Parameters:
        description - a description of the error
        Returns:
        a new instance
      • newUnresolvedError

        public static ApplicationError newUnresolvedError​(String description,
                                                          @Nullable
                                                          Throwable throwable)
        Create a new unresolved error with one occurrence using the given description and cause.
        Parameters:
        description - a description of the error
        throwable - a Throwable that is the cause of this application error
        Returns:
        a new instance
      • newUnresolvedError

        public static ApplicationError newUnresolvedError​(String description,
                                                          String hostName,
                                                          String ipAddress,
                                                          int port,
                                                          @Nullable
                                                          Throwable throwable)
        Create a new unresolved error with one occurrence using the given description, host information, and cause.
        Parameters:
        description - a description of the error
        hostName - the host name on which the error occurred
        ipAddress - the IP address of the host on which the error occurred
        port - the port on which the error occurred
        throwable - a Throwable that is the cause of this application error
        Returns:
        a new instance
      • newError

        public static ApplicationError newError​(String description,
                                                ApplicationError.Resolved resolved,
                                                @Nullable
                                                Throwable throwable)
        Create a new error instance with one occurrence the given description, resolution status, and cause.
        Parameters:
        description - a description of the error
        resolved - is this error resolved?
        throwable - a Throwable that is the cause of this application error
        Returns:
        a new instance
      • newError

        public static ApplicationError newError​(String description,
                                                ApplicationError.Resolved resolved,
                                                String hostName,
                                                String ipAddress,
                                                int port,
                                                @Nullable
                                                Throwable throwable)
        Create a new error instance with one occurrence the given description, resolution status, host information, and cause.
        Parameters:
        description - a description of the error
        resolved - is this error resolved?
        hostName - the host name on which the the error occurred
        ipAddress - the IP address of the host on which the error occurred
        port - the port on which the error occurred
        throwable - a Throwable that is the cause of this application error
        Returns:
        a new instance