Grants short-lived, key-based locks so callers can serialise access to an entity or other resource, either within this server (local) or across the cluster (global). A caller builds a LockRequest via newLockRequest(), then locks it directly or runs a Runnable/Callable while holding it. Reached from JS as the registered entityLockManager service, though AppTransactionManager is the preferred entry point for app code.
Group: Managers
Properties
| Property | Returns | Description |
|---|---|---|
| lockStats | Map | Reports lock activity for both the local and global lock services, for the maintenance page in the root account. Each entry gives the lock service's implementation type and its internal statistics. |
Methods
getLockStats()
Returns: Map
Reports lock activity for both the local and global lock services, for the maintenance page in the root account. Each entry gives the lock service's implementation type and its internal statistics.
findLock(boolean isLocal, String key)
Returns: LockRequest
Looks up a currently held lock by its key.
| Parameter | Description |
|---|---|
isLocal | true to search the local (in-process) lock service, false for the global (cluster wide) service |
key | the lock key to look up |
currentLocks(int from, int maxSize, boolean isLocal)
Returns: List<LockRequest>
Returns a page of currently active locks.
| Parameter | Description |
|---|---|
from | the zero based index of the first lock to return |
maxSize | the maximum number of locks to return |
isLocal | true to page the local (in-process) lock service, false for the global (cluster wide) service |
newLockRequest(Object entity)
Returns: LockRequestBuilder
Starts building a lock request for the given target, deriving the lock key from it. The target must be a Relational database entity, or a String, Long or Integer to use directly as the key.
| Parameter | Description |
|---|---|
entity | the object to derive the lock key from |
lockAndRun(LockRequestBuilder lrb, Runnable r)
Returns: void
Acquires a lock built from the given request, runs the given task, then releases the lock, even if the task throws.
| Parameter | Description |
|---|---|
lrb | the lock request to build and acquire, which also selects the local or global lock service |
r | the task to run while the lock is held |
lockAndProduce(LockRequestBuilder lrb, Callable<T> c)
Returns: T
Acquires a lock built from the given request, runs the given task and returns its result, then releases the lock, even if the task throws.
| Parameter | Description |
|---|---|
lrb | the lock request to build and acquire, which also selects the local or global lock service |
c | the task to run while the lock is held |
getKey(Object targetObject)
Returns: String
Derives the lock key that would be used for the given target: a Relational entity's row id, or a String, Long or Integer used directly.
| Parameter | Description |
|---|---|
targetObject | the object to derive the lock key from |