Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
core\lock\db_record_lock_factory Class Reference

This is a db record locking factory. More...

Inheritance diagram for core\lock\db_record_lock_factory:
core\lock\lock_factory

Public Member Functions

 __construct ($type)
 Almighty constructor.
 
 auto_release ()
 Auto release any open locks on shutdown.
 
 extend_lock (lock $lock, $maxlifetime=86400)
 Extend a lock that was previously obtained with @lock.
 
 get_lock ($resource, $timeout, $maxlifetime=86400)
 Create and get a lock.
 
 is_available ()
 Is available.
 
 release_lock (lock $lock)
 Release a lock that was previously obtained with @lock.
 
 supports_auto_release ()
 Will this lock type will be automatically released when a process ends.
 
 supports_recursion ()
 Multiple locks for the same resource can be held by a single process.
 
 supports_timeout ()
 Return information about the blocking behaviour of the lock type on this platform.
 

Protected Member Functions

 generate_unique_token ()
 This function generates a unique token for the lock to use.
 

Protected Attributes

moodle_database $db
 $db Hold a reference to the global $DB
 
array $openlocks = array()
 $openlocks - List of held locks - used by auto-release
 
string $type
 $type Used to prefix lock keys
 

Detailed Description

This is a db record locking factory.

This lock factory uses record locks relying on sql of the form "SET XXX where YYY" and checking if the value was set. It supports timeouts, autorelease and can work on any DB. The downside - is this will always be slower than some shared memory type locking function.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

core\lock\db_record_lock_factory::__construct ( $type)

Almighty constructor.

Parameters
string$type- Used to prefix lock keys.

Implements core\lock\lock_factory.

Member Function Documentation

◆ auto_release()

core\lock\db_record_lock_factory::auto_release ( )

Auto release any open locks on shutdown.

This is required, because we may be using persistent DB connections.

◆ extend_lock()

core\lock\db_record_lock_factory::extend_lock ( lock $lock,
$maxlifetime = 86400 )

Extend a lock that was previously obtained with @lock.

Deprecated
since Moodle 3.10.
Parameters
lock$lock- a lock obtained from this factory.
int$maxlifetime- the new lifetime for the lock (in seconds).
Return values
boolean- true if the lock was extended.

Implements core\lock\lock_factory.

◆ generate_unique_token()

core\lock\db_record_lock_factory::generate_unique_token ( )
protected

This function generates a unique token for the lock to use.

It is important that this token is not solely based on time as this could lead to duplicates in a clustered environment (especially on VMs due to poor time precision).

◆ get_lock()

core\lock\db_record_lock_factory::get_lock ( $resource,
$timeout,
$maxlifetime = 86400 )

Create and get a lock.

Parameters
string$resource- The identifier for the lock. Should use frankenstyle prefix.
int$timeout- The number of seconds to wait for a lock before giving up.
int$maxlifetime- Unused by this lock type.
Return values
boolean- true if a lock was obtained.

Implements core\lock\lock_factory.

◆ is_available()

core\lock\db_record_lock_factory::is_available ( )

Is available.

Return values
boolean- True if this lock type is available in this environment.

Implements core\lock\lock_factory.

◆ release_lock()

core\lock\db_record_lock_factory::release_lock ( lock $lock)

Release a lock that was previously obtained with @lock.

Parameters
lock$lock- a lock obtained from this factory.
Return values
boolean- true if the lock is no longer held (including if it was never held).

Implements core\lock\lock_factory.

◆ supports_auto_release()

core\lock\db_record_lock_factory::supports_auto_release ( )

Will this lock type will be automatically released when a process ends.

Return values
boolean- True (shutdown handler)

Implements core\lock\lock_factory.

◆ supports_recursion()

core\lock\db_record_lock_factory::supports_recursion ( )

Multiple locks for the same resource can be held by a single process.

Deprecated
since Moodle 3.10.
Return values
boolean- False - not process specific.

Implements core\lock\lock_factory.

◆ supports_timeout()

core\lock\db_record_lock_factory::supports_timeout ( )

Return information about the blocking behaviour of the lock type on this platform.

Return values
boolean- True

Implements core\lock\lock_factory.


The documentation for this class was generated from the following file: