Package org.kiwiproject.dropwizard.error
Class ErrorContextBuilder
- java.lang.Object
-
- org.kiwiproject.dropwizard.error.ErrorContextBuilder
-
public class ErrorContextBuilder extends Object
Builder forErrorContext
implementations.To start building, you call
newInstance()
. After that, there must be at the minimum three methods used:Example for an in-memory H2 version of
ErrorContext
.var serviceDetails = ServiceDetails.from(theHostname, theIpAddress, thePortNumber); var errorContext = ErrorContextBuilder.newInstance() .environment(theDropwizardEnvironment) .serviceDetails(serviceDetails) .buildInMemoryH2();
Example for a JDBI 3 version of
ErrorContext
(using Kiwi'sJdbi3Builders
to build theJdbi
instance).var jdbi = Jdbi3Builders.buildManagedJdbi3( theDropwizardEnvironment, theDataSourceFactory, theHealthCheckName); var serviceDetails = ServiceDetails.from(theHostname,theIpAddress, thePortNumber); var errorContext = ErrorContextBuilder.newInstance() .environment(theDropwizardEnvironment) .serviceDetails (serviceDetails) .buildWithJdbi3(jdbi);
All of the terminal build methods use
DataStoreType
to determine if theErrorContext
instance isshared
(i.e. multiple instances of the same service read and write to the same database) ornot shared
(i.e. each service instance has its own segregated database). You can change the defaults (listed below) by explicitly calling thedataStoreType(DataStoreType)
method with the store type you want. Defaults:buildInMemoryH2()
:DataStoreType.NOT_SHARED
(NOTE: this cannot be overridden)buildWithDataStoreFactory(DataSourceFactory)
- If the database defined by the
DataSourceFactory
is an H2 instance , thenDataStoreType.NOT_SHARED
- Otherwise,
DataStoreType.SHARED
- If the database defined by the
buildWithJdbi3(Jdbi)
:DataStoreType.SHARED
-
-
Constructor Summary
Constructors Constructor Description ErrorContextBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ErrorContext
buildInMemoryH2()
Build anErrorContext
backed by an in-memory H2 database that uses JDBI version 3.ErrorContext
buildWithDataStoreFactory(io.dropwizard.db.DataSourceFactory dataSourceFactory)
Build anErrorContext
using given thedataSourceFactory
that uses JDBI version 3.ErrorContext
buildWithJdbi3(org.jdbi.v3.core.Jdbi jdbi)
Build anErrorContext
that uses JDBI version 3.ErrorContextBuilder
cleanupConfig(CleanupConfig config)
Configures theCleanupApplicationErrorsJob
clean up job.ErrorContextBuilder
dataStoreType(DataStoreType dataStoreType)
Explicitly configures theDataStoreType
to use with this builder.ErrorContextBuilder
environment(io.dropwizard.setup.Environment environment)
Sets the DropwizardEnvironment
to use with this builder.static ErrorContextBuilder
newInstance()
ErrorContextBuilder
serviceDetails(ServiceDetails serviceDetails)
Sets theServiceDetails
to use with this builder.ErrorContextBuilder
skipCleanupJob()
Configures the resultingErrorContext
so that it does not create/register a cleanup job with Dropwizard.ErrorContextBuilder
skipHealthCheck()
Configures the resultingErrorContext
so that it does not create/register a health check with Dropwizard.ErrorContextBuilder
timeWindow(TimeWindow timeWindow)
Configures theTimeWindow
for the health check.ErrorContextBuilder
timeWindowUnit(TemporalUnit timeWindowUnit)
Configures theTemporalUnit
for the health check.ErrorContextBuilder
timeWindowValue(long timeWindowValue)
Configures the length of time for the health check.
-
-
-
Method Detail
-
newInstance
public static ErrorContextBuilder newInstance()
-
environment
public ErrorContextBuilder environment(io.dropwizard.setup.Environment environment)
Sets the DropwizardEnvironment
to use with this builder.- Parameters:
environment
- theEnvironment
- Returns:
- this builder
-
serviceDetails
public ErrorContextBuilder serviceDetails(ServiceDetails serviceDetails)
Sets theServiceDetails
to use with this builder.- Parameters:
serviceDetails
- theServiceDetails
- Returns:
- this builder
-
dataStoreType
public ErrorContextBuilder dataStoreType(DataStoreType dataStoreType)
Explicitly configures theDataStoreType
to use with this builder.- Parameters:
dataStoreType
- theDataStoreType
- Returns:
- this builder
- See Also:
buildInMemoryH2()
,buildWithDataStoreFactory(DataSourceFactory)
,buildWithJdbi3(Jdbi)
- Implementation Note:
- The builder implementations have default values; using this will override those defaults.
-
skipHealthCheck
public ErrorContextBuilder skipHealthCheck()
Configures the resultingErrorContext
so that it does not create/register a health check with Dropwizard.- Returns:
- this builder
-
skipCleanupJob
public ErrorContextBuilder skipCleanupJob()
Configures the resultingErrorContext
so that it does not create/register a cleanup job with Dropwizard.- Returns:
- this builder
-
cleanupConfig
public ErrorContextBuilder cleanupConfig(CleanupConfig config)
Configures theCleanupApplicationErrorsJob
clean up job.- Parameters:
config
- theCleanupConfig
- Returns:
- this builder
-
timeWindow
public ErrorContextBuilder timeWindow(TimeWindow timeWindow)
Configures theTimeWindow
for the health check. If an error occurs within this time window, the health check will report as unhealthy. If there are no errors inside of this window, the health check will report as healthy.- Parameters:
timeWindow
- theTimeWindow
- Returns:
- this builder
- Implementation Note:
- This will override any value set by
timeWindowValue(long)
andtimeWindowUnit(TemporalUnit)
. Also, it will recast the values given in terms ofminutes
.
-
timeWindowValue
public ErrorContextBuilder timeWindowValue(long timeWindowValue)
Configures the length of time for the health check. If an error occurs within this time window, the health check will report as unhealthy. If there are no errors inside of this window, the health check will report as healthy.- Parameters:
timeWindowValue
- the length of time- Returns:
- this builder
- Implementation Note:
- This value will be overwritten/ignored if
timeWindow(TimeWindow)
is invoked.
-
timeWindowUnit
public ErrorContextBuilder timeWindowUnit(TemporalUnit timeWindowUnit)
Configures theTemporalUnit
for the health check. If an error occurs within this time window, the health check will report as unhealthy. If there are no errors inside of this window, the health check will report as healthy.- Parameters:
timeWindowUnit
- theTemporalUnit
- Returns:
- this builder
- Implementation Note:
- This value will be overwritten/ignored if
timeWindow(TimeWindow)
is invoked.
-
buildInMemoryH2
public ErrorContext buildInMemoryH2()
Build anErrorContext
backed by an in-memory H2 database that uses JDBI version 3.- Returns:
- a new
ErrorContext
instance - Implementation Note:
- Always sets dataStoreType to
DataStoreType.NOT_SHARED
, since this builds an in-memory database that can only be accessed from within the service in which it resides.
-
buildWithDataStoreFactory
public ErrorContext buildWithDataStoreFactory(io.dropwizard.db.DataSourceFactory dataSourceFactory)
Build anErrorContext
using given thedataSourceFactory
that uses JDBI version 3.- Parameters:
dataSourceFactory
- the DropwizardDataSourceFactory
- Returns:
- a new
ErrorContext
instance - Implementation Note:
- If you do not invoke
dataStoreType(DataStoreType)
prior to calling this method, this method will attempt to determine whichDataStoreType
it should use by callingApplicationErrorJdbc.dataStoreTypeOf(DataSourceFactory)
.
-
buildWithJdbi3
public ErrorContext buildWithJdbi3(org.jdbi.v3.core.Jdbi jdbi)
Build anErrorContext
that uses JDBI version 3.- Parameters:
jdbi
- theJdbi
instance to use; it must be configured withSqlObjectPlugin
- Returns:
- a new
ErrorContext
instance - Implementation Note:
- If you do not invoke
dataStoreType(DataStoreType)
prior to calling this method, this method will default to using a value ofDataStoreType.SHARED
. Otherwise we would need to open a database connection, inspect the database metadata, etc. to figure out the database, and we don't want to do all this. If you are using an in-memory database, then be sure to configure the data store type before calling.
-
-