Documentation

SectorLock
in package

This class is responsible for ensuring that page processing occurs sequentially as requests come in, avoiding race conditions by using a blocking queue.

The lock creates exclusive access to a specified sector, since that is the primary way (caveat: but not the only way) in which simultaneous processing would create inconsistencies.

There are more elegant solutions to this problem (such a row-level locking within the database). There are also some deficiencies in this implementation, in particular the inability for a single player to lock two sectors at once (to avoid, e.g., race conditions with movement).

Table of Contents

Constants

LOCK_DURATION  = 10
The max time (in seconds) for a lock to be active before being considered stale.
RETRY_DURATION  = 5
The max time (in seconds) to retry acquiring locks before giving up.

Properties

$accountID  : int|null
$failed  : bool
$gameID  : int|null
$lockID  : int|null
$sectorID  : int|null

Methods

acquire()  : bool
Acquire an exclusive lock on a sector.
acquireForPlayer()  : bool
Convenience wrapper to acquire a lock for the player in their current sector.
getInstance()  : self
Returns the instance of this class from the DI container.
getSectorID()  : int
hasFailed()  : bool
isActive()  : bool
release()  : bool
resetInstance()  : void
Reset the instance of this class associated with this page request (i.e. stored in the DI container).
setFailed()  : void

Constants

LOCK_DURATION

The max time (in seconds) for a lock to be active before being considered stale.

private mixed LOCK_DURATION = 10

RETRY_DURATION

The max time (in seconds) to retry acquiring locks before giving up.

private mixed RETRY_DURATION = 5

Should be less than LOCK_DURATION.

Properties

Methods

acquire()

Acquire an exclusive lock on a sector.

public acquire(int $gameID, int $accountID, int $sectorID) : bool
Parameters
$gameID : int
$accountID : int
$sectorID : int
Return values
bool

True if a new lock is acquired or false if existing lock used.

acquireForPlayer()

Convenience wrapper to acquire a lock for the player in their current sector.

public acquireForPlayer(AbstractPlayer $player) : bool
Parameters
$player : AbstractPlayer
Return values
bool

getInstance()

Returns the instance of this class from the DI container.

public static getInstance() : self

The first time this is called, it will populate the DI container.

Return values
self

getSectorID()

public getSectorID() : int
Return values
int

hasFailed()

public hasFailed() : bool
Return values
bool

isActive()

public isActive() : bool
Tags
phpstan-assert-if-true

!null $this->lockID

Return values
bool

release()

public release() : bool
Return values
bool

Whether there was a lock to release or not

resetInstance()

Reset the instance of this class associated with this page request (i.e. stored in the DI container).

public static resetInstance() : void

NOTE: This should never be called by normal page requests, and should only be used by the CLI programs that run continuously.


        
On this page

Search results