Horde_Lock_Mongo
extends Horde_Lock
in package
Lock storage in a MongoDB database.
Tags
Table of Contents
- EXPIRY_TS = 'expiry_ts'
- LID = 'lid'
- ORIGIN_TS = 'origin_ts'
- OWNER = 'owner'
- PERMANENT = -1
- PRINCIPAL = 'principal'
- SCOPE = 'scope'
- TYPE = 'type'
- TYPE_EXCLUSIVE = 1
- TYPE_SHARED = 2
- UPDATE_TS = 'update_ts'
- $_db : MongoCollection
- The MongoDB Collection object for the cache data.
- $_logger : Horde_Log_Logger
- Logger.
- $_map : array<string|int, mixed>
- Ugly hack: lock driver written with assumption that it returns data as defined by SQL columns. So need to do mapping in this driver.
- $_params : array<string|int, mixed>
- Driver parameters.
- __construct() : mixed
- Constructor.
- __destruct() : mixed
- Destructor.
- clearLock() : bool
- Removes a lock given the lock ID.
- gc() : mixed
- Do garbage collection needed for the driver.
- getLockInfo() : array<string|int, mixed>
- Return an array of information about the requested lock.
- getLocks() : array<string|int, mixed>
- Return a list of valid locks with the option to limit the results by principal, scope and/or type.
- resetLock() : bool
- Extend the valid lifetime of a valid lock to now + $extend.
- setLock() : mixed
- Sets a lock on the requested principal and returns the generated lock ID. NOTE: No security checks are done in the Horde_Lock API. It is expected that the calling application has done all necessary security checks before requesting a lock be granted.
- _mapFields() : array<string|int, mixed>
- Map return to SQL fields.
Constants
EXPIRY_TS
public
mixed
EXPIRY_TS
= 'expiry_ts'
LID
public
mixed
LID
= 'lid'
ORIGIN_TS
public
mixed
ORIGIN_TS
= 'origin_ts'
OWNER
public
mixed
OWNER
= 'owner'
PERMANENT
public
mixed
PERMANENT
= -1
PRINCIPAL
public
mixed
PRINCIPAL
= 'principal'
SCOPE
public
mixed
SCOPE
= 'scope'
TYPE
public
mixed
TYPE
= 'type'
TYPE_EXCLUSIVE
public
mixed
TYPE_EXCLUSIVE
= 1
TYPE_SHARED
public
mixed
TYPE_SHARED
= 2
UPDATE_TS
public
mixed
UPDATE_TS
= 'update_ts'
Properties
$_db
The MongoDB Collection object for the cache data.
protected
MongoCollection
$_db
$_logger
Logger.
protected
Horde_Log_Logger
$_logger
$_map
Ugly hack: lock driver written with assumption that it returns data as defined by SQL columns. So need to do mapping in this driver.
protected
array<string|int, mixed>
$_map
= array(self::EXPIRY_TS => 'lock_expiry_timestamp', self::LID => 'lock_id', self::ORIGIN_TS => 'lock_origin_timestamp', self::OWNER => 'lock_owner', self::PRINCIPAL => 'lock_principal', self::SCOPE => 'lock_scope', self::TYPE => 'lock_type', self::UPDATE_TS => 'lock_update_timestamp')
$_params
Driver parameters.
protected
array<string|int, mixed>
$_params
Methods
__construct()
Constructor.
public
__construct([array<string|int, mixed> $params = array() ]) : mixed
Parameters
- $params : array<string|int, mixed> = array()
-
Parameters:
- collection: (string) The collection name. - mongo_db: [REQUIRED] (Horde_Mongo_Client) A MongoDB client object.
Return values
mixed —__destruct()
Destructor.
public
__destruct() : mixed
Return values
mixed —clearLock()
Removes a lock given the lock ID.
public
clearLock(mixed $lockid) : bool
Parameters
- $lockid : mixed
-
The lock ID as generated by a previous call to setLock()
Return values
bool —Returns true on success.
gc()
Do garbage collection needed for the driver.
public
gc() : mixed
Return values
mixed —getLockInfo()
Return an array of information about the requested lock.
public
getLockInfo(mixed $lockid) : array<string|int, mixed>
Parameters
- $lockid : mixed
-
Lock ID to look up.
Return values
array<string|int, mixed> —Lock information.
getLocks()
Return a list of valid locks with the option to limit the results by principal, scope and/or type.
public
getLocks([mixed $scope = null ][, mixed $principal = null ][, mixed $type = null ]) : array<string|int, mixed>
Parameters
- $scope : mixed = null
-
The scope of the lock. Typically the name of the application requesting the lock or some other identifier used to group locks together.
- $principal : mixed = null
-
Principal for which to check for locks
- $type : mixed = null
-
Only return locks of the given type. Defaults to null, or all locks
Return values
array<string|int, mixed> —Array of locks with the ID as the key and the lock details as the value. If there are no current locks this will return an empty array.
resetLock()
Extend the valid lifetime of a valid lock to now + $extend.
public
resetLock(mixed $lockid, mixed $lifetime) : bool
Parameters
- $lockid : mixed
-
Lock ID to reset. Must be a valid, non-expired lock.
- $lifetime : mixed
Return values
bool —Returns true on success.
setLock()
Sets a lock on the requested principal and returns the generated lock ID. NOTE: No security checks are done in the Horde_Lock API. It is expected that the calling application has done all necessary security checks before requesting a lock be granted.
public
setLock(mixed $requestor, mixed $scope, mixed $principal[, mixed $lifetime = 1 ][, mixed $type = Horde_Lock::TYPE_SHARED ]) : mixed
Parameters
- $requestor : mixed
-
User ID of the lock requestor.
- $scope : mixed
-
The scope of the lock. Typically the name of the application requesting the lock or some other identifier used to group locks together.
- $principal : mixed
-
A principal on which a lock should be granted. The format can be any string but is suggested to be in URI form.
- $lifetime : mixed = 1
-
Time (in seconds) for which the lock will be considered valid.
- $type : mixed = Horde_Lock::TYPE_SHARED
Return values
mixed —A string lock ID.
_mapFields()
Map return to SQL fields.
protected
_mapFields(mixed $res) : array<string|int, mixed>
Parameters
- $res : mixed