Class AbstractReloadableService<T>

    • 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.
      • 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.
    • Constructor Detail

      • AbstractReloadableService

        public AbstractReloadableService()
        Constructor.
    • 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
      • 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:
        getLastSuccessfulReloadInstant in interface ReloadableService<T>
        Returns:
        time when the service was last successfully reloaded
      • getReloadFailureCause

        @Nullable
        public Throwable getReloadFailureCause()
        Gets the reason the last reload failed.
        Specified by:
        getReloadFailureCause in interface ReloadableService<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.
      • 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:
        doDestroy in class AbstractInitializableComponent
      • reload

        public final void reload()
        Reloads the configuration of the service. Whether internal state is maintained between reloads is implementation dependent.
        Specified by:
        reload in interface ReloadableService<T>
      • shouldReload

        protected abstract boolean shouldReload()
        Called by the 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.

        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

        @Nonnull
        @NotEmpty
        protected String getLogPrefix()
        Return a string which is to be prepended to all log messages.
        Returns:
        "Service '<definitionID>' :"