org.opencms.lock
Class CmsLockManager

java.lang.Object
  extended byorg.opencms.lock.CmsLockManager

public final class CmsLockManager
extends java.lang.Object

The CmsLockManager is used by the Cms application to detect the lock state of a resource.

The lock state depends on the path of the resource, and probably locked parent folders. The result of a query to the lock manager are instances of CmsLock objects.

Since:
6.0.0
Version:
$Revision: 1.38 $
Author:
Michael Emmerich, Thomas Weckert, Andreas Zahner
See Also:
CmsObject.getLock(CmsResource), CmsLock

Method Summary
 void addResource(CmsDriverManager driverManager, CmsDbContext dbc, CmsResource resource, CmsUUID userId, int projectId, int mode)
          Adds a resource to the lock manager.
 int countExclusiveLocksInFolder(java.lang.String foldername)
          Counts the exclusive locked resources inside a folder.
 int countExclusiveLocksInProject(CmsProject project)
          Counts the exclusive locked resources in a project.
protected  void finalize()
           
static CmsLockManager getInstance()
          Returns the shared instance of the lock manager.
 CmsLock getLock(CmsDriverManager driverManager, CmsDbContext dbc, CmsResource resource)
          Returns the lock for a resource.
 boolean isLocked(CmsDriverManager driverManager, CmsDbContext dbc, CmsResource resource)
          Proves if a resource is locked.
 void removeDeletedResource(CmsDriverManager driverManager, CmsDbContext dbc, java.lang.String resourceName)
          Removes a resource after it has been deleted by the driver manager.
 CmsLock removeResource(CmsDriverManager driverManager, CmsDbContext dbc, CmsResource resource, boolean forceUnlock)
          Removes a resource from the lock manager.
 void removeResourcesInProject(int projectId)
          Removes all resources that are exclusively locked in a project.
 void removeTempLocks(CmsUUID userId)
          Removes all exclusive temporary locks of a user.
 int size()
          Returns the number of exclusive locked resources.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getInstance

public static CmsLockManager getInstance()
Returns the shared instance of the lock manager.

Returns:
the shared instance of the lock manager

addResource

public void addResource(CmsDriverManager driverManager,
                        CmsDbContext dbc,
                        CmsResource resource,
                        CmsUUID userId,
                        int projectId,
                        int mode)
                 throws CmsLockException,
                        CmsException
Adds a resource to the lock manager.

Parameters:
driverManager - the driver manager
dbc - the current database context
resource - the resource
userId - the ID of the user who locked the resource
projectId - the ID of the project where the resource is locked
mode - flag indicating the mode (temporary or common) of a lock
Throws:
CmsLockException - if the resource is locked
CmsException - if somethong goes wrong

countExclusiveLocksInFolder

public int countExclusiveLocksInFolder(java.lang.String foldername)
Counts the exclusive locked resources inside a folder.

Parameters:
foldername - the folder
Returns:
the number of exclusive locked resources in the specified folder

countExclusiveLocksInProject

public int countExclusiveLocksInProject(CmsProject project)
Counts the exclusive locked resources in a project.

Parameters:
project - the project
Returns:
the number of exclusive locked resources in the specified project

getLock

public CmsLock getLock(CmsDriverManager driverManager,
                       CmsDbContext dbc,
                       CmsResource resource)
                throws CmsException
Returns the lock for a resource.

Parameters:
driverManager - the driver manager
dbc - the current database context
resource - the resource
Returns:
the CmsLock if the specified resource is locked, or the shared Null lock if the resource is not locked
Throws:
CmsException - if something goes wrong

isLocked

public boolean isLocked(CmsDriverManager driverManager,
                        CmsDbContext dbc,
                        CmsResource resource)
                 throws CmsException
Proves if a resource is locked.

Use getLock(CmsDriverManager, CmsDbContext, CmsResource) to obtain a CmsLock object for the specified resource to get further information about how the resource is locked.

Parameters:
driverManager - the driver manager
dbc - the current database context
resource - the resource
Returns:
true, if and only if the resource is currently locked
Throws:
CmsException - if something goes wrong

removeDeletedResource

public void removeDeletedResource(CmsDriverManager driverManager,
                                  CmsDbContext dbc,
                                  java.lang.String resourceName)
                           throws CmsException
Removes a resource after it has been deleted by the driver manager.

Parameters:
driverManager - the driver manager
dbc - the current database context
resourceName - the root path of the deleted resource
Throws:
CmsException - if something goes wrong

removeResource

public CmsLock removeResource(CmsDriverManager driverManager,
                              CmsDbContext dbc,
                              CmsResource resource,
                              boolean forceUnlock)
                       throws CmsException
Removes a resource from the lock manager.

The forceUnlock option should be used with caution. forceUnlock will remove the lock by ignoring any rules which may cause wrong lock states.

Parameters:
driverManager - the driver manager
dbc - the current database context
resource - the resource
forceUnlock - true, if a resource is forced to get unlocked, no matter by which user and in which project the resource is currently locked
Returns:
the previous CmsLock object of the resource, or null if the resource was unlocked
Throws:
CmsException - if something goes wrong

removeResourcesInProject

public void removeResourcesInProject(int projectId)
Removes all resources that are exclusively locked in a project.

Parameters:
projectId - the ID of the project where the resources have been locked

removeTempLocks

public void removeTempLocks(CmsUUID userId)
Removes all exclusive temporary locks of a user.

Parameters:
userId - the ID of the user whose locks are removed

size

public int size()
Returns the number of exclusive locked resources.

Returns:
the number of exclusive locked resources

toString

public java.lang.String toString()
See Also:
Object.toString()

finalize

protected void finalize()
                 throws java.lang.Throwable
Throws:
java.lang.Throwable
See Also:
Object.finalize()