Class AbstractReloadableService<T>
- java.lang.Object
-
- net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
-
- net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent
-
- net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent
-
- net.shibboleth.utilities.java.support.service.AbstractReloadableService<T>
-
- Type Parameters:
T- The sort of service this implements.
- All Implemented Interfaces:
Component,DestructableComponent,IdentifiableComponent,IdentifiedComponent,InitializableComponent,UnmodifiableComponent,ReloadableService<T>
public abstract class AbstractReloadableService<T> extends AbstractIdentifiableInitializableComponent implements ReloadableService<T>, UnmodifiableComponent
Base class forReloadableService. This base class will use a background thread that will perform a periodic check, viashouldReload(), and, if required, invoke the service'sreload()method.This class does not deal with any synchronization; that is left to implementing classes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classAbstractReloadableService.ServiceReloadTaskA watcher that determines if a service should be reloaded and does so as appropriate.
-
Field Summary
Fields Modifier and Type Field Description private booleanfailFastDo we fail immediately if the config is bogus?private TimerinternalTaskTimerTimer used to schedule reload tasks if no external one set.private InstantlastReloadInstantThe last time the service was reloaded, whether successful or not.private InstantlastSuccessfulReleaseInstantThe last time the service was reloaded successfully.private org.slf4j.LoggerlogClass logger.private StringlogPrefixThe log prefix.private DurationreloadCheckDelayTime between one reload check and another.private ThrowablereloadFailureCauseThe cause of the last reload failure, if the last reload failed.private AbstractReloadableService.ServiceReloadTaskreloadTaskWatcher that monitors the set of configuration resources for this service for changes.private TimerreloadTaskTimerTimer used to schedule configuration reload tasks.
-
Constructor Summary
Constructors Constructor Description AbstractReloadableService()Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voiddoDestroy()Performs component specific destruction logic.protected voiddoInitialize()This method checks to ensure that the component ID is not null.protected voiddoReload()Performs the actual reload.InstantgetLastReloadAttemptInstant()Gets the time when the service last attempted to reload.InstantgetLastSuccessfulReloadInstant()Gets the time when the service was last successfully reloaded.protected StringgetLogPrefix()Return a string which is to be prepended to all log messages.DurationgetReloadCheckDelay()Gets the time between one reload check and another.ThrowablegetReloadFailureCause()Gets the reason the last reload failed.TimergetReloadTaskTimer()Gets the timer used to schedule configuration reload tasks.booleanisFailFast()Do we fail fast?voidreload()Reloads the configuration of the service.voidsetFailFast(boolean value)Sets whether we fail fast.voidsetReloadCheckDelay(Duration delay)Sets the time between one reload check and another.voidsetReloadTaskTimer(Timer timer)Sets the timer used to schedule configuration reload tasks.protected abstract booleanshouldReload()Called by theAbstractReloadableService.ServiceReloadTaskto determine if the service should be reloaded.-
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent
setId
-
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractIdentifiedInitializableComponent
getId
-
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
destroy, initialize, isDestroyed, isInitialized
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.shibboleth.utilities.java.support.component.IdentifiedComponent
getId
-
Methods inherited from interface net.shibboleth.utilities.java.support.component.InitializableComponent
initialize, isInitialized
-
Methods inherited from interface net.shibboleth.utilities.java.support.service.ReloadableService
getServiceableComponent
-
-
-
-
Field Detail
-
log
@Nonnull private final org.slf4j.Logger log
Class logger.
-
reloadCheckDelay
@Nonnull private Duration reloadCheckDelay
Time between one reload check and another.
-
reloadTaskTimer
@Nullable private Timer reloadTaskTimer
Timer used to schedule configuration reload tasks.
-
internalTaskTimer
@Nullable private Timer internalTaskTimer
Timer used to schedule reload tasks if no external one set.
-
reloadTask
@Nullable private AbstractReloadableService.ServiceReloadTask reloadTask
Watcher that monitors the set of configuration resources for this service for changes.
-
lastReloadInstant
@Nullable private Instant lastReloadInstant
The last time the service was reloaded, whether successful or not.
-
lastSuccessfulReleaseInstant
@Nullable private Instant lastSuccessfulReleaseInstant
The last time the service was reloaded successfully.
-
reloadFailureCause
@Nullable private Throwable reloadFailureCause
The cause of the last reload failure, if the last reload failed.
-
failFast
private boolean failFast
Do we fail immediately if the config is bogus?
-
logPrefix
@Nullable private String logPrefix
The log prefix.
-
-
Method Detail
-
getReloadCheckDelay
@Nonnull public Duration getReloadCheckDelay()
Gets the time between one reload check and another. A value of 0 or less indicates that no reloading will be performed.Default value: 0
- Returns:
- time between one reload check and another
-
setReloadCheckDelay
public void setReloadCheckDelay(@Nonnull Duration delay)Sets the time between one reload check and another. A value of 0 or less indicates that no reloading will be performed.This setting cannot be changed after the service has been initialized.
- Parameters:
delay- between one reload check and another
-
getReloadTaskTimer
@Nullable public Timer getReloadTaskTimer()
Gets the timer used to schedule configuration reload tasks.- Returns:
- timer used to schedule configuration reload tasks
-
setReloadTaskTimer
public void setReloadTaskTimer(@Nullable Timer timer)Sets the timer used to schedule configuration reload tasks. This setting can not be changed after the service has been initialized.- Parameters:
timer- timer used to schedule configuration reload tasks
-
getLastReloadAttemptInstant
@Nullable public Instant getLastReloadAttemptInstant()
Gets the time when the service last attempted to reload. If the reload was successful this time should match the time given byReloadableService.getLastSuccessfulReloadInstant().- Specified by:
getLastReloadAttemptInstantin interfaceReloadableService<T>- Returns:
- time when the service last attempted to reload
-
getLastSuccessfulReloadInstant
@Nullable public Instant getLastSuccessfulReloadInstant()
Gets the time when the service was last successfully reloaded. Returns null if the service has never reloaded.- Specified by:
getLastSuccessfulReloadInstantin interfaceReloadableService<T>- Returns:
- time when the service was last successfully reloaded
-
getReloadFailureCause
@Nullable public Throwable getReloadFailureCause()
Gets the reason the last reload failed.- Specified by:
getReloadFailureCausein interfaceReloadableService<T>- Returns:
- reason the last reload failed or null if the last reload was successful
-
isFailFast
public boolean isFailFast()
Do we fail fast?- Returns:
- whether we fail fast.
-
setFailFast
public void setFailFast(boolean value)
Sets whether we fail fast.- Parameters:
value- what to set.
-
doInitialize
protected void doInitialize() throws ComponentInitializationExceptionThis method checks to ensure that the component ID is not null. Performs the initialization of the component. This method is executed within the lock on the object being initialized. The default implementation of this method is a no-op.- Overrides:
doInitializein classAbstractIdentifiedInitializableComponent- Throws:
ComponentInitializationException- thrown if there is a problem initializing the component
-
doDestroy
protected void doDestroy()
Performs component specific destruction logic. This method is executed within the lock on the object being destroyed. The default implementation of this method is a no-op.- Overrides:
doDestroyin classAbstractInitializableComponent
-
reload
public final void reload()
Reloads the configuration of the service. Whether internal state is maintained between reloads is implementation dependent.- Specified by:
reloadin interfaceReloadableService<T>
-
shouldReload
protected abstract boolean shouldReload()
Called by theAbstractReloadableService.ServiceReloadTaskto determine if the service should be reloaded.No lock is held when this method is called, so any locking needed should be handled internally.
- Returns:
- true iff the service should be reloaded
-
doReload
protected void doReload()
Performs the actual reload.No lock is held when this method is called, so any locking needed should be handled internally.
- Throws:
ServiceException- thrown if there is a problem reloading the service
-
-