Tripal
Public Member Functions | List of all members
Drupal\tripal_biodb\Lock\SharedLockBackendInterface Interface Reference
Inheritance diagram for Drupal\tripal_biodb\Lock\SharedLockBackendInterface:
Inheritance graph
[legend]
Collaboration diagram for Drupal\tripal_biodb\Lock\SharedLockBackendInterface:
Collaboration graph
[legend]

Public Member Functions

 acquire ( $name, $timeout=30.0, string $owner='', ?int $pid=NULL)
 
 acquireShared (string $name, float $timeout=30.0, string $owner='', ?int $pid=NULL)
 
 releaseShared (string $name, string $owner)
 
 getStartTime (string $name, ?string $owner=NULL)
 
 getOwners (string $name)
 
 getOwnerPid (string $name, ?string $owner=NULL)
 
- Public Member Functions inherited from Drupal\tripal_biodb\Lock\LockInfoInterface
 getStartTime (string $name)
 
 getCurrentExpirationTime (string $name)
 
 getCurrentExpirationDelay (string $name)
 
 getOwner (string $name)
 
 getOwnerPid (string $name)
 

Detailed Description

Shared lock backend interface.

A shared lock allows an element to be locked for one or more operations that can access the locked element concurrently without problems. However, it prevents an operation to acquire an exclusive lock on that element.

The lock meccanism is quite similar to the exclusive one except that more than one operation at a time can aquire a same shared lock. Operations that try to acquire the lock in exclusive mode are denied. Finaly, the lock will only be released once all operations that acquired it released it.

This type of lock is useful when an element needs to be accessed in reading mode by several operations (that wont alter it) but no other operation should be able to alter that element while it is in use by thoses operations.

This interface extends the existing LockBackendInterface interface with 2 new methods that are dedicated to acquire and release a shared lock.

Member Function Documentation

◆ acquire()

Drupal\tripal_biodb\Lock\SharedLockBackendInterface::acquire (   $name,
  $timeout = 30.0,
string  $owner = '',
?int  $pid = NULL 
)

Acquires a lock.

Parameters
string$nameLock name. Limit of name's length is 255 characters.
float$timeout(optional) Lock lifetime in seconds. Defaults to 30.0.
string$owner(optional) Name of the (exclusive) lock owner.
?int$pid (optional) An operating system process ID owning the lock. It may be used to release the lock if the given PID becomes unused. A value of 0 will prevent the share to be released based on a PID. Default: if NULL, the current process ID (getmypid()) will be used.
Returns
bool TRUE if acquired and FALSE otherwise.

Implemented in Drupal\tripal_biodb\Lock\PersistentDatabaseSharedLockBackend.

◆ acquireShared()

Drupal\tripal_biodb\Lock\SharedLockBackendInterface::acquireShared ( string  $name,
float  $timeout = 30.0,
string  $owner = '',
?int  $pid = NULL 
)

Acquires a shared lock.

Parameters
string$nameShared lock name. Limit of name's length is 255 characters.
float$timeout(optional) Shared lock lifetime in seconds. Defaults to 30.0.
string$ownerName of the owner willing a share on the lock (used as identifier).
?int$pid (optional) An operating system process ID owning the share. It may be used to release the lock if the given PID becomes unused. A value of 0 will prevent the share to be released based on a PID. Default: if NULL, the current process ID (getmypid()) will be used.
Returns
mixed The owner name if the shared lock has been acquired and FALSE otherwise.

Implemented in Drupal\tripal_biodb\Lock\PersistentDatabaseSharedLockBackend.

◆ getOwnerPid()

Drupal\tripal_biodb\Lock\SharedLockBackendInterface::getOwnerPid ( string  $name,
?string  $owner = NULL 
)

Returns the system process identifier using the shared or exclusive lock.

If no owner is specified, the lock is assumed to be exclusive and 0 will be returned in case of a sheared lock. If an owner is specified, the PID of the owner is returned.

Parameters
string$nameName of the lock.
?string$owner Name of the owner of the share of a shared lock.
Returns
int The system process identifier using this lock or 0 if not available.

Implemented in Drupal\tripal_biodb\Lock\PersistentDatabaseSharedLockBackend.

◆ getOwners()

Drupal\tripal_biodb\Lock\SharedLockBackendInterface::getOwners ( string  $name)

Returns the list of shared lock owners.

Parameters
string$nameName of the shared lock.
Returns
array An array of shared lock owner names.

Implemented in Drupal\tripal_biodb\Lock\PersistentDatabaseSharedLockBackend.

◆ getStartTime()

Drupal\tripal_biodb\Lock\SharedLockBackendInterface::getStartTime ( string  $name,
?string  $owner = NULL 
)

Returns the time in seconds when the lock started.

If no owner is specified, the lock is assumed to be exclusive and 0 will be returned in case of a shared lock. If an owner is specified, the starting time of the lock share of the specified owner is returned.

Parameters
string$nameName of the lock.
?string$owner Name of the owner of the share of a shared lock.
Returns
float The lock starting time in seconds or 0 if not available.

Implemented in Drupal\tripal_biodb\Lock\PersistentDatabaseSharedLockBackend.

◆ releaseShared()

Drupal\tripal_biodb\Lock\SharedLockBackendInterface::releaseShared ( string  $name,
string  $owner 
)

Releases the given shared lock.

Parameters
string$nameLock name.
string$ownerName of the owner of a share on the lock.

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