Class AbstractBundlePersistenceManager
- java.lang.Object
-
- org.apache.jackrabbit.core.persistence.bundle.AbstractBundlePersistenceManager
-
- All Implemented Interfaces:
CacheAccessListener,CachingPersistenceManager,ConsistencyChecker,IterablePersistenceManager,PersistenceManager
- Direct Known Subclasses:
BundleDbPersistenceManager,BundleFsPersistenceManager,InMemBundlePersistenceManager
public abstract class AbstractBundlePersistenceManager extends Object implements PersistenceManager, CachingPersistenceManager, IterablePersistenceManager, CacheAccessListener, ConsistencyChecker
TheAbstractBundlePersistenceManageracts as base for all persistence managers that store the state in aNodePropBundle.The state and all property states of one node are stored together in one record. Property values of a certain size can be stored outside of the bundle. This currently only works for binary properties. NodeReferences are not included in the bundle since they are addressed by the target id.
Some strings like namespaces and local names are additionally managed by separate indexes. only the index number is serialized to the records which reduces the amount of memory used.
Special treatment is performed for the properties "jcr:uuid", "jcr:primaryType" and "jcr:mixinTypes". As they are also stored in the node state they are not included in the bundle but generated when required.
In order to increase performance, there are two caches being maintained. One is the bundle cache that caches already loaded bundles. The other is the
LRUNodeIdCachethat caches non-existent bundles. This is useful because a lot ofexists(NodeId)calls are issued that would result in a useless persistence lookup if the desired bundle does not exist.Configuration:
- <param name="
bundleCacheSize" value="8"/>
-
-
Field Summary
Fields Modifier and Type Field Description protected PMContextcontextthe persistence manager contextprotected static StringNODEFILENAMEthe prefix of a node fileprotected static StringNODEREFSFILENAMEthe prefix of a node references fileprotected static StringRES_NAME_INDEXthe name of the names-index resourceprotected static StringRES_NS_INDEXthe name of the namespace-index resource-
Fields inherited from interface org.apache.jackrabbit.core.cache.CacheAccessListener
ACCESS_INTERVAL
-
-
Constructor Summary
Constructors Constructor Description AbstractBundlePersistenceManager()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected StringBufferbuildBlobFilePath(StringBuffer buf, PropertyId id, int i)Creates the file path for the given property id and value index that is suitable for storing property values in a filesystem.protected StringBufferbuildNodeFilePath(StringBuffer buf, NodeId id)Creates the file path for the given node id that is suitable for storing node states in a filesystem.protected StringBufferbuildNodeFolderPath(StringBuffer buf, NodeId id)Creates the folder path for the given node id that is suitable for storing states in a filesystem.protected StringBufferbuildNodeReferencesFilePath(StringBuffer buf, NodeId id)Creates the file path for the given references id that is suitable for storing reference states in a filesystem.protected StringBufferbuildPropFilePath(StringBuffer buf, PropertyId id)Creates the folder path for the given property id that is suitable for storing states in a filesystem.voidcacheAccessed(long accessCount)The cache calls this method after a number of cache accesses.
For statistical purposes, the cache access count since the last call is included.ConsistencyReportcheck(String[] uuids, boolean recursive, boolean fix, String lostNFoundId, ConsistencyCheckListener listener)Perform a consistency check of the data.voidcheckConsistency(String[] uuids, boolean recursive, boolean fix)Perform a consistency check of the data.voidclose()Closes the persistence manager.NodeStatecreateNew(NodeId id)Creates a new node state instance with the given id.PropertyStatecreateNew(PropertyId id)Creates a new property state instance with the given id.protected abstract voiddestroy(NodeReferences refs)Deletes the node references from the underlying system.protected abstract voiddestroyBundle(NodePropBundle bundle)Deletes the bundle from the underlying system.voiddisposeCache(Cache cache)Called after the cache is no longer used.protected voidevictBundle(NodeId id)Evicts the bundle withidfrom the bundle cache.booleanexists(NodeId id)Checks whether the identified node exists.booleanexists(PropertyId id)Checks whether the identified property exists.Map<NodeId,NodeInfo>getAllNodeInfos(NodeId after, int maxCount)Get allNodeInfos.protected abstract BLOBStoregetBlobStore()Returns the BLOB store used by this persistence manager.StringgetBundleCacheSize()Returns the size of the bundle cache in megabytes.StringIndexgetNameIndex()Returns the local name indexStringIndexgetNsIndex()Returns the namespace indexvoidinit(PMContext context)Initializes the persistence manager.NodeStateload(NodeId id)Load the persistent members of a node state.PropertyStateload(PropertyId id)Load the persistent members of a property state.protected abstract NodePropBundleloadBundle(NodeId id)Loads a bundle from the underlying system.voidonExternalUpdate(ChangeLog changes)Notifies the persistence manager that an external (cluster) modification occurred.voidsetBundleCacheSize(String bundleCacheSize)Sets the size of the bundle cache in megabytes.voidsetEventChannel(UpdateEventChannel eventChannel)Set the update event channel.voidstore(ChangeLog changeLog)Right now, this iterates over all items in the changelog and calls the individual methods that handle single item states or node references objects.protected abstract voidstore(NodeReferences refs)Stores a node references to the underlying system.protected abstract voidstoreBundle(NodePropBundle bundle)Stores a bundle to the underlying system.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.jackrabbit.core.persistence.IterablePersistenceManager
getAllNodeIds
-
Methods inherited from interface org.apache.jackrabbit.core.persistence.PersistenceManager
existsReferencesTo, loadReferencesTo
-
-
-
-
Field Detail
-
NODEFILENAME
protected static final String NODEFILENAME
the prefix of a node file- See Also:
- Constant Field Values
-
NODEREFSFILENAME
protected static final String NODEREFSFILENAME
the prefix of a node references file- See Also:
- Constant Field Values
-
RES_NAME_INDEX
protected static final String RES_NAME_INDEX
the name of the names-index resource- See Also:
- Constant Field Values
-
RES_NS_INDEX
protected static final String RES_NS_INDEX
the name of the namespace-index resource- See Also:
- Constant Field Values
-
context
protected PMContext context
the persistence manager context
-
-
Method Detail
-
getBundleCacheSize
public String getBundleCacheSize()
Returns the size of the bundle cache in megabytes.- Returns:
- the size of the bundle cache in megabytes.
-
setBundleCacheSize
public void setBundleCacheSize(String bundleCacheSize)
Sets the size of the bundle cache in megabytes. the default is 8.- Parameters:
bundleCacheSize- the bundle cache size in megabytes.
-
buildNodeFolderPath
protected StringBuffer buildNodeFolderPath(StringBuffer buf, NodeId id)
Creates the folder path for the given node id that is suitable for storing states in a filesystem.- Parameters:
buf- buffer to append to ornullid- the id of the node- Returns:
- the buffer with the appended data.
-
buildPropFilePath
protected StringBuffer buildPropFilePath(StringBuffer buf, PropertyId id)
Creates the folder path for the given property id that is suitable for storing states in a filesystem.- Parameters:
buf- buffer to append to ornullid- the id of the property- Returns:
- the buffer with the appended data.
-
buildBlobFilePath
protected StringBuffer buildBlobFilePath(StringBuffer buf, PropertyId id, int i)
Creates the file path for the given property id and value index that is suitable for storing property values in a filesystem.- Parameters:
buf- buffer to append to ornullid- the id of the propertyi- the index of the property value- Returns:
- the buffer with the appended data.
-
buildNodeFilePath
protected StringBuffer buildNodeFilePath(StringBuffer buf, NodeId id)
Creates the file path for the given node id that is suitable for storing node states in a filesystem.- Parameters:
buf- buffer to append to ornullid- the id of the node- Returns:
- the buffer with the appended data.
-
buildNodeReferencesFilePath
protected StringBuffer buildNodeReferencesFilePath(StringBuffer buf, NodeId id)
Creates the file path for the given references id that is suitable for storing reference states in a filesystem.- Parameters:
buf- buffer to append to ornullid- the id of the node- Returns:
- the buffer with the appended data.
-
getNsIndex
public StringIndex getNsIndex()
Returns the namespace index- Returns:
- the namespace index
- Throws:
IllegalStateException- if an error occurs.
-
getNameIndex
public StringIndex getNameIndex()
Returns the local name index- Returns:
- the local name index
- Throws:
IllegalStateException- if an error occurs.
-
onExternalUpdate
public void onExternalUpdate(ChangeLog changes)
Notifies the persistence manager that an external (cluster) modification occurred.- Specified by:
onExternalUpdatein interfaceCachingPersistenceManager- Parameters:
changes- the set of changes of the external modification.
-
getAllNodeInfos
public Map<NodeId,NodeInfo> getAllNodeInfos(NodeId after, int maxCount) throws ItemStateException, RepositoryException
Description copied from interface:IterablePersistenceManagerGet allNodeInfos. A typical application will call this method multiple time, where 'after' is the last row read previously. The maxCount parameter defines the maximum number of node ids returned, 0 meaning no limit. The order of the node ids is specific for the given persistence manager. Items that are added concurrently may not be included.- Specified by:
getAllNodeInfosin interfaceIterablePersistenceManager- Parameters:
after- the lower limit, or null for no limit.maxCount- the maximum number of node infos to return, or 0 for no limit.- Returns:
- a list of all node infos.
- Throws:
ItemStateException- if an error while loading occurs.RepositoryException- if a repository exception occurs.
-
loadBundle
protected abstract NodePropBundle loadBundle(NodeId id) throws ItemStateException
Loads a bundle from the underlying system.- Parameters:
id- the node id of the bundle- Returns:
- the loaded bundle or
nullif the bundle does not exist. - Throws:
ItemStateException- if an error while loading occurs.
-
storeBundle
protected abstract void storeBundle(NodePropBundle bundle) throws ItemStateException
Stores a bundle to the underlying system.- Parameters:
bundle- the bundle to store- Throws:
ItemStateException- if an error while storing occurs.
-
destroyBundle
protected abstract void destroyBundle(NodePropBundle bundle) throws ItemStateException
Deletes the bundle from the underlying system.- Parameters:
bundle- the bundle to destroy- Throws:
ItemStateException- if an error while destroying occurs.
-
destroy
protected abstract void destroy(NodeReferences refs) throws ItemStateException
Deletes the node references from the underlying system.- Parameters:
refs- the node references to destroy.- Throws:
ItemStateException- if an error while destroying occurs.
-
store
protected abstract void store(NodeReferences refs) throws ItemStateException
Stores a node references to the underlying system.- Parameters:
refs- the node references to store.- Throws:
ItemStateException- if an error while storing occurs.
-
getBlobStore
protected abstract BLOBStore getBlobStore()
Returns the BLOB store used by this persistence manager.- Returns:
- BLOB store
-
init
public void init(PMContext context) throws Exception
Initializes the persistence manager. The persistence manager is permanently bound to the given context, and any required external resources are acquired.An appropriate exception is thrown if the persistence manager initialization fails for whatever reason. In this case the state of the persistence manager is undefined and the instance should be discarded. Initializes the internal structures of this abstract persistence manager.
- Specified by:
initin interfacePersistenceManager- Parameters:
context- persistence manager context- Throws:
Exception- if the persistence manager initialization failed
-
close
public void close() throws ExceptionCloses the persistence manager. The consistency of the persistent storage is guaranteed and all acquired resources are released. It is an error to invoke any methods on a closed persistence manager, and implementations are free to enforce this constraint by throwing IllegalStateExceptions in such cases.An appropriate exception is thrown if the persistence manager could not be closed properly. In this case the state of the persistence manager is undefined and the instance should be discarded. Closes the persistence manager, release acquired resources.
- Specified by:
closein interfacePersistenceManager- Throws:
Exception- if the persistence manager failed to close properly
-
load
public NodeState load(NodeId id) throws NoSuchItemStateException, ItemStateException
Load the persistent members of a node state. Loads the state via the appropriate NodePropBundle.- Specified by:
loadin interfacePersistenceManager- Parameters:
id- node id- Returns:
- loaded node state
- Throws:
NoSuchItemStateException- if the node state does not existItemStateException- if another error occurs
-
load
public PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException
Load the persistent members of a property state. Loads the state via the appropriate NodePropBundle.- Specified by:
loadin interfacePersistenceManager- Parameters:
id- property id- Returns:
- loaded property state
- Throws:
NoSuchItemStateException- if the property state does not existItemStateException- if another error occurs
-
exists
public boolean exists(PropertyId id) throws ItemStateException
Checks whether the identified property exists. Loads the state via the appropriate NodePropBundle.- Specified by:
existsin interfacePersistenceManager- Parameters:
id- property id- Returns:
trueif the property exists,falseotherwise- Throws:
ItemStateException- on persistence manager errors
-
exists
public boolean exists(NodeId id) throws ItemStateException
Checks whether the identified node exists. Checks the existence via the appropriate NodePropBundle.- Specified by:
existsin interfacePersistenceManager- Parameters:
id- node id- Returns:
trueif the node exists,falseotherwise- Throws:
ItemStateException- on persistence manager errors
-
createNew
public NodeState createNew(NodeId id)
Creates a new node state instance with the given id.- Specified by:
createNewin interfacePersistenceManager- Parameters:
id- node id- Returns:
- node state instance
-
createNew
public PropertyState createNew(PropertyId id)
Creates a new property state instance with the given id.- Specified by:
createNewin interfacePersistenceManager- Parameters:
id- property id- Returns:
- property state instance
-
store
public void store(ChangeLog changeLog) throws ItemStateException
Right now, this iterates over all items in the changelog and calls the individual methods that handle single item states or node references objects. Properly implemented, this method should ensure that changes are either written completely to the underlying persistence layer, or not at all. Atomically saves the given set of changes.- Specified by:
storein interfacePersistenceManager- Parameters:
changeLog- change log containing states that were changed- Throws:
ItemStateException- if the changes could not be saved
-
checkConsistency
public void checkConsistency(String[] uuids, boolean recursive, boolean fix)
Perform a consistency check of the data. An example are non-existent nodes referenced in a child node entry. The existence of this feature and the scope of the implementation can vary in different PersistenceManager implementations.- Specified by:
checkConsistencyin interfacePersistenceManager- Parameters:
uuids- list of UUIDs of nodes to be checked. if null, all nodes will be checkedrecursive- if true, the tree(s) below the given node(s) will be traversed and checked as wellfix- if true, any problems found that can be repaired will be repaired. if false, no data will be modified, instead all inconsistencies will only get logged
-
setEventChannel
public void setEventChannel(UpdateEventChannel eventChannel)
Description copied from interface:ConsistencyCheckerSet the update event channel. Needed to inform the cluster of any changes made during repairs.- Specified by:
setEventChannelin interfaceConsistencyChecker- Parameters:
eventChannel- the update event channel
-
check
public ConsistencyReport check(String[] uuids, boolean recursive, boolean fix, String lostNFoundId, ConsistencyCheckListener listener) throws RepositoryException
Perform a consistency check of the data. An example are non-existent nodes referenced in a child node entry. The existence of this feature and the scope of the implementation can vary in different PersistenceManager implementations.- Specified by:
checkin interfaceConsistencyChecker- Parameters:
uuids- list of UUIDs of nodes to be checked. if null, all nodes will be checkedrecursive- if true, the tree(s) below the given node(s) will be traversed and checked as wellfix- if true, any problems found that can be repaired will be repaired. if false, no data will be modified, instead all inconsistencies will only get loggedlostNFoundId- node to which to attach orphaned nodes (ornull, in which case orphaned nodes will not get moved); this node should be of a node type that allows adding arbitrary child nodeslistener- to be called on each node that was checked (may benull)- Throws:
RepositoryException
-
evictBundle
protected void evictBundle(NodeId id)
Evicts the bundle withidfrom the bundle cache.- Parameters:
id- the id of the bundle.
-
cacheAccessed
public void cacheAccessed(long accessCount)
Description copied from interface:CacheAccessListenerThe cache calls this method after a number of cache accesses.
For statistical purposes, the cache access count since the last call is included. In normal circumstances this is equal toCacheAccessListener.ACCESS_INTERVAL- Specified by:
cacheAccessedin interfaceCacheAccessListener- Parameters:
accessCount- number of cache accesses since the last call
-
disposeCache
public void disposeCache(Cache cache)
Description copied from interface:CacheAccessListenerCalled after the cache is no longer used.- Specified by:
disposeCachein interfaceCacheAccessListener
-
-