Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/ApiCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class ApiCall
/**
* @var array|Node[]
*/
private static array $nodes;
private array $nodes;

/**
* @var Node|null
*/
private static ?Node $nearestNode;
private ?Node $nearestNode;

/**
* @var int
Expand All @@ -73,8 +73,8 @@ public function __construct(Configuration $config)
$this->config = $config;
$this->logger = $config->getLogger();
$this->client = $config->getClient();
static::$nodes = $this->config->getNodes();
static::$nearestNode = $this->config->getNearestNode();
$this->nodes = $this->config->getNodes();
$this->nearestNode = $this->config->getNearestNode();
$this->nodeIndex = 0;
$this->initializeNodes();
}
Expand All @@ -84,11 +84,11 @@ public function __construct(Configuration $config)
*/
private function initializeNodes(): void
{
if (static::$nearestNode !== null) {
$this->setNodeHealthCheck(static::$nearestNode, true);
if ($this->nearestNode !== null) {
$this->setNodeHealthCheck($this->nearestNode, true);
}

foreach (static::$nodes as &$node) {
foreach ($this->nodes as &$node) {
$this->setNodeHealthCheck($node, true);
}
}
Expand Down Expand Up @@ -332,16 +332,16 @@ public function setNodeHealthCheck(Node $node, bool $isHealthy): void
*/
public function getNode(): Lib\Node
{
if (static::$nearestNode !== null) {
if (static::$nearestNode->isHealthy() || $this->nodeDueForHealthCheck(static::$nearestNode)) {
return static::$nearestNode;
if ($this->nearestNode !== null) {
if ($this->nearestNode->isHealthy() || $this->nodeDueForHealthCheck($this->nearestNode)) {
return $this->nearestNode;
}
}
$i = 0;
while ($i < count(static::$nodes)) {
while ($i < count($this->nodes)) {
$i++;
$node = static::$nodes[$this->nodeIndex];
$this->nodeIndex = ($this->nodeIndex + 1) % count(static::$nodes);
$node = $this->nodes[$this->nodeIndex];
$this->nodeIndex = ($this->nodeIndex + 1) % count($this->nodes);
if ($node->isHealthy() || $this->nodeDueForHealthCheck($node)) {
return $node;
}
Expand All @@ -351,7 +351,7 @@ public function getNode(): Lib\Node
* None of the nodes are marked healthy, but some of them could have become healthy since last health check.
* So we will just return the next node.
*/
return static::$nodes[$this->nodeIndex];
return $this->nodes[$this->nodeIndex];
}

/**
Expand Down