@ThreadSafe public class LazyCachedNode extends Object implements CachedNode
CachedNode
implementation that lazily loads its content. Technically each instance
modifies its internal state, but most of the state is based upon a single Document that is read-in only once and never changed
again. And thus externally each instance appears to be immutable and invariant, except anything that has to do with this node's
getName(NodeCache)
(e.g., segment
, and the path
{
methods
). That's because the name of this node is actually stored on the parent in the
parent's child references
, and this node's name, SNS index, and thus the path can all
change even though none of the information stored in this node's document will actually change.
The WorkspaceCache
that keeps these LazyCachedNode
instances is intended to be a cache of the persisted nodes,
and thus are accessed by all sessions for that workspace. When a persisted node is changed, the corresponding
CachedNode
is purged from the WorkspaceCache
. Therefore, these LazyCachedNode's must be able to be accessed
concurrently from multiple threads; this is the reason why all of the lazily-populated fields are either atomic references or
volatile. (Since all of these lazily-populated members are idempotent, the implementations do this properly without
synchronization or blocking. The exception is the parentRefToSelf
field, which can change but is done so in an atomic
fashion (see parentReferenceToSelf(WorkspaceCache)
for details).
Modifier and Type | Class and Description |
---|---|
protected static class |
LazyCachedNode.NonRootParentReferenceToSelf
A
LazyCachedNode.ParentReferenceToSelf implementation that caches the ChildReference from the parent plus the actual
parent (via a weak reference to the CachedNode . |
protected static interface |
LazyCachedNode.ParentReferenceToSelf
A single object used to cache the parent's
ChildReference that points to this node and methods that determine
whether this cached information is still valid. |
protected static class |
LazyCachedNode.RootParentReferenceToSelf
A
LazyCachedNode.ParentReferenceToSelf implementation used only for the root node. |
CachedNode.Properties, CachedNode.ReferenceType
Constructor and Description |
---|
LazyCachedNode(NodeKey key,
Document document) |
Modifier and Type | Method and Description |
---|---|
protected Document |
document()
Get the
Document that represents this node. |
boolean |
equals(Object obj) |
Set<NodeKey> |
getAdditionalParentKeys(NodeCache cache)
Get the keys for all of the nodes (other than the
primary parent ) under which this node
appears. |
ChildReferences |
getChildReferences(NodeCache cache)
Get the set of child references for this node.
|
int |
getDepth(NodeCache cache)
Get the depth of this node.
|
NodeKey |
getKey()
Get the key for the node.
|
Set<Name> |
getMixinTypes(NodeCache cache)
Get the set of mixin types for this node.
|
Name |
getName(NodeCache cache)
Get the name for this node, without any same-name-sibiling (SNS) index.
|
NodeKey |
getParentKey(NodeCache cache)
Get the node key for this node's primary parent within this workspace.
|
NodeKey |
getParentKeyInAnyWorkspace(NodeCache cache)
Get the node key for this node's primary parent in any workspace.
|
Path |
getPath(NodeCache cache)
Get the path to this node.
|
Path |
getPath(PathCache pathCache)
Get the path to this node.
|
Map<String,Set<String>> |
getPermissions(NodeCache cache)
Gets the map of privileges by principal name which are in effect for this node.
|
Name |
getPrimaryType(NodeCache cache)
Get the primary type for this node.
|
Iterator<Property> |
getProperties(Collection<?> namePatterns,
NodeCache cache)
Get an iterator over all of the properties of this node that have names matching at least one of the supplied patterns.
|
Iterator<Property> |
getProperties(NodeCache cache)
Get an iterator over all of the node's properties.
|
CachedNode.Properties |
getPropertiesByName(NodeCache cache)
Get the properties collection.
|
Property |
getProperty(Name name,
NodeCache cache)
Get the property with the given name.
|
int |
getPropertyCount(NodeCache cache)
Determine the number of properties that this node contains.
|
ReferrerCounts |
getReferrerCounts(NodeCache cache)
Get a snapshot of the referrers that have REFERENCE and/or WEAK_REFERENCE properties pointing to this node.
|
Set<NodeKey> |
getReferrers(NodeCache cache,
CachedNode.ReferenceType type)
Get the keys of the nodes that have JCR REFERENCE and/or WEAK_REFERENCE properties pointing to this node.
|
Path.Segment |
getSegment(NodeCache cache)
Get the path segment for this node.
|
protected Path.Segment |
getSegment(WorkspaceCache cache)
Get the name for this node, without any same-name-sibiling (SNS) index.
|
String |
getString(NamespaceRegistry registry) |
boolean |
hasACL(NodeCache cache)
Determine if there is an access control list for this node only, not taking into account any possible parents.
|
int |
hashCode() |
boolean |
hasProperties(NodeCache cache)
Determine if the node contains one or more properties.
|
boolean |
hasProperty(Name name,
NodeCache cache)
Determine if the node contains a property with the specified name.
|
boolean |
isAtOrBelow(NodeCache cache,
Path path)
Determine if this node is effectively at or below the supplied path.
|
boolean |
isExcludedFromSearch(NodeCache cache)
Determine if this node and *all* of its children should be taken into account when searching/indexing or not.
|
boolean |
isExternal(NodeCache cache)
Determine if this node belongs to an external source (via federation) or is local to the repository.
|
protected CachedNode |
parent(WorkspaceCache cache) |
protected ChildReference |
parentReferenceToSelf(WorkspaceCache cache)
Get the parent node's child reference to this node.
|
protected Map<Name,Property> |
properties() |
String |
toString() |
protected WorkspaceCache |
workspaceCache(NodeCache cache) |
protected final WorkspaceCache workspaceCache(NodeCache cache)
protected Document document()
Document
that represents this node.NodeNotFoundException
- if this node no longer existspublic NodeKey getParentKey(NodeCache cache)
CachedNode
getParentKey
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullpublic NodeKey getParentKeyInAnyWorkspace(NodeCache cache)
CachedNode
getParentKeyInAnyWorkspace
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullpublic Set<NodeKey> getAdditionalParentKeys(NodeCache cache)
CachedNode
primary parent
) under which this node
appears.getAdditionalParentKeys
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullpublic boolean isAtOrBelow(NodeCache cache, Path path)
CachedNode
additional parents
, a node has multiple effective paths.isAtOrBelow
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullpath
- the path to be used for comparison; may not be nullprotected CachedNode parent(WorkspaceCache cache)
protected ChildReference parentReferenceToSelf(WorkspaceCache cache)
parentRefToSelf
object is still up-to-date with the parent node's cached representation. If it is not still valid, then it will be
recomputed.
This method is carefully written to always return an atomically-consistent result without requiring any locking or synchronization. Generally speaking, at any given moment the cached information is idempotent, so we rely upon that and use an AtomicReference to ensure that the reference is updated atomically. The method implementation also reads the AtomicReference only once before deciding what to do; this means that multiple threads can concurrently call this method and it will always return the correct information.
cache
- the cacheNodeNotFoundInParentException
- if this node is no longer referenced by its parent as a child of the parent node
(which can happen if this node is used while in the midst of being (re)moved.public NodeKey getKey()
CachedNode
getKey
in interface CachedNode
public Name getName(NodeCache cache)
CachedNode
getName
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullCachedNode.getSegment(NodeCache)
,
CachedNode.getPath(NodeCache)
public Path.Segment getSegment(NodeCache cache)
CachedNode
getSegment
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullCachedNode.getName(NodeCache)
,
CachedNode.getPath(NodeCache)
protected Path.Segment getSegment(WorkspaceCache cache)
cache
- the workspace cache to which this node belongs, required in case this node needs to use the cache; may not be
nullNodeNotFoundInParentException
- if this node no longer existsgetSegment(NodeCache)
,
getPath(NodeCache)
public Path getPath(NodeCache cache)
CachedNode
getPath
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullCachedNode.getName(NodeCache)
,
CachedNode.getSegment(NodeCache)
public Path getPath(PathCache pathCache) throws NodeNotFoundException
CachedNode
getPath
in interface CachedNode
pathCache
- the cache of paths that can be used to compute the path for any node; may not be nullNodeNotFoundInParentException
- if this node no longer exists inside the parent node (and perhaps in no other parent)NodeNotFoundException
- if this node no longer existsCachedNode.getName(NodeCache)
,
CachedNode.getSegment(NodeCache)
public int getDepth(NodeCache cache) throws NodeNotFoundException
CachedNode
/foo
", 2 for "/foo/bar
", etc.), although this method will likely compute the depth more efficiently
that finding the path and asking for the number of segments.
The depth is calculated based upon the primary parent (and primary path
). This is, although
shared nodes are accessible at multiple paths, only the primary path is used to determine the depth of the node.
getDepth
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullNodeNotFoundException
- if this node no longer existspublic Name getPrimaryType(NodeCache cache)
CachedNode
getPrimaryType
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullpublic Set<Name> getMixinTypes(NodeCache cache)
CachedNode
getMixinTypes
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullpublic int getPropertyCount(NodeCache cache)
CachedNode
getPropertyCount
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullpublic boolean hasProperties(NodeCache cache)
CachedNode
hasProperties
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullpublic boolean hasProperty(Name name, NodeCache cache)
CachedNode
hasProperty
in interface CachedNode
name
- the name of the propertycache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullpublic Property getProperty(Name name, NodeCache cache)
CachedNode
getProperty
in interface CachedNode
name
- the name of the propertycache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullpublic CachedNode.Properties getPropertiesByName(NodeCache cache)
CachedNode
getPropertiesByName
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullpublic Iterator<Property> getProperties(NodeCache cache)
CachedNode
getProperties
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullpublic Iterator<Property> getProperties(Collection<?> namePatterns, NodeCache cache)
CachedNode
getProperties
in interface CachedNode
namePatterns
- the regex patterns or string literals describing the namescache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullpublic ChildReferences getChildReferences(NodeCache cache)
CachedNode
getChildReferences
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullpublic Set<NodeKey> getReferrers(NodeCache cache, CachedNode.ReferenceType type)
CachedNode
getReferrers
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nulltype
- the flag specifying whether nodes with REFERENCE properties and/or WEAK reference properties should be included
in the result; may not be nullpublic ReferrerCounts getReferrerCounts(NodeCache cache)
CachedNode
getReferrerCounts
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullpublic boolean isExcludedFromSearch(NodeCache cache)
CachedNode
isExcludedFromSearch
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nulltrue
if the node should be indexed, false
otherwisepublic boolean hasACL(NodeCache cache)
CachedNode
hasACL
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nulltrue
if this node has an ACL, false
otherwisepublic Map<String,Set<String>> getPermissions(NodeCache cache)
CachedNode
getPermissions
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nullMap
which contains a set of permission names keyed by principal name or null
if no privileges
are in effect for this node(i.e. this node does not have an ACL). An empty Map
means a node which has an ACL, but
does not have any permissions.public boolean isExternal(NodeCache cache)
CachedNode
isExternal
in interface CachedNode
cache
- the cache to which this node belongs, required in case this node needs to use the cache; may not be nulltrue
if the node is local, false
otherwise.public String getString(NamespaceRegistry registry)
Copyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.