The purpose of locking is to avoid concurrent write-access to resources. The Pcd provides methods to acquire and release locks for folders and units.
It is important to understand that the lock by itself does not protect resources in any way. Even if a foreign lock exists for a specific resource, applications could still perform any operation on it. Applications are expected to cooperate and respect locks consistently.
The standard lock-usage flow is:
The Pcd GL makes sure that at any given point in time there is not more than one lock active for a given resource. In order to detect and communicate potential conflicts, a user and session identifier have to be provided when requesting a lock.
It is important to differentiate between locks and lock objects:
The difference becomes apparent, when lifecycles are considered:
The lock object (instances of ILock) can be
in one of the following states:
ACTIVE: The lock object is backed by a lock in the
registry.
INACTIVE: The lock object is not backed by lock in the registry
- the resource is not locked!BROKEN: There exists a lock for the same resource, which is
associated with the ILock-instance, but either user id or
session id differ. This means that after creation of the ILock-instance,
some other user or session has obtained the lock.
A lock is usually owned by the user who requested it. However, it is sometimes necessary that other users can take the lock away from the original owner, because he/she forgot to release the respective resource. In a productive environment this clearly is an exceptional case. It can happen if e.g. an application is terminated irregularly so that stale locks stay in the registry.
In the Pcd GL, locks have a configurable protection-time, and an even longer life-time. During the protection-time, only the lock-owner or an admin can release a lock. After the protection-time, the lock is still valid, but can be released by any user. At the end of the lock-lifetime, the lock is released automatically.