Package org.opensaml.core.xml.persist
Class MapLoadSaveManager<T extends XMLObject>
java.lang.Object
org.opensaml.core.xml.persist.AbstractConditionalLoadXMLObjectLoadSaveManager<T>
org.opensaml.core.xml.persist.MapLoadSaveManager<T>
- Type Parameters:
T
- the specific base XML object type being managed
- All Implemented Interfaces:
ConditionalLoadXMLObjectLoadSaveManager<T>
,XMLObjectLoadSaveManager<T>
@NotThreadSafe
public class MapLoadSaveManager<T extends XMLObject>
extends AbstractConditionalLoadXMLObjectLoadSaveManager<T>
Simple implementation of
XMLObjectLoadSaveManager
which uses an in-memory map.-
Field Summary
FieldsModifier and TypeFieldDescriptionThe backing map.Storage to track last modified time of data.private org.slf4j.Logger
Logger. -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstructor.MapLoadSaveManager
(boolean conditionalLoad) Constructor.MapLoadSaveManager
(Map<String, T> map) Constructor.protected
Constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Evaluate whether an object already exists indexed by the supplied key.protected boolean
Check whether the data corresponding to the specified key has been modified since the last timeXMLObjectLoadSaveManager.load(String)
was called for that key.listAll()
Return an iterable of all objects under management, along with their associated index key.listKeys()
Return a set of the index keys of all objects under management.Load a particular object based on the supplied key.boolean
Remove the object indexed by the specified key.void
Save a particular object, indexed by the supplied key.void
Save a particular object, indexed by the supplied key.boolean
Update the key under which a particular object is stored.Methods inherited from class org.opensaml.core.xml.persist.AbstractConditionalLoadXMLObjectLoadSaveManager
clearAllLoadLastModified, clearLoadLastModified, getLoadLastModified, isLoadConditionally, updateLoadLastModified, updateLoadLastModified
-
Field Details
-
log
@Nonnull private org.slf4j.Logger logLogger. -
backingMap
The backing map. -
dataLastModified
Storage to track last modified time of data.
-
-
Constructor Details
-
MapLoadSaveManager
public MapLoadSaveManager()Constructor. -
MapLoadSaveManager
Constructor.- Parameters:
conditionalLoad
- whetherload(String)
should behave as defined inConditionalLoadXMLObjectLoadSaveManager
-
MapLoadSaveManager
Constructor.Note: conditional load is not supported with this option, because of the need to track modify times of items stored in the backing map. Use instead
MapLoadSaveManager(boolean)
.- Parameters:
map
- the backing map
-
MapLoadSaveManager
protected MapLoadSaveManager(@ParameterName(name="map") @Nonnull Map<String, T> map, @ParameterName(name="dataLastModified") @Nonnull Map<String, Instant> lastModifiedMap, @ParameterName(name="conditionalLoad") boolean conditionalLoad) Constructor.- Parameters:
map
- the backing maplastModifiedMap
- the storage for data last modified timesconditionalLoad
- whetherload(String)
should behave as defined inConditionalLoadXMLObjectLoadSaveManager
-
-
Method Details
-
listKeys
Return a set of the index keys of all objects under management.- Returns:
- a set of all indexed keys
- Throws:
IOException
- if there is a fatal error obtaining the keys
-
listAll
Return an iterable of all objects under management, along with their associated index key.- Returns:
- an iterable of all managed objects
- Throws:
IOException
- if there is a fatal error loading the managed objects
-
exists
Evaluate whether an object already exists indexed by the supplied key.- Parameters:
key
- the key of the desired object- Returns:
- true if object exists, false otherwise
- Throws:
IOException
- if there is a fatal error evaluating object existence
-
load
Load a particular object based on the supplied key.- Parameters:
key
- the key of the desired object- Returns:
- the object saved under the specified key, or null if there is no such object
- Throws:
IOException
- if there is a fatal error loading the object
-
save
Save a particular object, indexed by the supplied key.An existing object indexed by the supplied key will not be overwritten. Instead an
IOException
will be thrown. For saving with the overwrite option, seeXMLObjectLoadSaveManager.save(String, XMLObject, boolean)
.- Parameters:
key
- the key under which to index the objectxmlObject
- the object to save- Throws:
IOException
- if there is a fatal error saving the object, or if an object already exists indexed by the supplied key
-
save
Save a particular object, indexed by the supplied key.- Parameters:
key
- the key under which to index the objectxmlObject
- the object to saveoverwrite
- whether or not to overwrite any existing object indexed by the supplied key- Throws:
IOException
- if there is a fatal error saving the object, or if overwrite=false, if an object already exists indexed by the supplied key
-
remove
Remove the object indexed by the specified key.- Parameters:
key
- the key of the object to remove- Returns:
- true if the object was found and successfully removed, false if no such object was found
- Throws:
IOException
- if there was a fatal error removing the object
-
updateKey
Update the key under which a particular object is stored.- Parameters:
currentKey
- the current key under which the object is storednewKey
- the new key under which the object should be stored- Returns:
- true if the object was found under the current key and the key successfully updated, false if no such object was found
- Throws:
IOException
- if there was a fatal error updating the key
-
isUnmodifiedSinceLastLoad
Check whether the data corresponding to the specified key has been modified since the last timeXMLObjectLoadSaveManager.load(String)
was called for that key.- Specified by:
isUnmodifiedSinceLastLoad
in classAbstractConditionalLoadXMLObjectLoadSaveManager<T extends XMLObject>
- Parameters:
key
- the data key- Returns:
- true if the corresponding data has been modified since the last load, false otherwise
- Throws:
IOException
- if there is a fatal error evaluating the last modified status
-