Class BatchMetadataCache<IdentifierType,MetadataType>
java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
net.shibboleth.oidc.metadata.cache.impl.AbstractMetadataCache<IdentifierType,MetadataType>
net.shibboleth.oidc.metadata.cache.impl.BatchMetadataCache<IdentifierType,MetadataType>
- Type Parameters:
IdentifierType- the metadata identifier type.MetadataType- the metadata type.
- All Implemented Interfaces:
MetadataCache<MetadataType>,Component,DestructableComponent,IdentifiableComponent,IdentifiedComponent,InitializableComponent
@ThreadSafe
public class BatchMetadataCache<IdentifierType,MetadataType>
extends AbstractMetadataCache<IdentifierType,MetadataType>
A
metadata cache implementation that supports 'refresh-ahead' semantics for batch
cache updates. Does not support 'read-through' semantics if an entry does not exist in the cache.
The metadata source could either be an aggregate with more than one metadata entry, or a single source which contains a single metadata entry.
Supports the following:
- Batch reloading of metadata from the source using the supplied loading strategy. The cache is wiped and reloaded during each successful refresh cycle.
The schedule for batch metadata reloads are based on:
- If no expiry is set on the metadata source, or one can not be computed, the max refresh delay is used.
- If metadata expiry exists but is less than the min refresh delay, use the min refresh delay.
- If metadata expiry exists and is greater than the min, use the metadata expiry.
Does not support:
- Manual metadata refresh. Reloads only occur via the scheduled task. Supporting manual refresh would require alterations to remove/cancel existing tasks.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classA runnable that triggers a cache reload. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate LoadingStrategyThe function to use to load metadata.private final org.slf4j.LoggerClass logger.private booleanIs a match based on an identifier required? If not, all known metadata will be returned.private DurationRefresh interval used when metadata does not contain any validUntil or cacheDuration information.private DurationFloor, in milliseconds, for the refresh interval.private Function<byte[],List<MetadataType>> How to parse the loaded metadata from the loadingStrategy into a usable metadatatype.private final ReadWriteLockA lock to use when reading from and loading the cache.Determine the expiration time of the source batch loaded metadata.private Predicate<byte[]>Is the raw metadata bytes from the source valid? -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructor.protectedBatchMetadataCache(BatchBackingStore<IdentifierType, MetadataType> store, ScheduledExecutorService executor) Protected constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate DurationcomputeNextRefreshDelay(Instant expectedExpiration) Computes the delay until the next refresh time based on the current metadata's expiration time and the refresh interval floor.private CacheLoadingContextCreate a cache loading context based on the last refresh and last update time of the backing store.protected voidget(CriteriaSet criteria) Get the list of metadata matching the given identifier.protected BatchBackingStore<IdentifierType,MetadataType> Get the backing store.protected LoadingStrategyGet the loading strategy.protected DurationGet the maximum amount of time between refresh intervals.protected DurationGet the minimum amount of time between refreshes.protected Function<byte[],List<MetadataType>> Get the parsing strategy.Get the source metadata expiry strategy.protected Predicate<byte[]>Get the predicate which determines if the source metadata is valid or not.protected booleanIs a match on identifier required?private voidReload the entire backing-store cache using the loading strategy.private voidscheduleNextRefresh(Duration delay) Schedules the next refresh.voidsetLoadingStrategy(LoadingStrategy strategy) Set the strategy used to batch load metadata from a source.voidsetMatchOnIdentifierRequired(boolean required) Set if a match on identifier is required in order to return results.voidsetMaxRefreshDelay(Duration delay) Sets the maximum amount of time between refresh intervals.voidsetMinRefreshDelay(Duration delay) Sets the minimum amount of time between refreshes.voidsetParsingStrategy(Function<byte[], List<MetadataType>> strategy) Set the strategy used to convert raw metadata in bytes to the given metadata type.voidsetSourceMetadataExpiryStrategy(Function<byte[], Instant> strategy) Set a strategy to find the metadata expiry date from a source metadata document as bytes.voidsetSourceMetadataValidPredicate(Predicate<byte[]> predicate) Set the predicate which determines if the source metadata is valid or not.Methods inherited from class net.shibboleth.oidc.metadata.cache.impl.AbstractMetadataCache
doDestroy, errorHandlingWrapper, freshLoad, getCriteriaToIdentifierStrategy, getExecutorService, getIdentifierExtractionStrategy, getLogPrefix, getMetadataFilterStrategy, getMetadataValidPredicate, getRefreshDelayFactor, hasExpired, invalidate, invalidateAll, lookupIdentifier, lookupIndexedIdentifier, newFilterContext, setCriteriaToIdentifierStrategy, setIdentifierExtractionStrategy, setMetadataBeforeRemovalHook, setMetadataFilterStrategy, setMetadataValidPredicate, setRefreshDelayFactor, shouldAttemptRefresh, writeToBackingStoreMethods 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
getId
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
maxRefreshDelay
Refresh interval used when metadata does not contain any validUntil or cacheDuration information. -
minRefreshDelay
Floor, in milliseconds, for the refresh interval. -
loadingStrategy
The function to use to load metadata. -
parsingStrategy
How to parse the loaded metadata from the loadingStrategy into a usable metadatatype. -
sourceMetadataExpiryStrategy
Determine the expiration time of the source batch loaded metadata. -
sourceMetadataValidPredicate
Is the raw metadata bytes from the source valid? -
matchOnIdentifierRequired
private boolean matchOnIdentifierRequiredIs a match based on an identifier required? If not, all known metadata will be returned. Defaults to true - a match on identifier is required. -
readWriteLock
A lock to use when reading from and loading the cache.
-
-
Constructor Details
-
BatchMetadataCache
Constructor.- Parameters:
store- the backing store.
-
BatchMetadataCache
protected BatchMetadataCache(@Nonnull BatchBackingStore<IdentifierType, MetadataType> store, @Nullable ScheduledExecutorService executor) Protected constructor.- Parameters:
store- the backing store.executor- the scheduled executor
-
-
Method Details
-
doInitialize
- Overrides:
doInitializein classAbstractMetadataCache<IdentifierType,MetadataType> - Throws:
ComponentInitializationException
-
setSourceMetadataValidPredicate
Set the predicate which determines if the source metadata is valid or not.- Parameters:
predicate- the predicate.
-
getSourceMetadataValidPredicate
Get the predicate which determines if the source metadata is valid or not.- Returns:
- the predicate.
-
setLoadingStrategy
Set the strategy used to batch load metadata from a source.- Parameters:
strategy- the loading strategy.
-
getLoadingStrategy
Get the loading strategy.- Returns:
- the loading strategy
-
setParsingStrategy
Set the strategy used to convert raw metadata in bytes to the given metadata type.- Parameters:
strategy- the parsing strategy.
-
getParsingStrategy
Get the parsing strategy.- Returns:
- the parsing strategy
-
setSourceMetadataExpiryStrategy
Set a strategy to find the metadata expiry date from a source metadata document as bytes.- Parameters:
strategy- the strategy.
-
getSourceMetadataExpiryStrategy
Get the source metadata expiry strategy.- Returns:
- the source metadata expiry strategy
-
setMatchOnIdentifierRequired
public void setMatchOnIdentifierRequired(boolean required) Set if a match on identifier is required in order to return results. If false and there are no identifiers in the criteria to match on, all cached entries will be returned.- Parameters:
required- does the metadata lookup need to match the given criteria.
-
isMatchOnIdentifierRequired
protected boolean isMatchOnIdentifierRequired()Is a match on identifier required?- Returns:
- true if it is, false otherwise
-
getBackingStore
Get the backing store.Cast the backing store to the type used by this cache type.
- Overrides:
getBackingStorein classAbstractMetadataCache<IdentifierType,MetadataType> - Returns:
- the backing store. Can be null.
-
setMinRefreshDelay
Sets the minimum amount of time between refreshes.- Parameters:
delay- minimum amount of time between refreshes
-
getMinRefreshDelay
Get the minimum amount of time between refreshes.- Returns:
- the minimum refresh delay
-
setMaxRefreshDelay
Sets the maximum amount of time between refresh intervals.- Parameters:
delay- maximum amount of time, in milliseconds, between refresh intervals
-
getMaxRefreshDelay
Get the maximum amount of time between refresh intervals.- Returns:
- the delay maximum amount of time, in milliseconds, between refresh intervals
-
createLoadingContext
Create a cache loading context based on the last refresh and last update time of the backing store.- Returns:
- the cache loading context
-
loadCache
Reload the entire backing-store cache using the loading strategy.Acquires a write lock to prevent loading while the cache is being read from.
- Throws:
MetadataCacheException- on loading error.
-
scheduleNextRefresh
Schedules the next refresh. If the given delay is 0 or null, thenmaxRefreshDelayis used.- Parameters:
delay- The delay before the next refresh.
-
computeNextRefreshDelay
Computes the delay until the next refresh time based on the current metadata's expiration time and the refresh interval floor.- Parameters:
expectedExpiration- the time when the metadata is expected to expire and needs refreshing- Returns:
- delay until the next refresh time
-