T
- The sort of service this implements.public abstract class AbstractReloadableService<T> extends AbstractIdentifiableInitializableComponent implements ReloadableService<T>, UnmodifiableComponent
ReloadableService
. This base class will use a background thread that will perform a periodic
check, via shouldReload()
, and, if required, invoke the services reload()
method. Modifier and Type | Class and Description |
---|---|
protected class |
AbstractReloadableService.ServiceReloadTask
A watcher that determines if a service should be reloaded and does so as appropriate.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
failFast
Do we fail immediately if the config is bogus?
|
private Timer |
internalTaskTimer
Timer used to schedule reload tasks if no external one set.
|
private org.joda.time.DateTime |
lastReloadInstant
The last time time the service was reloaded, whether successful or not.
|
private org.joda.time.DateTime |
lastSuccessfulReleaseInstant
The last time the service was reloaded successfully.
|
private org.slf4j.Logger |
log
Class logger.
|
private String |
logPrefix
The log prefix.
|
private long |
reloadCheckDelay
Number of milliseconds between one reload check and another.
|
private Throwable |
reloadFailureCause
The cause of the last reload failure, if the last reload failed.
|
private AbstractReloadableService.ServiceReloadTask |
reloadTask
Watcher that monitors the set of configuration resources for this service for changes.
|
private Timer |
reloadTaskTimer
Timer used to schedule configuration reload tasks.
|
Constructor and Description |
---|
AbstractReloadableService()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
doDestroy()
Performs component specific destruction logic.
|
protected void |
doInitialize()
This method checks to ensure that the component ID is not null.
|
protected void |
doReload()
Performs the actual reload.
|
org.joda.time.DateTime |
getLastReloadAttemptInstant()
Gets the time when the service last attempted to reload.
|
org.joda.time.DateTime |
getLastSuccessfulReloadInstant()
Gets the time when the service was last successfully reloaded.
|
protected String |
getLogPrefix()
Return a string which is to be prepended to all log messages.
|
long |
getReloadCheckDelay()
Gets the number of milliseconds between one reload check and another.
|
Throwable |
getReloadFailureCause()
Gets the reason the last reload failed.
|
Timer |
getReloadTaskTimer()
Gets the timer used to schedule configuration reload tasks.
|
boolean |
isFailFast()
Do we fail fast?
|
void |
reload()
Reloads the configuration of the service.
|
void |
setFailFast(boolean value)
Sets whether we fail fast.
|
void |
setReloadCheckDelay(long delay)
Sets the number of milliseconds between one reload check and another.
|
void |
setReloadTaskTimer(Timer timer)
Sets the timer used to schedule configuration reload tasks.
|
protected abstract boolean |
shouldReload()
Called by the
AbstractReloadableService.ServiceReloadTask to determine if the service should be reloaded. |
setId
getId
destroy, initialize, isDestroyed, isInitialized
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getServiceableComponent
initialize, isInitialized
getId
@Nonnull private final org.slf4j.Logger log
@Duration private long reloadCheckDelay
@Nullable private Timer reloadTaskTimer
@Nullable private Timer internalTaskTimer
@Nullable private AbstractReloadableService.ServiceReloadTask reloadTask
@Nullable private org.joda.time.DateTime lastReloadInstant
@Nullable private org.joda.time.DateTime lastSuccessfulReleaseInstant
@Nullable private Throwable reloadFailureCause
private boolean failFast
public long getReloadCheckDelay()
Default value: 0
public void setReloadCheckDelay(@Duration long delay)
delay
- number of milliseconds between one reload check and another@Nullable public Timer getReloadTaskTimer()
public void setReloadTaskTimer(@Nullable Timer timer)
timer
- timer used to schedule configuration reload tasks@Nullable public org.joda.time.DateTime getLastReloadAttemptInstant()
ReloadableService.getLastSuccessfulReloadInstant()
.getLastReloadAttemptInstant
in interface ReloadableService<T>
@Nullable public org.joda.time.DateTime getLastSuccessfulReloadInstant()
getLastSuccessfulReloadInstant
in interface ReloadableService<T>
@Nullable public Throwable getReloadFailureCause()
getReloadFailureCause
in interface ReloadableService<T>
public boolean isFailFast()
public void setFailFast(boolean value)
value
- what to set.protected void doInitialize() throws ComponentInitializationException
doInitialize
in class AbstractIdentifiedInitializableComponent
ComponentInitializationException
- thrown if there is a problem initializing the componentprotected void doDestroy()
doDestroy
in class AbstractInitializableComponent
public final void reload()
reload
in interface ReloadableService<T>
protected abstract boolean shouldReload()
AbstractReloadableService.ServiceReloadTask
to determine if the service should be reloaded.
No lock is held when this method is called, so any locking needed should be handled internally.
protected void doReload()
No lock is held when this method is called, so any locking needed should be handled internally.
ServiceException
- thrown if there is a problem reloading the serviceCopyright © 1999–2018. All rights reserved.