public class LockManagerImpl extends Object implements LockManager, SynchronousEventListener, LockEventListener
Constructor and Description |
---|
LockManagerImpl(SessionImpl session,
FileSystem fs,
ScheduledExecutorService executor)
Create a new instance of this class.
|
Modifier and Type | Method and 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,
javax.jcr.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,
javax.jcr.Session session)
Check whether the path given is locked by somebody else than the
session described.
|
protected void |
checkUnlock(LockInfo info,
javax.jcr.Session session)
Check whether a session is allowed to unlock a node.
|
void |
checkUnlock(javax.jcr.Session session,
NodeImpl node)
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.
|
javax.jcr.lock.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.
|
javax.jcr.lock.Lock[] |
getLocks(SessionImpl session)
Returns all locks owned by the specified session.
|
boolean |
holdsLock(NodeImpl node)
Returns
true if the node given holds a lock;
otherwise returns false . |
boolean |
isLocked(NodeImpl 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 returns false |
javax.jcr.lock.Lock |
lock(NodeImpl node,
boolean isDeep,
boolean isSessionScoped)
Lock a node.
|
javax.jcr.lock.Lock |
lock(NodeImpl node,
boolean isDeep,
boolean isSessionScoped,
long timoutHint,
String ownerInfo)
Lock a node.
|
void |
onEvent(javax.jcr.observation.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 channel
|
String |
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.
|
public LockManagerImpl(SessionImpl session, FileSystem fs, ScheduledExecutorService executor) throws javax.jcr.RepositoryException
session
- system sessionfs
- file system for persisting locksexecutor
- scheduled executor service for handling lock timeoutsjavax.jcr.RepositoryException
- if an error occurspublic void close()
public void copyOpenScopedLocksFrom(LockManagerImpl source)
source
- source lock managerRepositoryCopier
public LockInfo getLockInfo(NodeId id) throws javax.jcr.RepositoryException
null
if node is not lockedjavax.jcr.RepositoryException
- if an error occurspublic javax.jcr.lock.Lock lock(NodeImpl node, boolean isDeep, boolean isSessionScoped) throws javax.jcr.lock.LockException, javax.jcr.RepositoryException
lock
in interface LockManager
node
- nodeisDeep
- whether the lock applies to this node onlyisSessionScoped
- whether the lock is session scopedjavax.jcr.lock.LockException
- if this node already is locked, or some descendant
node is locked and isDeep
is true
javax.jcr.RepositoryException
Node.lock(boolean, boolean)
public javax.jcr.lock.Lock lock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timoutHint, String ownerInfo) throws javax.jcr.lock.LockException, javax.jcr.RepositoryException
LockManager
lock
in interface LockManager
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.javax.jcr.lock.LockException
- if this node already is locked, or some descendant
node is locked and isDeep
is true
javax.jcr.RepositoryException
LockManager.lock(String, boolean, boolean, long, String)
public javax.jcr.lock.Lock getLock(NodeImpl node) throws javax.jcr.lock.LockException, javax.jcr.RepositoryException
getLock
in interface LockManager
node
- nodejavax.jcr.lock.LockException
- if this node is not lockedjavax.jcr.RepositoryException
Node.getLock()
public javax.jcr.lock.Lock[] getLocks(SessionImpl session) throws javax.jcr.RepositoryException
getLocks
in interface LockManager
session
- sessionjavax.jcr.RepositoryException
- if an error occursSessionImpl.getLocks()
public void unlock(NodeImpl node) throws javax.jcr.lock.LockException, javax.jcr.RepositoryException
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)
unlock
in interface LockManager
node
- nodejavax.jcr.lock.LockException
- if this node is not locked or the session
does not have the correct lock tokenjavax.jcr.RepositoryException
Node.unlock()
public boolean holdsLock(NodeImpl node) throws javax.jcr.RepositoryException
true
if the node given holds a lock;
otherwise returns false
.holdsLock
in interface LockManager
node
- nodetrue
if the node given holds a lock;
otherwise returns false
javax.jcr.RepositoryException
- If an exception occurs.Node.holdsLock()
public boolean isLocked(NodeImpl node) throws javax.jcr.RepositoryException
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 returns false
isLocked
in interface LockManager
node
- nodetrue
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 returns false
javax.jcr.RepositoryException
- If an exception occurs.Node.isLocked()
public void checkLock(NodeImpl node) throws javax.jcr.lock.LockException, javax.jcr.RepositoryException
checkLock
in interface LockManager
node
- node to checkjavax.jcr.lock.LockException
- if write access to the specified node is not allowedjavax.jcr.RepositoryException
- if some other error occurspublic void checkLock(Path path, javax.jcr.Session session) throws javax.jcr.lock.LockException, javax.jcr.RepositoryException
checkLock
in interface LockManager
path
- path to checksession
- sessionjavax.jcr.lock.LockException
- if write access to the specified path is not allowedjavax.jcr.RepositoryException
- if some other error occursprotected void checkLock(LockInfo info, javax.jcr.Session session) throws javax.jcr.lock.LockException, javax.jcr.RepositoryException
Default implementation allows access to the lock holder only.
info
- info to checksession
- sessionjavax.jcr.lock.LockException
- if write access to the specified path is not allowedjavax.jcr.RepositoryException
- if some other error occurspublic void checkUnlock(javax.jcr.Session session, NodeImpl node) throws javax.jcr.lock.LockException, javax.jcr.RepositoryException
checkUnlock
in interface LockManager
javax.jcr.lock.LockException
- if unlocking is deniedjavax.jcr.RepositoryException
- if some other error occursprotected void checkUnlock(LockInfo info, javax.jcr.Session session) throws javax.jcr.lock.LockException, javax.jcr.RepositoryException
Default implementation allows unlocking to the lock holder only.
info
- info to checksession
- sessionjavax.jcr.lock.LockException
- if unlocking is deniedjavax.jcr.RepositoryException
- if some other error occurspublic void addLockToken(SessionImpl session, String lt) throws javax.jcr.lock.LockException, javax.jcr.RepositoryException
addLockToken
in interface LockManager
session
- session that has a added lock tokenlt
- added lock tokenjavax.jcr.lock.LockException
javax.jcr.RepositoryException
public void removeLockToken(SessionImpl session, String lt) throws javax.jcr.lock.LockException, javax.jcr.RepositoryException
removeLockToken
in interface LockManager
session
- session that has a removed lock tokenlt
- removed lock tokenjavax.jcr.lock.LockException
javax.jcr.RepositoryException
public void beginUpdate()
public void endUpdate()
public void cancelUpdate()
protected void writeLockProperties(NodeImpl node, String lockOwner, boolean isDeep) throws javax.jcr.RepositoryException
node
- lockOwner
- isDeep
- javax.jcr.RepositoryException
protected void removeLockProperties(NodeImpl node) throws javax.jcr.RepositoryException
node
- javax.jcr.RepositoryException
public void onEvent(javax.jcr.observation.EventIterator events)
onEvent
in interface javax.jcr.observation.EventListener
public void setEventChannel(LockEventChannel eventChannel)
eventChannel
- lock event channelpublic void externalLock(NodeId nodeId, boolean isDeep, String lockOwner) throws javax.jcr.RepositoryException
externalLock
in interface LockEventListener
nodeId
- node idisDeep
- true
if the lock is deep;
false
otherwiselockOwner
- lock ownerjavax.jcr.RepositoryException
- if the lock cannot be processedpublic void externalUnlock(NodeId nodeId) throws javax.jcr.RepositoryException
externalUnlock
in interface LockEventListener
nodeId
- node idjavax.jcr.RepositoryException
- if the unlock cannot be processedCopyright © 2004-2020 The Apache Software Foundation. All Rights Reserved.