org.apache.jackrabbit.core.lock
Class LockManagerImpl

java.lang.Object
  extended byorg.apache.jackrabbit.core.lock.LockManagerImpl
All Implemented Interfaces:
EventListener, LockManager, SynchronousEventListener

public class LockManagerImpl
extends Object
implements LockManager, SynchronousEventListener

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. 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.
 void checkLock(Path path, Session session)
          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.
 void close()
          Close this lock manager.
 void endUpdate()
          End an update operation.
 Lock getLock(NodeImpl node)
          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.
 org.apache.jackrabbit.core.lock.AbstractLockInfo getLockInfo(NodeId id)
          Return the most appropriate lock information for a node.
 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
 Lock lock(NodeImpl node, boolean isDeep, boolean isSessionScoped)
          Lock a node. Checks whether the node is not locked and then returns a lock object for this 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(EventIterator events)
          
 void unlock(NodeImpl node)
          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.

 
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 RepositoryException
Create a new instance of this class.

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

close

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


getLockInfo

public org.apache.jackrabbit.core.lock.AbstractLockInfo 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 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:
LockException - if this node already is locked, or some descendant node is locked and isDeep is true
RepositoryException
See Also:
Node.lock(boolean, boolean)

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

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

holdsLock

public boolean holdsLock(NodeImpl node)
                  throws 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:
RepositoryException
See Also:
Node.holdsLock()

isLocked

public boolean isLocked(NodeImpl node)
                 throws 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:
RepositoryException
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 interface LockManager
Parameters:
node - node to check
Throws:
LockException - if write access to the specified node is not allowed
RepositoryException - 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 interface LockManager
Parameters:
path - path to check
session - session
Throws:
RepositoryException - if some other error occurs
LockException - if write access to the specified path is not allowed

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(EventIterator events)

Specified by:
onEvent in interface EventListener


Copyright © 2004-2006 The Apache Software Foundation. All Rights Reserved.