ConcurrencyManager.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2017 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
12 
15 
16 /**
17  * ConcurrencyManager is used to handle concurrency for objects.
18  * Depending on the lock type, locking has different semantics:
19  * - Optimistic locks can be aquired on the same object by different users.
20  * This lock quarantees that an exception is thrown, if the user tries
21  * to persist an object, which another used has updated, since the user
22  * retrieved it.
23  * - Pessimistic (write) locks can be aquired on the same object only by one
24  * user. This lock quarantees that no other user can modify the object
25  * until the lock is released.
26  * A user can only aquire one lock on each object. An exeption is thrown,
27  * if a user tries to aquire a lock on an object on which another user
28  * already owns a pessimistic lock.
29  *
30  * @author ingo herwig <ingo@wemove.com>
31  */
32 interface ConcurrencyManager {
33 
34  /**
35  * Aquire a lock on an ObjectId for the current user. Throws an exception if
36  * locking fails.
37  * @param $oid The object id of the object to lock.
38  * @param $type One of the Lock::Type constants.
39  * @param $currentState PersistentObject instance defining the current state
40  * for an optimistic lock (optional, if not given, the current state will
41  * be loaded from the store)
42  */
43  public function aquireLock(ObjectId $oid, $type, PersistentObject $currentState=null);
44 
45  /**
46  * Release a lock on an ObjectId for the current user.
47  * @param $oid object id of the object to release.
48  * @param $type One of the Lock::Type constants or null for all types (default: _null_)
49  */
50  public function releaseLock(ObjectId $oid, $type=null);
51 
52  /**
53  * Release all locks on an ObjectId regardless of the user.
54  * @param $oid object id of the object to release.
55  */
56  public function releaseLocks(ObjectId $oid);
57 
58  /**
59  * Release all locks for the current user.
60  */
61  public function releaseAllLocks();
62 
63  /**
64  * Get the lock for an object id.
65  * @param $oid object id of the object to get the lock data for.
66  * @return Lock instance or null
67  */
68  public function getLock(ObjectId $oid);
69 
70  /**
71  * Check if the given object can be persisted. Throws an exception if not.
72  * @param $object The object to check.
73  */
74  public function checkPersist(PersistentObject $object);
75 
76  /**
77  * Update the current state of the lock belonging to the given object
78  * if existing and owned by the current.
79  * @param $oid The object id.
80  * @param $object The updated object data.
81  */
82  public function updateLock(ObjectId $oid, PersistentObject $object);
83 }
84 ?>
releaseLocks(ObjectId $oid)
Release all locks on an ObjectId regardless of the user.
checkPersist(PersistentObject $object)
Check if the given object can be persisted.
updateLock(ObjectId $oid, PersistentObject $object)
Update the current state of the lock belonging to the given object if existing and owned by the curre...
ObjectId is the unique identifier of an object.
Definition: ObjectId.php:27
ConcurrencyManager is used to handle concurrency for objects.
aquireLock(ObjectId $oid, $type, PersistentObject $currentState=null)
Aquire a lock on an ObjectId for the current user.
releaseAllLocks()
Release all locks for the current user.
releaseLock(ObjectId $oid, $type=null)
Release a lock on an ObjectId for the current user.
getLock(ObjectId $oid)
Get the lock for an object id.
PersistentObject defines the interface of all persistent objects.