PHP Class Disque\Connection\Manager

Inheritance: implements Disque\Connection\ManagerInterface
Datei anzeigen Open project: mariano/disque-php Class Usage Examples

Protected Properties

Property Type Description
$credentials Disque\Connection\Credentials[] After connecting to one, the server returns a list of other nodes in the cluster so we can connect to them automatically, unless the discovered nodes are secured with a password. 'serverAddress' => Credentials
$nodeId string The ID of the node we are currently connected to
$nodePrefixes array Node prefix consists of the first 8 bytes from the node ID. Because job IDs contain the node prefix, it can be used to identify on which node a job lives. 'nodePrefix' => 'nodeId'
$nodes Disque\Connection\Node\Node[] 'nodeId' => Node
$priorityStrategy Disque\Connection\Node\NodePrioritizerInterface The default strategy is the ConservativeJobCountPrioritizer. It prioritizes nodes by their job count, but prefers the current node in order to avoid switching until there is a clearly better node.

Public Methods

Method Description
__construct ( )
addServer ( Disque\Connection\Credentials $credentials )
connect ( )
execute ( Disque\Command\CommandInterface $command )
getConnectionFactory ( )
getCredentials ( )
getCurrentNode ( )
getPriorityStrategy ( )
isConnected ( )
setConnectionFactory ( Disque\Connection\Factory\ConnectionFactoryInterface $connectionFactory )
setPriorityStrategy ( Disque\Connection\Node\NodePrioritizerInterface $priorityStrategy )

Protected Methods

Method Description
findAvailableConnection ( ) : Node Get a functional connection to any known node
getNodeConnection ( Disque\Connection\Credentials $server ) : Node Connect to the node given in the credentials
postprocessExecution ( Disque\Command\CommandInterface $command, mixed $response ) : mixed Postprocess the command execution, eg. update node stats
preprocessExecution ( Disque\Command\CommandInterface $command ) : Disque\Command\CommandInterface Hook into the command execution and do anything before it's executed
resetNodeCounters ( ) Reset node counters that should be reset upon node switch
updateNodeStats ( array $jobs ) Update node counters indicating how many jobs the node has produced

Private Methods

Method Description
copyNodeStats ( Node $oldNode, Node $newNode ) Copy node stats from the old to the new node
createNode ( Disque\Connection\Credentials $credentials ) : Node Create a new Node object
getNodeIdFromJobId ( string $jobId ) : string | null Get a node ID based off a Job ID
getNodePrefixFromJobId ( string $jobId ) : string Get the node prefix from the job ID
revealClusterFromHello ( Node $node ) Reveal the whole Disque cluster from a node HELLO response
revealNodeFromHello ( string $nodeId, array $node ) : Node Reveal a single node from a HELLO response, or use an existing node
shouldBeConnected ( ) : void We should be connected
switchNodeIfNeeded ( ) Decide if we should switch to a better node
switchToNode ( Node $node ) Switch to the given node and map the cluster from its HELLO
wasAlreadyConnected ( ) : boolean Check if the manager held a connection to Disque already

Method Details

__construct() public method

public __construct ( )

addServer() public method

public addServer ( Disque\Connection\Credentials $credentials )
$credentials Disque\Connection\Credentials

connect() public method

public connect ( )

execute() public method

public execute ( Disque\Command\CommandInterface $command )
$command Disque\Command\CommandInterface

findAvailableConnection() protected method

Disque suggests the first connection should be chosen randomly We go through the user-supplied credentials randomly and try to connect.
protected findAvailableConnection ( ) : Node
return Disque\Connection\Node\Node A connected node

getConnectionFactory() public method

getCredentials() public method

public getCredentials ( )

getCurrentNode() public method

public getCurrentNode ( )

getNodeConnection() protected method

Connect to the node given in the credentials
protected getNodeConnection ( Disque\Connection\Credentials $server ) : Node
$server Disque\Connection\Credentials
return Disque\Connection\Node\Node A connected node

getPriorityStrategy() public method

public getPriorityStrategy ( )

isConnected() public method

public isConnected ( )

postprocessExecution() protected method

Postprocess the command execution, eg. update node stats
protected postprocessExecution ( Disque\Command\CommandInterface $command, mixed $response ) : mixed
$command Disque\Command\CommandInterface
$response mixed
return mixed

preprocessExecution() protected method

Eg. start measuring node latency etc.
protected preprocessExecution ( Disque\Command\CommandInterface $command ) : Disque\Command\CommandInterface
$command Disque\Command\CommandInterface
return Disque\Command\CommandInterface $command

resetNodeCounters() protected method

Reset node counters that should be reset upon node switch
protected resetNodeCounters ( )

setConnectionFactory() public method

public setConnectionFactory ( Disque\Connection\Factory\ConnectionFactoryInterface $connectionFactory )
$connectionFactory Disque\Connection\Factory\ConnectionFactoryInterface

setPriorityStrategy() public method

public setPriorityStrategy ( Disque\Connection\Node\NodePrioritizerInterface $priorityStrategy )
$priorityStrategy Disque\Connection\Node\NodePrioritizerInterface

updateNodeStats() protected method

Update node counters indicating how many jobs the node has produced
protected updateNodeStats ( array $jobs )
$jobs array Jobs

Property Details

$credentials protected_oe property

After connecting to one, the server returns a list of other nodes in the cluster so we can connect to them automatically, unless the discovered nodes are secured with a password. 'serverAddress' => Credentials
protected Credentials[],Disque\Connection $credentials
return Disque\Connection\Credentials[]

$nodeId protected_oe property

The ID of the node we are currently connected to
protected string $nodeId
return string

$nodePrefixes protected_oe property

Node prefix consists of the first 8 bytes from the node ID. Because job IDs contain the node prefix, it can be used to identify on which node a job lives. 'nodePrefix' => 'nodeId'
protected array $nodePrefixes
return array

$nodes protected_oe property

'nodeId' => Node
protected Node[],Disque\Connection\Node $nodes
return Disque\Connection\Node\Node[]

$priorityStrategy protected_oe property

The default strategy is the ConservativeJobCountPrioritizer. It prioritizes nodes by their job count, but prefers the current node in order to avoid switching until there is a clearly better node.
protected NodePrioritizerInterface,Disque\Connection\Node $priorityStrategy
return Disque\Connection\Node\NodePrioritizerInterface