Class SharedItemStateManager
- java.lang.Object
-
- org.apache.jackrabbit.core.state.SharedItemStateManager
-
- All Implemented Interfaces:
ItemStateListener
,ItemStateManager
- Direct Known Subclasses:
VersionItemStateManager
public class SharedItemStateManager extends Object implements ItemStateManager, ItemStateListener
SharedItemStateManager
(SISM). Caches objects returned from aPersistenceManager
. Objects returned by this item state manager are shared among all sessions.A shared item state manager operates on a
PersistenceManager
(PM) that is used to load and store the item states. Additionally, a SISM can haveVirtualItemStateProvider
s (VISP) that are used to provide additional, non-persistent, read-only states. Examples of VISP are the content representation of the NodeTypes (/jcr:system/jcr:nodeTypes) and the version store (/jcr:system/jcr:versionStore). those 2 VISP are added to the SISM during initialization of a workspace. i.e. they are 'mounted' to all workspaces. we assume, that VISP cannot be added dynamically, neither during runtime nor by configuration.The states from the VISP are read-only. by the exception for node references. remember that the referrers are stored in a
NodeReferences
state, having the ID of the target state.there are 5 types of referential relations to be distinguished:
- normal --> normal (references from 'normal' states to 'normal' states) this is the normal case and will be handled by the SISM.
- normal --> virtual (references from 'normal' states to 'virtual' states) those references should be handled by the VISP rather by the SISM.
- virtual --> normal (references from 'virtual' states to 'normal' states) such references are not supported. eg. references of versioned nodes do not impose any constraints on the referenced nodes.
- virtual --> virtual (references from 'virtual' states to 'virtual' states of the same VISP). intra-virtual references are handled by the item state manager of the VISP.
- virtual --> virtual' (references from 'virtual' states to 'virtual' states of different VISP). those do currently not occur and are therefore not supported.
if VISP are not dynamic, there is not risk that NV-type references can dangle (since a VISP cannot be 'unmounted', leaving eventual references dangling). although multi-workspace-referrers are not explicitly supported, the architecture of
NodeReferences
support multiple referrers with the same PropertyId. So the number of references can be tracked (an example of multi-workspace-referrers is a version referenced by the jcr:baseVersion of several (corresponding) nodes in multiple workspaces).As mentioned, VN-type references should not impose any constraints on the referrers (e.g. a normal node referenced by a versioned reference property). In case of the version store, the VN-type references are not stored at all, but reinforced as NN-type references in the normal states in case of a checkout operation.
VV-type references should be handled by the respective VISP. they look as NN-type references in the scope if the VISP anyway...so no special treatment should be necessary.
VV'-type references are currently not possible, since the version store and virtual node type representation don't allow such references.
-
-
Constructor Summary
Constructors Constructor Description SharedItemStateManager(PersistenceManager persistMgr, NodeId rootNodeId, NodeTypeRegistry ntReg, boolean usesReferences, ItemStateCacheFactory cacheFactory, ISMLocking locking, NodeIdFactory nodeIdFactory)
Creates a newSharedItemStateManager
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(ItemStateListener listener)
Add anItemStateListener
void
addVirtualItemStateProvider(VirtualItemStateProvider prov)
Adds a new virtual item state provider.org.apache.jackrabbit.core.state.SharedItemStateManager.Update
beginUpdate(ChangeLog local, EventStateCollectionFactory factory, VirtualItemStateProvider virtualProvider)
Begin update operation.void
dispose()
Disposes thisSharedItemStateManager
and frees resources.protected void
doExternalUpdate(ChangeLog external)
Perform the external update.void
externalUpdate(ChangeLog external, EventStateCollection events)
Handle an external update.ItemState
getItemState(ItemId id)
Return an item state, given its item id.NodeIdFactory
getNodeIdFactory()
NodeReferences
getNodeReferences(NodeId id)
Return a node references object, given its target idboolean
hasItemState(ItemId id)
Return a flag indicating whether an item state for a given item id exists.boolean
hasNodeReferences(NodeId id)
Return a flag indicating whether a node references object for a given target id exists.protected boolean
hasNonVirtualItemState(ItemId id)
Checks if this item state manager has the given item state without considering the virtual item state managers.void
removeListener(ItemStateListener listener)
Remove anItemStateListener
void
setCheckReferences(boolean checkReferences)
Enables or disables the referential integrity checking, this should be used very carefully by experienced developers only.void
setEventChannel(UpdateEventChannel eventChannel)
Set an update event channelvoid
setISMLocking(ISMLocking ismLocking)
Sets a new locking strategy.void
stateCreated(ItemState created)
Called when anItemState
has successfully been created (i.e.void
stateDestroyed(ItemState destroyed)
Called when anItemState
has successfully been removed (i.e.void
stateDiscarded(ItemState discarded)
Called when anItemState
has been discarded (i.e.void
stateModified(ItemState modified)
Called when anItemState
has successfully been modified (i.e.String
toString()
void
update(ChangeLog local, EventStateCollectionFactory factory)
Store modifications registered in aChangeLog
.
-
-
-
Constructor Detail
-
SharedItemStateManager
public SharedItemStateManager(PersistenceManager persistMgr, NodeId rootNodeId, NodeTypeRegistry ntReg, boolean usesReferences, ItemStateCacheFactory cacheFactory, ISMLocking locking, NodeIdFactory nodeIdFactory) throws ItemStateException
Creates a newSharedItemStateManager
instance.- Parameters:
persistMgr
-rootNodeId
-ntReg
-- Throws:
ItemStateException
-
-
Method Detail
-
setCheckReferences
public void setCheckReferences(boolean checkReferences)
Enables or disables the referential integrity checking, this should be used very carefully by experienced developers only.- Parameters:
checkReferences
- whether to do referential integrity checks- See Also:
- "https://issues.apache.org/jira/browse/JCR-954"
-
setEventChannel
public void setEventChannel(UpdateEventChannel eventChannel)
Set an update event channel- Parameters:
eventChannel
- update event channel
-
setISMLocking
public void setISMLocking(ISMLocking ismLocking)
Sets a new locking strategy.- Parameters:
ismLocking
- the locking strategy for this item state manager.
-
getItemState
public ItemState getItemState(ItemId id) throws NoSuchItemStateException, ItemStateException
Return an item state, given its item id.- Specified by:
getItemState
in interfaceItemStateManager
- Parameters:
id
- item id- Returns:
- item state
- Throws:
NoSuchItemStateException
- if the item does not existItemStateException
- if an error occurs
-
hasItemState
public boolean hasItemState(ItemId id)
Return a flag indicating whether an item state for a given item id exists.- Specified by:
hasItemState
in interfaceItemStateManager
- Parameters:
id
- item id- Returns:
true
if an item state exists, otherwisefalse
-
getNodeReferences
public NodeReferences getNodeReferences(NodeId id) throws NoSuchItemStateException, ItemStateException
Return a node references object, given its target id- Specified by:
getNodeReferences
in interfaceItemStateManager
- Parameters:
id
- target id- Returns:
- node references object
- Throws:
NoSuchItemStateException
- if the item does not existItemStateException
- if an error occurs
-
hasNodeReferences
public boolean hasNodeReferences(NodeId id)
Return a flag indicating whether a node references object for a given target id exists.- Specified by:
hasNodeReferences
in interfaceItemStateManager
- Parameters:
id
- target id- Returns:
true
if a node reference object exists for the given id, otherwisefalse
.
-
stateCreated
public void stateCreated(ItemState created)
Called when anItemState
has successfully been created (i.e. its underlying persistent state was created).Notifications are received for items that this manager created itself or items that are managed by one of the virtual providers.
- Specified by:
stateCreated
in interfaceItemStateListener
- Parameters:
created
- theItemState
that has been 'created'
-
stateModified
public void stateModified(ItemState modified)
Called when anItemState
has successfully been modified (i.e. its underlying persistent state has changed).Notifications are received for items that this manager created itself or items that are managed by one of the virtual providers.
- Specified by:
stateModified
in interfaceItemStateListener
- Parameters:
modified
- theItemState
that has been 'modified'
-
stateDestroyed
public void stateDestroyed(ItemState destroyed)
Called when anItemState
has successfully been removed (i.e. its underlying persistent state has been destroyed).Notifications are received for items that this manager created itself or items that are managed by one of the virtual providers.
- Specified by:
stateDestroyed
in interfaceItemStateListener
- Parameters:
destroyed
- theItemState
that has been 'destroyed'
-
stateDiscarded
public void stateDiscarded(ItemState discarded)
Called when anItemState
has been discarded (i.e. it has been rendered 'invalid').Notifications are received for items that this manager created itself or items that are managed by one of the virtual providers.
- Specified by:
stateDiscarded
in interfaceItemStateListener
- Parameters:
discarded
- theItemState
that has been discarded- See Also:
ItemState.discard()
-
dispose
public void dispose()
Disposes thisSharedItemStateManager
and frees resources.
-
addVirtualItemStateProvider
public void addVirtualItemStateProvider(VirtualItemStateProvider prov)
Adds a new virtual item state provider.NOTE: This method is not synchronized, because it is called right after creation only by the same thread and therefore concurrency issues do not occur. Should this ever change, the synchronization status has to be re-examined.
- Parameters:
prov
-
-
beginUpdate
public org.apache.jackrabbit.core.state.SharedItemStateManager.Update beginUpdate(ChangeLog local, EventStateCollectionFactory factory, VirtualItemStateProvider virtualProvider) throws ReferentialIntegrityException, StaleItemStateException, ItemStateException
Begin update operation. This will return an object that can itself be ended/canceled.
-
update
public void update(ChangeLog local, EventStateCollectionFactory factory) throws ReferentialIntegrityException, StaleItemStateException, ItemStateException
Store modifications registered in aChangeLog
. The items contained in theChangeLog
are not states returned by this item state manager but rather must be reconnected to items provided by this state manager.After successfully storing the states the observation manager is informed about the changes, if an observation manager is passed to this method.
NOTE: This method is not synchronized, because all methods it invokes on instance members (such as
PersistenceManager.store(org.apache.jackrabbit.core.state.ChangeLog)
are considered to be thread-safe. Should this ever change, the synchronization status has to be re-examined.- Parameters:
local
- change log containing local itemsfactory
- event state collection factory- Throws:
ReferentialIntegrityException
- if a new or modified REFERENCE property refers to a non-existent target or if a removed node is still being referencedStaleItemStateException
- if at least one of the affected item states has become staleItemStateException
- if another error occurs
-
externalUpdate
public void externalUpdate(ChangeLog external, EventStateCollection events)
Handle an external update.- Parameters:
external
- external change containing only node and property ids.events
- events to deliver
-
doExternalUpdate
protected void doExternalUpdate(ChangeLog external)
Perform the external update. While executing this method, thewriteLock
on this manager is held.- Parameters:
external
- external change containing only node and property ids.
-
addListener
public void addListener(ItemStateListener listener)
Add anItemStateListener
- Parameters:
listener
- the new listener to be informed on modifications
-
removeListener
public void removeListener(ItemStateListener listener)
Remove anItemStateListener
- Parameters:
listener
- an existing listener
-
hasNonVirtualItemState
protected boolean hasNonVirtualItemState(ItemId id)
Checks if this item state manager has the given item state without considering the virtual item state managers.
-
getNodeIdFactory
public NodeIdFactory getNodeIdFactory()
-
-