|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.opensaml.saml2.metadata.provider.BaseMetadataProvider org.opensaml.saml2.metadata.provider.AbstractMetadataProvider org.opensaml.saml2.metadata.provider.AbstractObservableMetadataProvider org.opensaml.saml2.metadata.provider.AbstractReloadingMetadataProvider
public abstract class AbstractReloadingMetadataProvider
Base class for metadata providers that cache and periodically refresh their metadata.
This metadata provider periodically checks to see if the read metadata file has changed. The delay between each
refresh interval is calculated as follows. If no validUntil or cacheDuration is present then the
getMaxRefreshDelay()
value is used. Otherwise, the earliest refresh interval of the metadata file is checked
by looking for the earliest of all the validUntil attributes and cacheDuration attributes. If that refresh interval
is larger than the max refresh delay then getMaxRefreshDelay()
is used. If that number is smaller than the
min refresh delay then getMinRefreshDelay()
is used. Otherwise the calculated refresh delay multiplied by
getRefreshDelayFactor()
is used. By using this factor, the provider will attempt to be refresh before the
cache actually expires, allowing a some room for error and recovery. Assuming the factor is not exceedingly close to
1.0 and a min refresh delay that is not overly large, this refresh will likely occur a few times before the cache
expires.
Nested Class Summary | |
---|---|
private class |
AbstractReloadingMetadataProvider.RefreshMetadataTask
Background task that refreshes metadata. |
Nested classes/interfaces inherited from interface org.opensaml.saml2.metadata.provider.ObservableMetadataProvider |
---|
ObservableMetadataProvider.Observer |
Field Summary | |
---|---|
private XMLObject |
cachedMetadata
Last successfully read in metadata. |
private boolean |
createdOwnTaskTimer
Whether we created our own task timer during object construction. |
private org.joda.time.DateTime |
expirationTime
Time when the currently cached metadata file expires. |
private org.joda.time.DateTime |
lastRefresh
Last time a refresh cycle occurred. |
private org.joda.time.DateTime |
lastUpdate
Last time the metadata was updated. |
private org.slf4j.Logger |
log
Class logger. |
private long |
maxRefreshDelay
Refresh interval used when metadata does not contain any validUntil or cacheDuration information. |
private int |
minRefreshDelay
Floor, in milliseconds, for the refresh interval. |
private org.joda.time.DateTime |
nextRefresh
Next time a refresh cycle will occur. |
private float |
refreshDelayFactor
Factor used to compute when the next refresh interval will occur. |
private AbstractReloadingMetadataProvider.RefreshMetadataTask |
refresMetadataTask
Current task to refresh metadata. |
private Timer |
taskTimer
Timer used to schedule background metadata update tasks. |
Fields inherited from class org.opensaml.saml2.metadata.provider.BaseMetadataProvider |
---|
unmarshallerFactory |
Constructor Summary | |
---|---|
protected |
AbstractReloadingMetadataProvider()
Constructor. |
protected |
AbstractReloadingMetadataProvider(Timer backgroundTaskTimer)
Constructor. |
Method Summary | |
---|---|
protected long |
computeNextRefreshDelay(org.joda.time.DateTime expectedExpiration)
Computes the delay until the next refresh time based on the current metadata's expiration time and the refresh interval floor. |
void |
destroy()
Destroys the metadata provider and frees any resources current held by it. |
protected XMLObject |
doGetMetadata()
Gets the metadata currently held by the provider. |
protected void |
doInitialization()
Subclasses should override this method to perform any initialization logic necessary. |
protected abstract byte[] |
fetchMetadata()
Fetches metadata from a source. |
org.joda.time.DateTime |
getExpirationTime()
Gets the time when the currently cached metadata expires. |
org.joda.time.DateTime |
getLastRefresh()
Gets the time the last refresh cycle occurred. |
org.joda.time.DateTime |
getLastUpdate()
Gets the time that the currently available metadata was last updated. |
long |
getMaxRefreshDelay()
Gets the maximum amount of time, in milliseconds, between refresh intervals. |
protected abstract String |
getMetadataIdentifier()
Gets an identifier which may be used to distinguish this metadata in logging statements. |
int |
getMinRefreshDelay()
Gets the minimum amount of time, in milliseconds, between refreshes. |
org.joda.time.DateTime |
getNextRefresh()
Gets the time when the next refresh cycle will occur. |
float |
getRefreshDelayFactor()
Gets the delay factor used to compute the next refresh time. |
protected byte[] |
inputstreamToByteArray(InputStream ins)
Converts an InputStream into a byte array. |
protected void |
postProcessMetadata(byte[] metadataBytes,
Document metadataDom,
XMLObject metadata)
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. |
protected void |
processCachedMetadata(String metadataIdentifier,
org.joda.time.DateTime refreshStart)
Processes a cached metadata document in order to determine, and schedule, the next time it should be refreshed. |
protected void |
processNewMetadata(String metadataIdentifier,
org.joda.time.DateTime refreshStart,
byte[] metadataBytes)
Process a new metadata document. |
protected void |
processNonExpiredMetadata(String metadataIdentifier,
org.joda.time.DateTime refreshStart,
byte[] metadataBytes,
XMLObject metadata)
Processes metadata that has been determined to be valid at the time it was fetched. |
protected void |
processPreExpiredMetadata(String metadataIdentifier,
org.joda.time.DateTime refreshStart,
byte[] metadataBytes,
XMLObject metadata)
Processes metadata that has been determined to be invalid (usually because it's already expired) at the time it was fetched. |
void |
refresh()
Refreshes the metadata from its source. |
void |
setMaxRefreshDelay(long delay)
Sets the maximum amount of time, in milliseconds, between refresh intervals. |
void |
setMinRefreshDelay(int delay)
Sets the minimum amount of time, in milliseconds, between refreshes. |
void |
setRefreshDelayFactor(float factor)
Sets the delay factor used to compute the next refresh time. |
protected XMLObject |
unmarshallMetadata(byte[] metadataBytes)
Unmarshalls the given metadata bytes. |
Methods inherited from class org.opensaml.saml2.metadata.provider.AbstractObservableMetadataProvider |
---|
emitChangeEvent, getObservers |
Methods inherited from class org.opensaml.saml2.metadata.provider.AbstractMetadataProvider |
---|
clearDescriptorIndex, doGetEntitiesDescriptor, doGetEntityDescriptor, doGetRole, doGetRole, filterMetadata, getEntitiesDescriptor, getEntitiesDescriptorByName, getEntityDescriptor, getEntityDescriptorById, getEntityDescriptorById, getMetadata, getParserPool, getRole, getRole, initialize, isFailFastInitialization, isInitialized, isValid, releaseMetadataDOM, setFailFastInitialization, setInitialized, setParserPool, unmarshallMetadata |
Methods inherited from class org.opensaml.saml2.metadata.provider.BaseMetadataProvider |
---|
getMetadataFilter, requireValidMetadata, setMetadataFilter, setRequireValidMetadata |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.opensaml.saml2.metadata.provider.MetadataProvider |
---|
getEntitiesDescriptor, getEntityDescriptor, getMetadata, getMetadataFilter, getRole, getRole, requireValidMetadata, setMetadataFilter, setRequireValidMetadata |
Field Detail |
---|
private final org.slf4j.Logger log
private Timer taskTimer
private boolean createdOwnTaskTimer
private AbstractReloadingMetadataProvider.RefreshMetadataTask refresMetadataTask
private float refreshDelayFactor
private long maxRefreshDelay
private int minRefreshDelay
private org.joda.time.DateTime expirationTime
private org.joda.time.DateTime lastUpdate
private org.joda.time.DateTime lastRefresh
private org.joda.time.DateTime nextRefresh
private XMLObject cachedMetadata
Constructor Detail |
---|
protected AbstractReloadingMetadataProvider()
protected AbstractReloadingMetadataProvider(Timer backgroundTaskTimer)
backgroundTaskTimer
- time used to schedule background refresh tasksMethod Detail |
---|
public org.joda.time.DateTime getExpirationTime()
public org.joda.time.DateTime getLastUpdate()
getLastRefresh()
if the metadata was known not to have changed during the last refresh
cycle.
public org.joda.time.DateTime getLastRefresh()
public org.joda.time.DateTime getNextRefresh()
public long getMaxRefreshDelay()
public void setMaxRefreshDelay(long delay)
delay
- maximum amount of time, in milliseconds, between refresh intervalspublic float getRefreshDelayFactor()
public void setRefreshDelayFactor(float factor)
factor
- delay factor used to compute the next refresh timepublic int getMinRefreshDelay()
public void setMinRefreshDelay(int delay)
delay
- minimum amount of time, in milliseconds, between refreshespublic void destroy()
destroy
in class AbstractObservableMetadataProvider
protected XMLObject doGetMetadata() throws MetadataProviderException
doGetMetadata
in class AbstractMetadataProvider
MetadataProviderException
- thrown if there is a problem retrieving the metadataprotected void doInitialization() throws MetadataProviderException
doInitialization
in class AbstractMetadataProvider
MetadataProviderException
- thrown if there is a problem initializing the providerpublic void refresh() throws MetadataProviderException
MetadataProviderException
- thrown is there is a problem retrieving and processing the metadataprotected abstract String getMetadataIdentifier()
protected abstract byte[] fetchMetadata() throws MetadataProviderException
MetadataProviderException
- thrown if there is a problem fetching the metadataprotected XMLObject unmarshallMetadata(byte[] metadataBytes) throws MetadataProviderException
metadataBytes
- raw metadata bytes
MetadataProviderException
- thrown if the metadata can not be unmarshalledprotected void processCachedMetadata(String metadataIdentifier, org.joda.time.DateTime refreshStart) throws MetadataProviderException
metadataIdentifier
- identifier of the metadata sourcerefreshStart
- when the current refresh cycle started
MetadataProviderException
- throw is there is a problem process the cached metadataprotected void processNewMetadata(String metadataIdentifier, org.joda.time.DateTime refreshStart, byte[] metadataBytes) throws MetadataProviderException
metadataIdentifier
- identifier of the metadata sourcerefreshStart
- when the current refresh cycle startedmetadataBytes
- raw bytes of the new metadata document
MetadataProviderException
- thrown if there is a problem unmarshalling or filtering the new metadataprotected void processPreExpiredMetadata(String metadataIdentifier, org.joda.time.DateTime refreshStart, byte[] metadataBytes, XMLObject metadata)
AbstractMetadataProvider.isValid(XMLObject)
method.
metadataIdentifier
- identifier of the metadata sourcerefreshStart
- when the current refresh cycle startedmetadataBytes
- raw bytes of the new metadata documentmetadata
- new metadata document unmarshalledprotected void processNonExpiredMetadata(String metadataIdentifier, org.joda.time.DateTime refreshStart, byte[] metadataBytes, XMLObject metadata) throws MetadataProviderException
AbstractMetadataProvider.isValid(XMLObject)
method.
metadataIdentifier
- identifier of the metadata sourcerefreshStart
- when the current refresh cycle startedmetadataBytes
- raw bytes of the new metadata documentmetadata
- new metadata document unmarshalled
MetadataProviderException
- thrown if there s a problem processing the metadataprotected void postProcessMetadata(byte[] metadataBytes, Document metadataDom, XMLObject metadata) throws MetadataProviderException
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
metadataBytes
- raw metadata bytes retrieved via fetchMetadata()
metadataDom
- metadata after it has been parsed in to a DOM documentmetadata
- metadata after it has been run through all registered filters and its DOM released
MetadataProviderException
- thrown if there is a problem with the provided dataprotected long computeNextRefreshDelay(org.joda.time.DateTime expectedExpiration)
expectedExpiration
- the time when the metadata is expected to expire and need refreshing
protected byte[] inputstreamToByteArray(InputStream ins) throws MetadataProviderException
ins
- input stream to convert
MetadataProviderException
- thrown if there is a problem reading the resultant byte array
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |