Package org.apache.jackrabbit.core.lock
Class LockManagerImpl
- java.lang.Object
-
- org.apache.jackrabbit.core.lock.LockManagerImpl
-
- All Implemented Interfaces:
EventListener
,LockEventListener
,LockManager
,SynchronousEventListener
public class LockManagerImpl extends Object implements LockManager, SynchronousEventListener, LockEventListener
Provides the functionality needed for locking and unlocking nodes.
-
-
Constructor Summary
Constructors Constructor Description LockManagerImpl(SessionImpl session, FileSystem fs, ScheduledExecutorService executor)
Create a new instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLockToken(SessionImpl session, String lt)
Invoked by a session to inform that a lock token has been added.void
beginUpdate()
Start an update operation.void
cancelUpdate()
Cancel an update operation.protected void
checkLock(LockInfo info, Session session)
Check whether a lock info allows access to a session.void
checkLock(NodeImpl node)
Check whether the node given is locked by somebody else than the current session.void
checkLock(Path path, Session session)
Check whether the path given is locked by somebody else than the session described.void
checkUnlock(Session session, NodeImpl node)
Check whether a session is allowed to unlock a node.protected void
checkUnlock(LockInfo info, Session session)
Check whether a session is allowed to unlock a node.void
close()
Close this lock manager.void
copyOpenScopedLocksFrom(LockManagerImpl source)
Helper method that copies all the active open-scoped locks from the given source to this lock manager.void
endUpdate()
End an update operation.void
externalLock(NodeId nodeId, boolean isDeep, String lockOwner)
Handle an external lock operation.void
externalUnlock(NodeId nodeId)
Handle an external unlock operation.Lock
getLock(NodeImpl node)
Returns the Lock object that applies to a node.LockInfo
getLockInfo(NodeId id)
Return the most appropriate lock information for a node.Lock[]
getLocks(SessionImpl session)
Returns all locks owned by the specified session.boolean
holdsLock(NodeImpl node)
Returnstrue
if the node given holds a lock; otherwise returnsfalse
.boolean
isLocked(NodeImpl node)
Returnstrue
if this node is locked either as a result of a lock held by this node or by a deep lock on a node above this node; otherwise returnsfalse
Lock
lock(NodeImpl node, boolean isDeep, boolean isSessionScoped)
Lock a node.Lock
lock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timoutHint, String ownerInfo)
Lock a node.void
onEvent(EventIterator events)
protected void
removeLockProperties(NodeImpl node)
void
removeLockToken(SessionImpl session, String lt)
Invoked by a session to inform that a lock token has been removed.void
setEventChannel(LockEventChannel eventChannel)
Set a lock event channelString
toString()
Dump contents of path map and elements included to a string.void
unlock(NodeImpl node)
Removes the lock on a node given by its path.protected void
writeLockProperties(NodeImpl node, String lockOwner, boolean isDeep)
Add the lock related properties to the target node.
-
-
-
Constructor Detail
-
LockManagerImpl
public LockManagerImpl(SessionImpl session, FileSystem fs, ScheduledExecutorService executor) throws RepositoryException
Create a new instance of this class.- Parameters:
session
- system sessionfs
- file system for persisting locksexecutor
- scheduled executor service for handling lock timeouts- Throws:
RepositoryException
- if an error occurs
-
-
Method Detail
-
close
public void close()
Close this lock manager. Writes back all changes.
-
copyOpenScopedLocksFrom
public void copyOpenScopedLocksFrom(LockManagerImpl source)
Helper method that copies all the active open-scoped locks from the given source to this lock manager. This method is used when backing up repositories, and only works correctly when the source lock manager belongs to the original copy of the workspace being backed up.- Parameters:
source
- source lock manager- See Also:
RepositoryCopier
-
getLockInfo
public LockInfo getLockInfo(NodeId id) throws RepositoryException
Return the most appropriate lock information for a node. This is either the lock info for the node itself, if it is locked, or a lock info for one of its parents, if that is deep locked.- Returns:
- lock info or
null
if node is not locked - Throws:
RepositoryException
- if an error occurs
-
lock
public Lock lock(NodeImpl node, boolean isDeep, boolean isSessionScoped) throws LockException, RepositoryException
Lock a node. Checks whether the node is not locked and then returns a lock object for this node.- Specified by:
lock
in interfaceLockManager
- Parameters:
node
- nodeisDeep
- whether the lock applies to this node onlyisSessionScoped
- whether the lock is session scoped- Returns:
- lock object
- Throws:
LockException
- if this node already is locked, or some descendant node is locked andisDeep
istrue
RepositoryException
- See Also:
Node.lock(boolean, boolean)
-
lock
public Lock lock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timoutHint, String ownerInfo) throws LockException, RepositoryException
Description copied from interface:LockManager
Lock a node. Checks whether the node is not locked and then returns a lock object for this node.- Specified by:
lock
in interfaceLockManager
- Parameters:
node
- Node to create the lock for.isDeep
- whether the lock applies to this node onlyisSessionScoped
- whether the lock is session scopedtimoutHint
- Desired lock timeout in seconds.ownerInfo
- Optional string acting as information about the owner.- Returns:
- the lock.
- Throws:
LockException
- if this node already is locked, or some descendant node is locked andisDeep
istrue
RepositoryException
- See Also:
LockManager.lock(String, boolean, boolean, long, String)
-
getLock
public Lock getLock(NodeImpl node) throws LockException, RepositoryException
Returns the Lock object that applies to a node. This may be either a lock on this node itself or a deep lock on a node above this node.- Specified by:
getLock
in interfaceLockManager
- Parameters:
node
- node- Returns:
- lock object
- Throws:
LockException
- if this node is not lockedRepositoryException
- See Also:
Node.getLock()
-
getLocks
public Lock[] getLocks(SessionImpl session) throws RepositoryException
Returns all locks owned by the specified session.- Specified by:
getLocks
in interfaceLockManager
- Parameters:
session
- session- Returns:
- an array of lock objects
- Throws:
RepositoryException
- if an error occurs- See Also:
SessionImpl.getLocks()
-
unlock
public void unlock(NodeImpl node) throws LockException, RepositoryException
Removes the lock on a node given by its path.In order to prevent deadlocks from within the synchronous dispatching of events, content modifications should not be made from within code sections that hold monitors. (see #JCR-194)
- Specified by:
unlock
in interfaceLockManager
- Parameters:
node
- node- Throws:
LockException
- if this node is not locked or the session does not have the correct lock tokenRepositoryException
- See Also:
Node.unlock()
-
holdsLock
public boolean holdsLock(NodeImpl node) throws RepositoryException
Returnstrue
if the node given holds a lock; otherwise returnsfalse
.- Specified by:
holdsLock
in interfaceLockManager
- Parameters:
node
- node- Returns:
true
if the node given holds a lock; otherwise returnsfalse
- Throws:
RepositoryException
- If an exception occurs.- See Also:
Node.holdsLock()
-
isLocked
public boolean isLocked(NodeImpl node) throws RepositoryException
Returnstrue
if this node is locked either as a result of a lock held by this node or by a deep lock on a node above this node; otherwise returnsfalse
- Specified by:
isLocked
in interfaceLockManager
- Parameters:
node
- node- Returns:
true
if this node is locked either as a result of a lock held by this node or by a deep lock on a node above this node; otherwise returnsfalse
- Throws:
RepositoryException
- If an exception occurs.- See Also:
Node.isLocked()
-
checkLock
public void checkLock(NodeImpl node) throws LockException, RepositoryException
Check whether the node given is locked by somebody else than the current session. Access is allowed if the node is not locked or if the session itself holds the lock to this node, i.e. the session contains the lock token for the lock.- Specified by:
checkLock
in interfaceLockManager
- Parameters:
node
- node to check- Throws:
LockException
- if write access to the specified node is not allowedRepositoryException
- if some other error occurs
-
checkLock
public void checkLock(Path path, Session session) throws LockException, RepositoryException
Check whether the path given is locked by somebody else than the session described. Access is allowed if the node is not locked or if the session itself holds the lock to this node, i.e. the session contains the lock token for the lock.- Specified by:
checkLock
in interfaceLockManager
- Parameters:
path
- path to checksession
- session- Throws:
LockException
- if write access to the specified path is not allowedRepositoryException
- if some other error occurs
-
checkLock
protected void checkLock(LockInfo info, Session session) throws LockException, RepositoryException
Check whether a lock info allows access to a session. May be overridden by subclasses to allow access to nodes for sessions other than the lock holder itself.Default implementation allows access to the lock holder only.
- Parameters:
info
- info to checksession
- session- Throws:
LockException
- if write access to the specified path is not allowedRepositoryException
- if some other error occurs
-
checkUnlock
public void checkUnlock(Session session, NodeImpl node) throws LockException, RepositoryException
Check whether a session is allowed to unlock a node.- Specified by:
checkUnlock
in interfaceLockManager
- Throws:
LockException
- if unlocking is deniedRepositoryException
- if some other error occurs
-
checkUnlock
protected void checkUnlock(LockInfo info, Session session) throws LockException, RepositoryException
Check whether a session is allowed to unlock a node. May be overridden by subclasses to allow this to sessions other than the lock holder itself.Default implementation allows unlocking to the lock holder only.
- Parameters:
info
- info to checksession
- session- Throws:
LockException
- if unlocking is deniedRepositoryException
- if some other error occurs
-
addLockToken
public void addLockToken(SessionImpl session, String lt) throws LockException, RepositoryException
Invoked by a session to inform that a lock token has been added.- Specified by:
addLockToken
in interfaceLockManager
- Parameters:
session
- session that has a added lock tokenlt
- added lock token- Throws:
LockException
RepositoryException
-
removeLockToken
public void removeLockToken(SessionImpl session, String lt) throws LockException, RepositoryException
Invoked by a session to inform that a lock token has been removed.- Specified by:
removeLockToken
in interfaceLockManager
- Parameters:
session
- session that has a removed lock tokenlt
- removed lock token- Throws:
LockException
RepositoryException
-
beginUpdate
public void beginUpdate()
Start an update operation. This will acquire the lock on the lock map and disable saving the lock map file.
-
endUpdate
public void endUpdate()
End an update operation. This will save the lock map file and release the lock on the lock map.
-
cancelUpdate
public void cancelUpdate()
Cancel an update operation. This will release the lock on the lock map.
-
writeLockProperties
protected void writeLockProperties(NodeImpl node, String lockOwner, boolean isDeep) throws RepositoryException
Add the lock related properties to the target node.- Parameters:
node
-lockOwner
-isDeep
-- Throws:
RepositoryException
-
removeLockProperties
protected void removeLockProperties(NodeImpl node) throws RepositoryException
- Parameters:
node
-- Throws:
RepositoryException
-
onEvent
public void onEvent(EventIterator events)
- Specified by:
onEvent
in interfaceEventListener
-
setEventChannel
public void setEventChannel(LockEventChannel eventChannel)
Set a lock event channel- Parameters:
eventChannel
- lock event channel
-
externalLock
public void externalLock(NodeId nodeId, boolean isDeep, String lockOwner) throws RepositoryException
Handle an external lock operation.- Specified by:
externalLock
in interfaceLockEventListener
- Parameters:
nodeId
- node idisDeep
-true
if the lock is deep;false
otherwiselockOwner
- lock owner- Throws:
RepositoryException
- if the lock cannot be processed
-
externalUnlock
public void externalUnlock(NodeId nodeId) throws RepositoryException
Handle an external unlock operation.- Specified by:
externalUnlock
in interfaceLockEventListener
- Parameters:
nodeId
- node id- Throws:
RepositoryException
- if the unlock cannot be processed
-
-