Elgg  Version master
Public Member Functions | Protected Member Functions | List of all members
Elgg\Database\Mutex Class Reference

Provides database mutex that can be used to prevent race conditions between two processes that affect the same data. More...

Public Member Functions

 __construct (protected Database $db)
 Constructor. More...
 
 lock (string $namespace)
 Creates a table {prefix}{$namespace}_lock that is used as a mutex. More...
 
 unlock (string $namespace)
 Unlocks mutex. More...
 
 isLocked (string $namespace)
 Checks if mutex is locked. More...
 

Protected Member Functions

 assertNamespace (string $namespace)
 Assert that the namespace contains only characters [A-Za-z]. More...
 

Detailed Description

Provides database mutex that can be used to prevent race conditions between two processes that affect the same data.

NOTE: This class uses the database connections directly because the queries aren't QueryBuilders

Definition at line 18 of file Mutex.php.

Constructor & Destructor Documentation

Elgg\Database\Mutex::__construct ( protected Database  $db)

Constructor.

Parameters
Database$dbDatabase

Definition at line 27 of file Mutex.php.

Member Function Documentation

Elgg\Database\Mutex::assertNamespace ( string  $namespace)
protected

Assert that the namespace contains only characters [A-Za-z].

Parameters
string$namespaceNamespace to use for the database table
Returns
void
Exceptions
InvalidArgumentException

Definition at line 89 of file Mutex.php.

Elgg\Database\Mutex::isLocked ( string  $namespace)

Checks if mutex is locked.

Parameters
string$namespaceNamespace to use for the database table
Returns
bool

Definition at line 74 of file Mutex.php.

Elgg\Database\Mutex::lock ( string  $namespace)

Creates a table {prefix}{$namespace}_lock that is used as a mutex.

Parameters
string$namespaceAllows having separate locks for separate processes
Returns
bool

Definition at line 37 of file Mutex.php.

Elgg\Database\Mutex::unlock ( string  $namespace)

Unlocks mutex.

Parameters
string$namespaceNamespace to use for the database table
Returns
void

Definition at line 59 of file Mutex.php.


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