public abstract class AbstractBundlePersistenceManager extends Object implements PersistenceManager, CachingPersistenceManager, IterablePersistenceManager, CacheAccessListener, ConsistencyChecker
AbstractBundlePersistenceManager
acts as base for all
persistence managers that store the state in a NodePropBundle
.
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
LRUNodeIdCache
that caches non-existent bundles. This is useful
because a lot of exists(NodeId)
calls are issued that would result
in a useless persistence lookup if the desired bundle does not exist.
Configuration:
bundleCacheSize
" value="8"/>
Modifier and Type | Field and Description |
---|---|
protected PMContext |
context
the persistence manager context
|
protected static String |
NODEFILENAME
the prefix of a node file
|
protected static String |
NODEREFSFILENAME
the prefix of a node references file
|
protected static String |
RES_NAME_INDEX
the name of the names-index resource
|
protected static String |
RES_NS_INDEX
the name of the namespace-index resource
|
ACCESS_INTERVAL
Constructor and Description |
---|
AbstractBundlePersistenceManager() |
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
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.
|
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.
|
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.
|
void |
cacheAccessed(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. |
ConsistencyReport |
check(String[] uuids,
boolean recursive,
boolean fix,
String lostNFoundId,
ConsistencyCheckListener listener)
Perform a consistency check of the data.
|
void |
checkConsistency(String[] uuids,
boolean recursive,
boolean fix)
Perform a consistency check of the data.
|
void |
close()
Closes the persistence manager.
|
NodeState |
createNew(NodeId id)
Creates a new node state instance with the given id.
|
PropertyState |
createNew(PropertyId id)
Creates a new property state instance with the given id.
|
protected abstract void |
destroy(NodeReferences refs)
Deletes the node references from the underlying system.
|
protected abstract void |
destroyBundle(NodePropBundle bundle)
Deletes the bundle from the underlying system.
|
void |
disposeCache(Cache cache)
Called after the cache is no longer used.
|
protected void |
evictBundle(NodeId id)
Evicts the bundle with
id from the bundle cache. |
boolean |
exists(NodeId id)
Checks whether the identified node exists.
|
boolean |
exists(PropertyId id)
Checks whether the identified property exists.
|
Map<NodeId,NodeInfo> |
getAllNodeInfos(NodeId after,
int maxCount)
Get all
NodeInfo s. |
protected abstract BLOBStore |
getBlobStore()
Returns the BLOB store used by this persistence manager.
|
String |
getBundleCacheSize()
Returns the size of the bundle cache in megabytes.
|
StringIndex |
getNameIndex()
Returns the local name index
|
StringIndex |
getNsIndex()
Returns the namespace index
|
void |
init(PMContext context)
Initializes the persistence manager.
|
NodeState |
load(NodeId id)
Load the persistent members of a node state.
|
PropertyState |
load(PropertyId id)
Load the persistent members of a property state.
|
protected abstract NodePropBundle |
loadBundle(NodeId id)
Loads a bundle from the underlying system.
|
void |
onExternalUpdate(ChangeLog changes)
Notifies the persistence manager that an external (cluster) modification
occurred.
|
void |
setBundleCacheSize(String bundleCacheSize)
Sets the size of the bundle cache in megabytes.
|
void |
setEventChannel(UpdateEventChannel eventChannel)
Set the update event channel.
|
void |
store(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 void |
store(NodeReferences refs)
Stores a node references to the underlying system.
|
protected abstract void |
storeBundle(NodePropBundle bundle)
Stores a bundle to the underlying system.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAllNodeIds
existsReferencesTo, loadReferencesTo
protected static final String NODEFILENAME
protected static final String NODEREFSFILENAME
protected static final String RES_NAME_INDEX
protected static final String RES_NS_INDEX
protected PMContext context
public String getBundleCacheSize()
public void setBundleCacheSize(String bundleCacheSize)
bundleCacheSize
- the bundle cache size in megabytes.protected StringBuffer buildNodeFolderPath(StringBuffer buf, NodeId id)
buf
- buffer to append to or null
id
- the id of the nodeprotected StringBuffer buildPropFilePath(StringBuffer buf, PropertyId id)
buf
- buffer to append to or null
id
- the id of the propertyprotected StringBuffer buildBlobFilePath(StringBuffer buf, PropertyId id, int i)
buf
- buffer to append to or null
id
- the id of the propertyi
- the index of the property valueprotected StringBuffer buildNodeFilePath(StringBuffer buf, NodeId id)
buf
- buffer to append to or null
id
- the id of the nodeprotected StringBuffer buildNodeReferencesFilePath(StringBuffer buf, NodeId id)
buf
- buffer to append to or null
id
- the id of the nodepublic StringIndex getNsIndex()
IllegalStateException
- if an error occurs.public StringIndex getNameIndex()
IllegalStateException
- if an error occurs.public void onExternalUpdate(ChangeLog changes)
onExternalUpdate
in interface CachingPersistenceManager
changes
- the set of changes of the external modification.public Map<NodeId,NodeInfo> getAllNodeInfos(NodeId after, int maxCount) throws ItemStateException, RepositoryException
IterablePersistenceManager
NodeInfo
s.
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.getAllNodeInfos
in interface IterablePersistenceManager
after
- the lower limit, or null for no limit.maxCount
- the maximum number of node infos to return, or 0 for no limit.ItemStateException
- if an error while loading occurs.RepositoryException
- if a repository exception occurs.protected abstract NodePropBundle loadBundle(NodeId id) throws ItemStateException
id
- the node id of the bundlenull
if the bundle does not
exist.ItemStateException
- if an error while loading occurs.protected abstract void storeBundle(NodePropBundle bundle) throws ItemStateException
bundle
- the bundle to storeItemStateException
- if an error while storing occurs.protected abstract void destroyBundle(NodePropBundle bundle) throws ItemStateException
bundle
- the bundle to destroyItemStateException
- if an error while destroying occurs.protected abstract void destroy(NodeReferences refs) throws ItemStateException
refs
- the node references to destroy.ItemStateException
- if an error while destroying occurs.protected abstract void store(NodeReferences refs) throws ItemStateException
refs
- the node references to store.ItemStateException
- if an error while storing occurs.protected abstract BLOBStore getBlobStore()
public void init(PMContext context) throws Exception
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.
init
in interface PersistenceManager
context
- persistence manager contextException
- if the persistence manager initialization failedpublic void close() throws Exception
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.
close
in interface PersistenceManager
Exception
- if the persistence manager failed to close properlypublic NodeState load(NodeId id) throws NoSuchItemStateException, ItemStateException
load
in interface PersistenceManager
id
- node idNoSuchItemStateException
- if the node state does not existItemStateException
- if another error occurspublic PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException
load
in interface PersistenceManager
id
- property idNoSuchItemStateException
- if the property state does not existItemStateException
- if another error occurspublic boolean exists(PropertyId id) throws ItemStateException
exists
in interface PersistenceManager
id
- property idtrue
if the property exists,
false
otherwiseItemStateException
- on persistence manager errorspublic boolean exists(NodeId id) throws ItemStateException
exists
in interface PersistenceManager
id
- node idtrue
if the node exists,
false
otherwiseItemStateException
- on persistence manager errorspublic NodeState createNew(NodeId id)
createNew
in interface PersistenceManager
id
- node idpublic PropertyState createNew(PropertyId id)
createNew
in interface PersistenceManager
id
- property idpublic void store(ChangeLog changeLog) throws ItemStateException
store
in interface PersistenceManager
changeLog
- change log containing states that were changedItemStateException
- if the changes could not be savedpublic void checkConsistency(String[] uuids, boolean recursive, boolean fix)
checkConsistency
in interface PersistenceManager
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 loggedpublic void setEventChannel(UpdateEventChannel eventChannel)
ConsistencyChecker
setEventChannel
in interface ConsistencyChecker
eventChannel
- the update event channelpublic ConsistencyReport check(String[] uuids, boolean recursive, boolean fix, String lostNFoundId, ConsistencyCheckListener listener) throws RepositoryException
check
in interface ConsistencyChecker
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 (or null
,
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 be null
)RepositoryException
protected void evictBundle(NodeId id)
id
from the bundle cache.id
- the id of the bundle.public void cacheAccessed(long accessCount)
CacheAccessListener
CacheAccessListener.ACCESS_INTERVAL
cacheAccessed
in interface CacheAccessListener
accessCount
- number of cache accesses since the last callpublic void disposeCache(Cache cache)
CacheAccessListener
disposeCache
in interface CacheAccessListener
Copyright © 2004–2021 The Apache Software Foundation. All rights reserved.