Package org.apache.jackrabbit.core.lock
Class XALockManager
- java.lang.Object
-
- org.apache.jackrabbit.core.lock.XALockManager
-
- All Implemented Interfaces:
LockManager,InternalXAResource
public class XALockManager extends Object implements LockManager, InternalXAResource
Session-local lock manager that implements the semantical changes inside transactions. This manager validates lock/unlock operations inside its view of the locking space.
-
-
Constructor Summary
Constructors Constructor Description XALockManager(LockManagerImpl lockMgr)Create a new instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLockToken(SessionImpl session, String lt)Invoked by a session to inform that a lock token has been added.voidafterOperation(TransactionContext tx)voidassociate(TransactionContext tx)Associate this resource with a transaction.voidbeforeOperation(TransactionContext tx)voidcheckLock(NodeImpl node)Check whether the node given is locked by somebody else than the current session.voidcheckLock(Path path, Session session)Check whether the path given is locked by somebody else than the session described.voidcheckUnlock(Session session, NodeImpl node)Check whether a session is allowed to unlock a node.voidcommit(TransactionContext tx)Commit transaction.booleandifferentXAEnv(LockInfo info)Return a flag indicating whether a lock info belongs to a different XA environment.LockgetLock(NodeImpl node)Returns the Lock object that applies to a node.Lock[]getLocks(SessionImpl session)Returns all locks owned by the specified session.booleanholdsLock(NodeImpl node)Returnstrueif the node given holds a lock; otherwise returnsfalse.booleanisLocked(NodeImpl node)Returnstrueif 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 returnsfalseLocklock(NodeImpl node, boolean isDeep, boolean isSessionScoped)Lock a node.Locklock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timoutHint, String ownerInfo)Lock a node.voidprepare(TransactionContext tx)Prepare transaction.voidremoveLockToken(SessionImpl session, String lt)Invoked by a session to inform that a lock token has been removed.voidrollback(TransactionContext tx)Rollback transaction.voidunlock(NodeImpl node)Removes the lock on a node given by its path.
-
-
-
Constructor Detail
-
XALockManager
public XALockManager(LockManagerImpl lockMgr)
Create a new instance of this class.- Parameters:
lockMgr- lockMgr global lock manager
-
-
Method Detail
-
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:
lockin 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 andisDeepistrueRepositoryException- 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:LockManagerLock a node. Checks whether the node is not locked and then returns a lock object for this node.- Specified by:
lockin 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 andisDeepistrueRepositoryException- See Also:
LockManager.lock(NodeImpl, 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:
getLockin 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:
getLocksin 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.- Specified by:
unlockin 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
Returnstrueif the node given holds a lock; otherwise returnsfalse.- Specified by:
holdsLockin interfaceLockManager- Parameters:
node- node- Returns:
trueif 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
Returnstrueif 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:
isLockedin interfaceLockManager- Parameters:
node- node- Returns:
trueif 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:
checkLockin 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:
checkLockin interfaceLockManager- Parameters:
path- path 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:
checkUnlockin interfaceLockManager- Throws:
LockException- if unlocking is deniedRepositoryException- if some other error occurs
-
addLockToken
public void addLockToken(SessionImpl session, String lt) throws RepositoryException
Invoked by a session to inform that a lock token has been added.- Specified by:
addLockTokenin interfaceLockManager- Parameters:
session- session that has a added lock tokenlt- added lock token- Throws:
LockExceptionRepositoryException
-
removeLockToken
public void removeLockToken(SessionImpl session, String lt) throws RepositoryException
Invoked by a session to inform that a lock token has been removed.- Specified by:
removeLockTokenin interfaceLockManager- Parameters:
session- session that has a removed lock tokenlt- removed lock token- Throws:
LockExceptionRepositoryException
-
associate
public void associate(TransactionContext tx)
Associate this resource with a transaction. All further operations on the object should be interpreted as part of this transaction and changes recorded in some attribute of the transaction context.- Specified by:
associatein interfaceInternalXAResource- Parameters:
tx- transaction context, ifnulldisassociate
-
beforeOperation
public void beforeOperation(TransactionContext tx)
Invoked before one of theInternalXAResource.prepare(org.apache.jackrabbit.data.core.TransactionContext),InternalXAResource.commit(org.apache.jackrabbit.data.core.TransactionContext)orInternalXAResource.rollback(org.apache.jackrabbit.data.core.TransactionContext)method is called.- Specified by:
beforeOperationin interfaceInternalXAResource- Parameters:
tx- transaction context
-
prepare
public void prepare(TransactionContext tx) throws TransactionException
Prepare transaction. The transaction is identified by a transaction context.- Specified by:
preparein interfaceInternalXAResource- Parameters:
tx- transaction context- Throws:
TransactionException- if an error occurs
-
commit
public void commit(TransactionContext tx)
Commit transaction. The transaction is identified by a transaction context. If the method throws, other resources get their changes rolled back.This will finish the update and unlock the shared lock manager.
- Specified by:
commitin interfaceInternalXAResource- Parameters:
tx- transaction context
-
rollback
public void rollback(TransactionContext tx)
Rollback transaction. The transaction is identified by a transaction context.This will undo all updates and unlock the shared lock manager.
- Specified by:
rollbackin interfaceInternalXAResource- Parameters:
tx- transaction context.
-
afterOperation
public void afterOperation(TransactionContext tx)
Invoked after one of theInternalXAResource.prepare(org.apache.jackrabbit.data.core.TransactionContext),InternalXAResource.commit(org.apache.jackrabbit.data.core.TransactionContext)orInternalXAResource.rollback(org.apache.jackrabbit.data.core.TransactionContext)method has been called.- Specified by:
afterOperationin interfaceInternalXAResource- Parameters:
tx- transaction context
-
differentXAEnv
public boolean differentXAEnv(LockInfo info)
Return a flag indicating whether a lock info belongs to a different XA environment.
-
-