Class ApplicationError
- java.lang.Object
-
- org.kiwiproject.dropwizard.error.model.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
andnumTimesOccurred
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ApplicationError.Resolved
Indicates whether an ApplicationError is resolved.
-
Constructor Summary
Constructors Constructor Description ApplicationError()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
clearPersistentHostInformation()
Clears out (by nullifying) the persistent host name, IP address, and port.Long
getCreatedAtMillis()
static PersistentHostInformation
getPersistentHostInformation()
Return the currently set persistent host information.Long
getUpdatedAtMillis()
static ApplicationError
newError(String description, ApplicationError.Resolved resolved, String hostName, String ipAddress, int port, Throwable throwable)
Create a new error instance with one occurrence the given description, resolution status, host information, and cause.static ApplicationError
newError(String description, ApplicationError.Resolved resolved, Throwable throwable)
Create a new error instance with one occurrence the given description, resolution status, and cause.static ApplicationError
newUnresolvedError(String description)
Create a new unresolved error with one occurrence using only the given description.static ApplicationError
newUnresolvedError(String description, String hostName, String ipAddress, int port, Throwable throwable)
Create a new unresolved error with one occurrence using the given description, host information, and cause.static ApplicationError
newUnresolvedError(String description, Throwable throwable)
Create a new unresolved error with one occurrence using the given description and cause.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.static void
setPersistentHostInformation(PersistentHostInformation hostInfo)
Overload/alias ofsetPersistentHostInformation(String, String, int)
that accepts aPersistentHostInformation
instance.
-
-
-
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 forhostName
,ipAddress
, andport
when created via the static factory methods.Please note this is intended to be called only once at initialization (see the "
build*
" methods inErrorContextBuilder
. 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 nameipAddress
- the persistent IP addressport
- 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.
-
setPersistentHostInformation
public static void setPersistentHostInformation(PersistentHostInformation hostInfo)
Overload/alias ofsetPersistentHostInformation(String, String, int)
that accepts aPersistentHostInformation
instance.- Parameters:
hostInfo
- the persistent host information- 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 errorthrowable
- 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 errorhostName
- the host name on which the error occurredipAddress
- the IP address of the host on which the error occurredport
- the port on which the error occurredthrowable
- 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 errorresolved
- 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 errorresolved
- is this error resolved?hostName
- the host name on which the the error occurredipAddress
- the IP address of the host on which the error occurredport
- the port on which the error occurredthrowable
- a Throwable that is the cause of this application error- Returns:
- a new instance
-
-