Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | List of all members
core\lock\lock_factory Interface Reference
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\postgres_lock_factory

Public Member Functions

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

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\postgres_lock_factory, core\lock\installation_lock_factory, core\lock\file_lock_factory, and core\lock\db_record_lock_factory.

Member Function Documentation

◆ extend_lock()

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

Extend the timeout on a held lock.

Parameters
lock$lock- lock obtained from this factory
int$maxlifetime- new max time to hold the lock
Return values
boolean- True if the lock was extended.

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

◆ 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

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

◆ is_available()

core\lock\lock_factory::is_available ( )

Is available.

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

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

◆ 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\postgres_lock_factory, core\lock\installation_lock_factory, core\lock\file_lock_factory, and core\lock\db_record_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\postgres_lock_factory, core\lock\installation_lock_factory, core\lock\file_lock_factory, and core\lock\db_record_lock_factory.

◆ supports_recursion()

core\lock\lock_factory::supports_recursion ( )

Supports recursion.

Return values
boolean- True if attempting to get 2 locks on the same resource will "stack"

Implemented in core\lock\postgres_lock_factory, core\lock\installation_lock_factory, core\lock\file_lock_factory, and core\lock\db_record_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\postgres_lock_factory, core\lock\installation_lock_factory, core\lock\file_lock_factory, and core\lock\db_record_lock_factory.


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