Class FileBackedHTTPMetadataResolver

    • Field Detail

      • log

        @Nonnull
        private final org.slf4j.Logger log
        Class logger.
      • metadataBackupFile

        @Nullable
        private File metadataBackupFile
        File containing the backup of the metadata.
      • initializing

        private boolean initializing
        Flag used to track state of whether currently initializing or not.
      • initializeFromBackupFile

        private boolean initializeFromBackupFile
        Flag indicating whether initialization should first attempt to load metadata from backup file.
      • initializedFromBackupFile

        private boolean initializedFromBackupFile
        Flag indicating whether metadata load during init was from backup file.
      • backupFileInitNextRefreshDelay

        @Nonnull
        private Duration backupFileInitNextRefreshDelay
        Duration after which to schedule next refresh, when initialized from backup file.
    • Constructor Detail

      • FileBackedHTTPMetadataResolver

        public FileBackedHTTPMetadataResolver​(org.apache.http.client.HttpClient client,
                                              String metadataURL,
                                              String backupFilePath)
                                       throws ResolverException
        Constructor.
        Parameters:
        client - HTTP client used to fetch remote metadata
        metadataURL - the URL to fetch the metadata
        backupFilePath - the file that will keep a backup copy of the metadata,
        Throws:
        ResolverException - thrown if the URL is not a valid URL, the metadata can not be retrieved from the URL
      • FileBackedHTTPMetadataResolver

        public FileBackedHTTPMetadataResolver​(Timer backgroundTaskTimer,
                                              org.apache.http.client.HttpClient client,
                                              String metadataURL,
                                              String backupFilePath)
                                       throws ResolverException
        Constructor.
        Parameters:
        client - HTTP client used to fetch remote metadata
        backgroundTaskTimer - timer used to schedule background metadata refresh tasks
        metadataURL - the URL to fetch the metadata
        backupFilePath - the file that will keep a backup copy of the metadata,
        Throws:
        ResolverException - thrown if the URL is not a valid URL, the metadata can not be retrieved from the URL
    • Method Detail

      • isInitializedFromBackupFile

        public boolean isInitializedFromBackupFile()
        Get the flag indicating whether metadata load during initialization was from backup file.
        Returns:
        true if initial load was from backup file, false otherwise
      • isInitializeFromBackupFile

        public boolean isInitializeFromBackupFile()
        Get the flag indicating whether initialization should first attempt to load metadata from backup file, if it exists.

        Defaults to: true.

        Returns:
        true if should initialize from backup file, false otherwise
      • setInitializeFromBackupFile

        public void setInitializeFromBackupFile​(boolean flag)
        Set the flag indicating whether initialization should first attempt to load metadata from backup file, if it exists.

        Defaults to: true.

        Parameters:
        flag - true if should initialize from backup file, false otherwise
      • getBackupFileInitNextRefreshDelay

        @Nonnull
        public Duration getBackupFileInitNextRefreshDelay()
        Get the duration after which to schedule next refresh, when initialized from backup file.

        Defaults to 5s.

        Returns:
        the duration
      • setBackupFileInitNextRefreshDelay

        public void setBackupFileInitNextRefreshDelay​(@Nonnull
                                                      Duration delay)
        Set the duration after which to schedule next refresh, when initialized from backup file.

        Defaults to 5s.

        Parameters:
        delay - the next refresh delay
      • setBackupFile

        protected void setBackupFile​(String backupFilePath)
                              throws ResolverException
        Sets the file used to backup metadata. The given file path is checked to see if it is a read/writable file if it exists or if can be created if it does not exist.
        Parameters:
        backupFilePath - path to the backup file
        Throws:
        ResolverException - thrown if the backup file is not read/writable or creatable
      • validateBackupFile

        protected void validateBackupFile​(File backupFile)
                                   throws ResolverException
        Validate the basic properties of the specified metadata backup file, for example that it exists and/or can be created; that it is not a directory; and that it is readable and writable.
        Parameters:
        backupFile - the file to evaluate
        Throws:
        ResolverException - if file does not pass basic properties required of a metadata backup file
      • fetchMetadata

        protected byte[] fetchMetadata()
                                throws ResolverException
        Gets the metadata document from the remote server.
        Overrides:
        fetchMetadata in class HTTPMetadataResolver
        Returns:
        the metadata from remote server, or null if the metadata document has not changed since the last retrieval
        Throws:
        ResolverException - thrown if there is a problem retrieving the metadata from the remote server
      • computeNextRefreshDelay

        @Nonnull
        protected Duration computeNextRefreshDelay​(@Nullable
                                                   Instant expectedExpiration)
        Computes the delay until the next refresh time based on the current metadata's expiration time and the refresh interval floor.
        Overrides:
        computeNextRefreshDelay in class AbstractReloadingMetadataResolver
        Parameters:
        expectedExpiration - the time when the metadata is expected to expire and need refreshing
        Returns:
        delay until the next refresh time
      • postProcessMetadata

        protected void postProcessMetadata​(byte[] metadataBytes,
                                           Document metadataDom,
                                           XMLObject originalMetadata,
                                           XMLObject filteredMetadata)
                                    throws ResolverException
        Post-processing hook called after new metadata has been unmarshalled, filtered, and the DOM released (from the XMLObject) but before the metadata is saved off. Any exception thrown by this hook will cause the retrieved metadata to be discarded. The default implementation of this method is a no-op
        Overrides:
        postProcessMetadata in class AbstractReloadingMetadataResolver
        Parameters:
        metadataBytes - original raw metadata bytes retrieved via AbstractReloadingMetadataResolver.fetchMetadata()
        metadataDom - original metadata after it has been parsed in to a DOM document
        originalMetadata - original metadata prior to being filtered, with its DOM released
        filteredMetadata - metadata after it has been run through all registered filters and its DOM released
        Throws:
        ResolverException - thrown if there is a problem with the provided data