Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
core\lock\lock_factory Interface Reference

Defines abstract factory class for generating locks. More...

Inheritance diagram for core\lock\lock_factory:
core\lock\db_record_lock_factory core\lock\file_lock_factory core\lock\installation_lock_factory core\lock\mysql_lock_factory core\lock\postgres_lock_factory core\lock\timing_wrapper_lock_factory

Public Member Functions

 __construct ($type)
 Define the constructor signature required by the lock_config class.
 
 get_lock ($resource, $timeout, $maxlifetime=86400)
 Get a lock within the specified timeout or return false.
 
 is_available ()
 Is available.
 
 release_lock (lock $lock)
 Release a lock that was previously obtained with @lock.
 
 supports_auto_release ()
 Will this lock be automatically released when the process ends.
 
 supports_timeout ()
 Return information about the blocking behaviour of the locks on this platform.
 

Detailed Description

Defines abstract factory class for generating locks.

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

Constructor & Destructor Documentation

◆ __construct()

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

Define the constructor signature required by the lock_config class.

Parameters
string$type- The type this lock is used for (e.g. cron, cache)

Implemented in core\lock\db_record_lock_factory, core\lock\installation_lock_factory, core\lock\mysql_lock_factory, and core\lock\postgres_lock_factory.

Member Function Documentation

◆ get_lock()

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

Get a lock within the specified timeout or return false.

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. Not all lock types will support this.
int$maxlifetime- The number of seconds to wait before reclaiming a stale lock. Not all lock types will use this - e.g. if they support auto releasing a lock when a process ends.
Return values
core\lock\lock|boolean- An instance of core\lock\lock if the lock was obtained, or false.

Implemented in core\lock\db_record_lock_factory, core\lock\file_lock_factory, core\lock\installation_lock_factory, core\lock\mysql_lock_factory, core\lock\postgres_lock_factory, and core\lock\timing_wrapper_lock_factory.

◆ is_available()

core\lock\lock_factory::is_available ( )

◆ release_lock()

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

Release a lock that was previously obtained with @lock.

Parameters
lock$lock- The lock to release.
Return values
boolean- True if the lock is no longer held (including if it was never held).

Implemented in core\lock\db_record_lock_factory, core\lock\file_lock_factory, core\lock\installation_lock_factory, core\lock\mysql_lock_factory, core\lock\postgres_lock_factory, and core\lock\timing_wrapper_lock_factory.

◆ supports_auto_release()

core\lock\lock_factory::supports_auto_release ( )

Will this lock be automatically released when the process ends.

This should never be relied upon in code - but is useful in the case of fatal errors. If a lock type does not support this auto release, the max lock time parameter must be obeyed to eventually clean up a lock.

Return values
boolean- True if this lock type will be automatically released when the current process ends.

Implemented in core\lock\db_record_lock_factory, core\lock\file_lock_factory, core\lock\installation_lock_factory, core\lock\mysql_lock_factory, core\lock\postgres_lock_factory, and core\lock\timing_wrapper_lock_factory.

◆ supports_timeout()

core\lock\lock_factory::supports_timeout ( )

Return information about the blocking behaviour of the locks on this platform.

Return values
boolean- False if attempting to get a lock will block indefinitely.

Implemented in core\lock\db_record_lock_factory, core\lock\file_lock_factory, core\lock\installation_lock_factory, core\lock\mysql_lock_factory, core\lock\postgres_lock_factory, and core\lock\timing_wrapper_lock_factory.


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