org.apache.jackrabbit.core.lock
Class LockManagerImpl

java.lang.Object
  extended by org.apache.jackrabbit.core.lock.LockManagerImpl
All Implemented Interfaces:
javax.jcr.observation.EventListener, LockEventListener, LockManager, SynchronousEventListener, Dumpable

public class LockManagerImpl
extends Object
implements LockManager, SynchronousEventListener, LockEventListener, Dumpable

Provides the functionality needed for locking and unlocking nodes.


Constructor Summary
LockManagerImpl(SessionImpl session, FileSystem fs)
          Create a new instance of this class.
 
Method Summary
 void beginUpdate()
          Start an update operation.
 void cancelUpdate()
          Cancel an update operation.
 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.
 void close()
          Close this lock manager.
 void dump(PrintStream ps)
          Dump contents of path map and elements included to PrintStream given.
 void endUpdate()
          End an update operation.
 void externalLock(NodeId nodeId, boolean isDeep, String userId)
          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.
 AbstractLockInfo 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
 boolean isLockHolder(javax.jcr.Session session, NodeImpl node)
          Returns true if the specified session holds a lock on the given node; otherwise returns false.
 javax.jcr.lock.Lock lock(NodeImpl node, boolean isDeep, boolean isSessionScoped)
          Lock a node.
 void lockTokenAdded(SessionImpl session, String lt)
          Invoked by a session to inform that a lock token has been added.
 void lockTokenRemoved(SessionImpl session, String lt)
          Invoked by a session to inform that a lock token has been removed.
 void onEvent(javax.jcr.observation.EventIterator events)
          
 void setEventChannel(LockEventChannel eventChannel)
          Set a lock event channel
 void unlock(NodeImpl node)
          Removes the lock on a node given by its path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LockManagerImpl

public LockManagerImpl(SessionImpl session,
                       FileSystem fs)
                throws javax.jcr.RepositoryException
Create a new instance of this class.

Parameters:
session - system session
fs - file system for persisting locks
Throws:
javax.jcr.RepositoryException - if an error occurs
Method Detail

close

public void close()
Close this lock manager. Writes back all changes.


getLockInfo

public AbstractLockInfo getLockInfo(NodeId id)
                             throws javax.jcr.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:
javax.jcr.RepositoryException - if an error occurs

lock

public javax.jcr.lock.Lock lock(NodeImpl node,
                                boolean isDeep,
                                boolean isSessionScoped)
                         throws javax.jcr.lock.LockException,
                                javax.jcr.RepositoryException
Lock a node. Checks whether the node is not locked and then returns a lock object for this node.

Specified by:
lock in interface LockManager
Parameters:
node - node
isDeep - whether the lock applies to this node only
isSessionScoped - whether the lock is session scoped
Returns:
lock object
Throws:
javax.jcr.lock.LockException - if this node already is locked, or some descendant node is locked and isDeep is true
javax.jcr.RepositoryException
See Also:
Node.lock(boolean, boolean)

getLock

public javax.jcr.lock.Lock getLock(NodeImpl node)
                            throws javax.jcr.lock.LockException,
                                   javax.jcr.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 interface LockManager
Parameters:
node - node
Returns:
lock object
Throws:
javax.jcr.lock.LockException - if this node is not locked
javax.jcr.RepositoryException
See Also:
Node.getLock()

getLocks

public javax.jcr.lock.Lock[] getLocks(SessionImpl session)
                               throws javax.jcr.RepositoryException
Returns all locks owned by the specified session.

Specified by:
getLocks in interface LockManager
Parameters:
session - session
Returns:
an array of lock objects
Throws:
javax.jcr.RepositoryException - if an error occurs
See Also:
SessionImpl.getLocks()

unlock

public void unlock(NodeImpl node)
            throws javax.jcr.lock.LockException,
                   javax.jcr.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 interface LockManager
Parameters:
node - node
Throws:
javax.jcr.lock.LockException - if this node is not locked or the session does not have the correct lock token
javax.jcr.RepositoryException
See Also:
Node.unlock()

holdsLock

public boolean holdsLock(NodeImpl node)
                  throws javax.jcr.RepositoryException
Returns true if the node given holds a lock; otherwise returns false.

Specified by:
holdsLock in interface LockManager
Parameters:
node - node
Returns:
true if the node given holds a lock; otherwise returns false
Throws:
javax.jcr.RepositoryException
See Also:
Node.holdsLock()

isLockHolder

public boolean isLockHolder(javax.jcr.Session session,
                            NodeImpl node)
                     throws javax.jcr.RepositoryException
Returns true if the specified session holds a lock on the given node; otherwise returns false.

Note that isLockHolder(session, node)==true implies holdsLock(node)==true.

Specified by:
isLockHolder in interface LockManager
Parameters:
session - session
node - node
Returns:
if the specified session holds a lock on the given node; otherwise returns false
Throws:
javax.jcr.RepositoryException

isLocked

public boolean isLocked(NodeImpl node)
                 throws javax.jcr.RepositoryException
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

Specified by:
isLocked in interface LockManager
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 returns false
Throws:
javax.jcr.RepositoryException
See Also:
Node.isLocked()

checkLock

public void checkLock(NodeImpl node)
               throws javax.jcr.lock.LockException,
                      javax.jcr.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 interface LockManager
Parameters:
node - node to check
Throws:
javax.jcr.lock.LockException - if write access to the specified node is not allowed
javax.jcr.RepositoryException - if some other error occurs

checkLock

public void checkLock(Path path,
                      javax.jcr.Session session)
               throws javax.jcr.lock.LockException,
                      javax.jcr.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 interface LockManager
Parameters:
path - path to check
session - session
Throws:
javax.jcr.lock.LockException - if write access to the specified path is not allowed
javax.jcr.RepositoryException - if some other error occurs

lockTokenAdded

public void lockTokenAdded(SessionImpl session,
                           String lt)
Invoked by a session to inform that a lock token has been added.

Specified by:
lockTokenAdded in interface LockManager
Parameters:
session - session that has a added lock token
lt - added lock token

lockTokenRemoved

public void lockTokenRemoved(SessionImpl session,
                             String lt)
Invoked by a session to inform that a lock token has been removed.

Specified by:
lockTokenRemoved in interface LockManager
Parameters:
session - session that has a removed lock token
lt - removed lock token

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.


onEvent

public void onEvent(javax.jcr.observation.EventIterator events)

Specified by:
onEvent in interface javax.jcr.observation.EventListener

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 userId)
                  throws javax.jcr.RepositoryException
Handle an external lock operation.

Specified by:
externalLock in interface LockEventListener
Parameters:
nodeId - node id
isDeep - true if the lock is deep; false otherwise
userId - user id
Throws:
javax.jcr.RepositoryException - if the lock cannot be processed

externalUnlock

public void externalUnlock(NodeId nodeId)
                    throws javax.jcr.RepositoryException
Handle an external unlock operation.

Specified by:
externalUnlock in interface LockEventListener
Parameters:
nodeId - node id
Throws:
javax.jcr.RepositoryException - if the unlock cannot be processed

dump

public void dump(PrintStream ps)
Dump contents of path map and elements included to PrintStream given.

Specified by:
dump in interface Dumpable
Parameters:
ps - print stream to dump to


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.