Package net.shibboleth.shared.service
Class AbstractReloadableService<T>
java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
net.shibboleth.shared.service.AbstractReloadableService<T>
- Type Parameters:
T- The sort of service this implements.
- All Implemented Interfaces:
Component,DestructableComponent,IdentifiableComponent,IdentifiedComponent,InitializableComponent,UnmodifiableComponent,ReloadableService<T>
- Direct Known Subclasses:
LogbackLoggingService,MockReloadableService,ReloadableSpringService
public abstract class AbstractReloadableService<T>
extends AbstractIdentifiableInitializableComponent
implements ReloadableService<T>, UnmodifiableComponent
Base class for
ReloadableService. This base class will use a background thread that will perform a periodic
check, via shouldReload(), and, if required, invoke the service's reload() method.
This class does not deal with any synchronization; that is left to implementing classes.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classA watcher that determines if a service should be reloaded and does so as appropriate. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanDo we fail immediately if the config is bogus?private TimerTimer used to schedule reload tasks if no external one set.private InstantThe last time the service was reloaded, whether successful or not.private InstantThe last time the service was reloaded successfully.private final org.slf4j.LoggerClass logger.private StringThe log prefix.private DurationTime between one reload check and another.private ThrowableThe cause of the last reload failure, if the last reload failed.private AbstractReloadableService<T>.ServiceReloadTaskWatcher that monitors the set of configuration resources for this service for changes.private TimerTimer used to schedule configuration reload tasks. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidPerforms component specific destruction logic.protected voidThis method checks to ensure that the component ID is not null.protected voiddoReload()Performs the actual reload.Gets the time when the service last attempted to reload.Gets the time when the service was last successfully reloaded.protected StringReturn a string which is to be prepended to all log messages.Gets the time between one reload check and another.Gets the reason the last reload failed.Gets the timer used to schedule configuration reload tasks.booleanDo we fail fast?final 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 booleanCalled by theAbstractReloadableService<T>.ServiceReloadTaskto determine if the service should be reloaded.Methods inherited from class net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
setIdMethods inherited from class net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
ensureId, getId, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentExceptionMethods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent
checkComponentActive, checkSetterPreconditions, destroy, initialize, isDestroyed, isInitializedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.shibboleth.shared.component.IdentifiedComponent
getIdMethods inherited from interface net.shibboleth.shared.component.InitializableComponent
initialize, isInitializedMethods inherited from interface net.shibboleth.shared.service.ReloadableService
getServiceableComponent
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
reloadCheckDelay
Time between one reload check and another. -
reloadTaskTimer
Timer used to schedule configuration reload tasks. -
internalTaskTimer
Timer used to schedule reload tasks if no external one set. -
reloadTask
Watcher that monitors the set of configuration resources for this service for changes. -
lastReloadInstant
The last time the service was reloaded, whether successful or not. -
lastSuccessfulReleaseInstant
The last time the service was reloaded successfully. -
reloadFailureCause
The cause of the last reload failure, if the last reload failed. -
failFast
private boolean failFastDo we fail immediately if the config is bogus? -
logPrefix
The log prefix.
-
-
Constructor Details
-
AbstractReloadableService
public AbstractReloadableService()Constructor.
-
-
Method Details
-
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
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
Gets the timer used to schedule configuration reload tasks.- Returns:
- timer used to schedule configuration reload tasks
-
setReloadTaskTimer
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
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
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
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
This 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<T>.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
-
getLogPrefix
Return a string which is to be prepended to all log messages.- Returns:
- "Service '<definitionID>' :"
-