@@ -15,6 +15,5 @@ |
||
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception; |
| 16 | 16 | |
| 17 | 17 | use RuntimeException; |
| 18 | -class NoNodeAvailableException extends RuntimeException implements TransportException |
|
| 19 | -{ |
|
| 18 | +class NoNodeAvailableException extends RuntimeException implements TransportException { |
|
| 20 | 19 | } |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception; |
| 16 | 16 | |
| 17 | 17 | use RuntimeException; |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception; |
| 16 | 16 | |
| 17 | 17 | use Throwable; |
@@ -15,6 +15,5 @@ |
||
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception; |
| 16 | 16 | |
| 17 | 17 | use Throwable; |
| 18 | -interface TransportException extends Throwable |
|
| 19 | -{ |
|
| 18 | +interface TransportException extends Throwable { |
|
| 20 | 19 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport; |
| 16 | 16 | |
| 17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\NodePoolInterface; |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | try { |
| 100 | 100 | list($name, $encoded) = \explode(':', $cloudId); |
| 101 | 101 | list($uri, $uuids) = \explode('$', \base64_decode($encoded)); |
| 102 | - list($es, ) = \explode(':', $uuids); |
|
| 102 | + list($es,) = \explode(':', $uuids); |
|
| 103 | 103 | return \sprintf("https://%s.%s", $es, $uri); |
| 104 | 104 | } catch (Throwable $t) { |
| 105 | 105 | throw new Exception\CloudIdParseException('Cloud ID not valid'); |
@@ -24,8 +24,7 @@ |
||
| 24 | 24 | use Psr\Log\LoggerInterface; |
| 25 | 25 | use Psr\Log\NullLogger; |
| 26 | 26 | use Throwable; |
| 27 | -class TransportBuilder |
|
| 28 | -{ |
|
| 27 | +class TransportBuilder { |
|
| 29 | 28 | protected ClientInterface $client; |
| 30 | 29 | protected NodePoolInterface $nodePool; |
| 31 | 30 | protected LoggerInterface $logger; |
@@ -27,84 +27,84 @@ |
||
| 27 | 27 | use Throwable; |
| 28 | 28 | class TransportBuilder |
| 29 | 29 | { |
| 30 | - protected ClientInterface $client; |
|
| 31 | - protected NodePoolInterface $nodePool; |
|
| 32 | - protected LoggerInterface $logger; |
|
| 33 | - protected array $hosts = []; |
|
| 34 | - protected TracerInterface $OTelTracer; |
|
| 35 | - public final function __construct() |
|
| 36 | - { |
|
| 37 | - } |
|
| 38 | - public static function create() : TransportBuilder |
|
| 39 | - { |
|
| 40 | - return new static(); |
|
| 41 | - } |
|
| 42 | - public function setClient(ClientInterface $client) : self |
|
| 43 | - { |
|
| 44 | - $this->client = $client; |
|
| 45 | - return $this; |
|
| 46 | - } |
|
| 47 | - public function getClient() : ClientInterface |
|
| 48 | - { |
|
| 49 | - if (empty($this->client)) { |
|
| 50 | - $this->client = Psr18ClientDiscovery::find(); |
|
| 51 | - } |
|
| 52 | - return $this->client; |
|
| 53 | - } |
|
| 54 | - public function setNodePool(NodePoolInterface $nodePool) : self |
|
| 55 | - { |
|
| 56 | - $this->nodePool = $nodePool; |
|
| 57 | - return $this; |
|
| 58 | - } |
|
| 59 | - public function getNodePool() : NodePoolInterface |
|
| 60 | - { |
|
| 61 | - if (empty($this->nodePool)) { |
|
| 62 | - $this->nodePool = new SimpleNodePool(new RoundRobin(), new NoResurrect()); |
|
| 63 | - } |
|
| 64 | - return $this->nodePool; |
|
| 65 | - } |
|
| 66 | - public function setLogger(LoggerInterface $logger) : self |
|
| 67 | - { |
|
| 68 | - $this->logger = $logger; |
|
| 69 | - return $this; |
|
| 70 | - } |
|
| 71 | - public function getLogger() : LoggerInterface |
|
| 72 | - { |
|
| 73 | - if (empty($this->logger)) { |
|
| 74 | - $this->logger = new NullLogger(); |
|
| 75 | - } |
|
| 76 | - return $this->logger; |
|
| 77 | - } |
|
| 78 | - public function setHosts(array $hosts) : self |
|
| 79 | - { |
|
| 80 | - $this->hosts = $hosts; |
|
| 81 | - return $this; |
|
| 82 | - } |
|
| 83 | - public function getHosts() : array |
|
| 84 | - { |
|
| 85 | - return $this->hosts; |
|
| 86 | - } |
|
| 87 | - public function setCloudId(string $cloudId) : self |
|
| 88 | - { |
|
| 89 | - $this->hosts = [$this->parseElasticCloudId($cloudId)]; |
|
| 90 | - return $this; |
|
| 91 | - } |
|
| 92 | - public function build() : Transport |
|
| 93 | - { |
|
| 94 | - return new Transport($this->getClient(), $this->getNodePool()->setHosts($this->hosts), $this->getLogger()); |
|
| 95 | - } |
|
| 96 | - /** |
|
| 97 | - * Return the URL of Elastic Cloud from the Cloud ID |
|
| 98 | - */ |
|
| 99 | - private function parseElasticCloudId(string $cloudId) : string |
|
| 100 | - { |
|
| 101 | - try { |
|
| 102 | - list($name, $encoded) = \explode(':', $cloudId); |
|
| 103 | - list($uri, $uuids) = \explode('$', \base64_decode($encoded)); |
|
| 104 | - list($es, ) = \explode(':', $uuids); |
|
| 105 | - return \sprintf("https://%s.%s", $es, $uri); |
|
| 106 | - } catch (Throwable $t) { |
|
| 107 | - throw new Exception\CloudIdParseException('Cloud ID not valid'); |
|
| 108 | - } |
|
| 109 | - } |
|
| 30 | + protected ClientInterface $client; |
|
| 31 | + protected NodePoolInterface $nodePool; |
|
| 32 | + protected LoggerInterface $logger; |
|
| 33 | + protected array $hosts = []; |
|
| 34 | + protected TracerInterface $OTelTracer; |
|
| 35 | + public final function __construct() |
|
| 36 | + { |
|
| 37 | + } |
|
| 38 | + public static function create() : TransportBuilder |
|
| 39 | + { |
|
| 40 | + return new static(); |
|
| 41 | + } |
|
| 42 | + public function setClient(ClientInterface $client) : self |
|
| 43 | + { |
|
| 44 | + $this->client = $client; |
|
| 45 | + return $this; |
|
| 46 | + } |
|
| 47 | + public function getClient() : ClientInterface |
|
| 48 | + { |
|
| 49 | + if (empty($this->client)) { |
|
| 50 | + $this->client = Psr18ClientDiscovery::find(); |
|
| 51 | + } |
|
| 52 | + return $this->client; |
|
| 53 | + } |
|
| 54 | + public function setNodePool(NodePoolInterface $nodePool) : self |
|
| 55 | + { |
|
| 56 | + $this->nodePool = $nodePool; |
|
| 57 | + return $this; |
|
| 58 | + } |
|
| 59 | + public function getNodePool() : NodePoolInterface |
|
| 60 | + { |
|
| 61 | + if (empty($this->nodePool)) { |
|
| 62 | + $this->nodePool = new SimpleNodePool(new RoundRobin(), new NoResurrect()); |
|
| 63 | + } |
|
| 64 | + return $this->nodePool; |
|
| 65 | + } |
|
| 66 | + public function setLogger(LoggerInterface $logger) : self |
|
| 67 | + { |
|
| 68 | + $this->logger = $logger; |
|
| 69 | + return $this; |
|
| 70 | + } |
|
| 71 | + public function getLogger() : LoggerInterface |
|
| 72 | + { |
|
| 73 | + if (empty($this->logger)) { |
|
| 74 | + $this->logger = new NullLogger(); |
|
| 75 | + } |
|
| 76 | + return $this->logger; |
|
| 77 | + } |
|
| 78 | + public function setHosts(array $hosts) : self |
|
| 79 | + { |
|
| 80 | + $this->hosts = $hosts; |
|
| 81 | + return $this; |
|
| 82 | + } |
|
| 83 | + public function getHosts() : array |
|
| 84 | + { |
|
| 85 | + return $this->hosts; |
|
| 86 | + } |
|
| 87 | + public function setCloudId(string $cloudId) : self |
|
| 88 | + { |
|
| 89 | + $this->hosts = [$this->parseElasticCloudId($cloudId)]; |
|
| 90 | + return $this; |
|
| 91 | + } |
|
| 92 | + public function build() : Transport |
|
| 93 | + { |
|
| 94 | + return new Transport($this->getClient(), $this->getNodePool()->setHosts($this->hosts), $this->getLogger()); |
|
| 95 | + } |
|
| 96 | + /** |
|
| 97 | + * Return the URL of Elastic Cloud from the Cloud ID |
|
| 98 | + */ |
|
| 99 | + private function parseElasticCloudId(string $cloudId) : string |
|
| 100 | + { |
|
| 101 | + try { |
|
| 102 | + list($name, $encoded) = \explode(':', $cloudId); |
|
| 103 | + list($uri, $uuids) = \explode('$', \base64_decode($encoded)); |
|
| 104 | + list($es, ) = \explode(':', $uuids); |
|
| 105 | + return \sprintf("https://%s.%s", $es, $uri); |
|
| 106 | + } catch (Throwable $t) { |
|
| 107 | + throw new Exception\CloudIdParseException('Cloud ID not valid'); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | } |
@@ -20,25 +20,25 @@ |
||
| 20 | 20 | use function substr; |
| 21 | 21 | class Node |
| 22 | 22 | { |
| 23 | - protected UriInterface $uri; |
|
| 24 | - protected bool $alive = \true; |
|
| 25 | - public function __construct(string $host) |
|
| 26 | - { |
|
| 27 | - if (substr($host, 0, 5) !== 'http:' && substr($host, 0, 6) !== 'https:') { |
|
| 28 | - $host = sprintf("http://%s", $host); |
|
| 29 | - } |
|
| 30 | - $this->uri = Psr17FactoryDiscovery::findUriFactory()->createUri($host); |
|
| 31 | - } |
|
| 32 | - public function markAlive(bool $alive) : void |
|
| 33 | - { |
|
| 34 | - $this->alive = $alive; |
|
| 35 | - } |
|
| 36 | - public function isAlive() : bool |
|
| 37 | - { |
|
| 38 | - return $this->alive; |
|
| 39 | - } |
|
| 40 | - public function getUri() : UriInterface |
|
| 41 | - { |
|
| 42 | - return $this->uri; |
|
| 43 | - } |
|
| 23 | + protected UriInterface $uri; |
|
| 24 | + protected bool $alive = \true; |
|
| 25 | + public function __construct(string $host) |
|
| 26 | + { |
|
| 27 | + if (substr($host, 0, 5) !== 'http:' && substr($host, 0, 6) !== 'https:') { |
|
| 28 | + $host = sprintf("http://%s", $host); |
|
| 29 | + } |
|
| 30 | + $this->uri = Psr17FactoryDiscovery::findUriFactory()->createUri($host); |
|
| 31 | + } |
|
| 32 | + public function markAlive(bool $alive) : void |
|
| 33 | + { |
|
| 34 | + $this->alive = $alive; |
|
| 35 | + } |
|
| 36 | + public function isAlive() : bool |
|
| 37 | + { |
|
| 38 | + return $this->alive; |
|
| 39 | + } |
|
| 40 | + public function getUri() : UriInterface |
|
| 41 | + { |
|
| 42 | + return $this->uri; |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool; |
| 16 | 16 | |
| 17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Http\Discovery\Psr17FactoryDiscovery; |
@@ -18,8 +18,7 @@ |
||
| 18 | 18 | use OCA\FullTextSearch_Elasticsearch\Vendor\Psr\Http\Message\UriInterface; |
| 19 | 19 | use function sprintf; |
| 20 | 20 | use function substr; |
| 21 | -class Node |
|
| 22 | -{ |
|
| 21 | +class Node { |
|
| 23 | 22 | protected UriInterface $uri; |
| 24 | 23 | protected bool $alive = \true; |
| 25 | 24 | public function __construct(string $host) |
@@ -16,9 +16,9 @@ |
||
| 16 | 16 | |
| 17 | 17 | interface NodePoolInterface |
| 18 | 18 | { |
| 19 | - public function nextNode() : Node; |
|
| 20 | - /** |
|
| 21 | - * @param string[] $hosts |
|
| 22 | - */ |
|
| 23 | - public function setHosts(array $hosts) : self; |
|
| 19 | + public function nextNode() : Node; |
|
| 20 | + /** |
|
| 21 | + * @param string[] $hosts |
|
| 22 | + */ |
|
| 23 | + public function setHosts(array $hosts) : self; |
|
| 24 | 24 | } |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool; |
| 16 | 16 | |
| 17 | 17 | interface NodePoolInterface |
@@ -14,8 +14,7 @@ |
||
| 14 | 14 | declare (strict_types=1); |
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool; |
| 16 | 16 | |
| 17 | -interface NodePoolInterface |
|
| 18 | -{ |
|
| 17 | +interface NodePoolInterface { |
|
| 19 | 18 | public function nextNode() : Node; |
| 20 | 19 | /** |
| 21 | 20 | * @param string[] $hosts |
@@ -17,13 +17,13 @@ |
||
| 17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Node; |
| 18 | 18 | interface SelectorInterface |
| 19 | 19 | { |
| 20 | - public function nextNode() : Node; |
|
| 21 | - /** |
|
| 22 | - * @param Node[] $nodes |
|
| 23 | - */ |
|
| 24 | - public function setNodes(array $nodes) : void; |
|
| 25 | - /** |
|
| 26 | - * @return Node[] |
|
| 27 | - */ |
|
| 28 | - public function getNodes() : array; |
|
| 20 | + public function nextNode() : Node; |
|
| 21 | + /** |
|
| 22 | + * @param Node[] $nodes |
|
| 23 | + */ |
|
| 24 | + public function setNodes(array $nodes) : void; |
|
| 25 | + /** |
|
| 26 | + * @return Node[] |
|
| 27 | + */ |
|
| 28 | + public function getNodes() : array; |
|
| 29 | 29 | } |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Selector; |
| 16 | 16 | |
| 17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Node; |
@@ -15,8 +15,7 @@ |
||
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Selector; |
| 16 | 16 | |
| 17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Node; |
| 18 | -interface SelectorInterface |
|
| 19 | -{ |
|
| 18 | +interface SelectorInterface { |
|
| 20 | 19 | public function nextNode() : Node; |
| 21 | 20 | /** |
| 22 | 21 | * @param Node[] $nodes |
@@ -18,17 +18,17 @@ |
||
| 18 | 18 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\NoNodeAvailableException; |
| 19 | 19 | class RoundRobin implements SelectorInterface |
| 20 | 20 | { |
| 21 | - use SelectorTrait; |
|
| 22 | - public function nextNode() : Node |
|
| 23 | - { |
|
| 24 | - if (empty($this->getNodes())) { |
|
| 25 | - $className = \substr(__CLASS__, \strrpos(__CLASS__, '\\') + 1); |
|
| 26 | - throw new NoNodeAvailableException(\sprintf("No node available. Please use %s::setNodes() before calling %s::nextNode().", $className, $className)); |
|
| 27 | - } |
|
| 28 | - $node = \current($this->nodes); |
|
| 29 | - if (\false === \next($this->nodes)) { |
|
| 30 | - \reset($this->nodes); |
|
| 31 | - } |
|
| 32 | - return $node; |
|
| 33 | - } |
|
| 21 | + use SelectorTrait; |
|
| 22 | + public function nextNode() : Node |
|
| 23 | + { |
|
| 24 | + if (empty($this->getNodes())) { |
|
| 25 | + $className = \substr(__CLASS__, \strrpos(__CLASS__, '\\') + 1); |
|
| 26 | + throw new NoNodeAvailableException(\sprintf("No node available. Please use %s::setNodes() before calling %s::nextNode().", $className, $className)); |
|
| 27 | + } |
|
| 28 | + $node = \current($this->nodes); |
|
| 29 | + if (\false === \next($this->nodes)) { |
|
| 30 | + \reset($this->nodes); |
|
| 31 | + } |
|
| 32 | + return $node; |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -16,8 +16,7 @@ |
||
| 16 | 16 | |
| 17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Node; |
| 18 | 18 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\NoNodeAvailableException; |
| 19 | -class RoundRobin implements SelectorInterface |
|
| 20 | -{ |
|
| 19 | +class RoundRobin implements SelectorInterface { |
|
| 21 | 20 | use SelectorTrait; |
| 22 | 21 | public function nextNode() : Node |
| 23 | 22 | { |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Selector; |
| 16 | 16 | |
| 17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Node; |
@@ -18,18 +18,18 @@ |
||
| 18 | 18 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\InvalidArrayException; |
| 19 | 19 | trait SelectorTrait |
| 20 | 20 | { |
| 21 | - protected array $nodes = []; |
|
| 22 | - public function setNodes(array $nodes) : void |
|
| 23 | - { |
|
| 24 | - foreach ($nodes as $node) { |
|
| 25 | - if (!$node instanceof Node) { |
|
| 26 | - throw new InvalidArrayException(\sprintf("The nodes array must contain only %s objects", Node::class)); |
|
| 27 | - } |
|
| 28 | - } |
|
| 29 | - $this->nodes = $nodes; |
|
| 30 | - } |
|
| 31 | - public function getNodes() : array |
|
| 32 | - { |
|
| 33 | - return $this->nodes; |
|
| 34 | - } |
|
| 21 | + protected array $nodes = []; |
|
| 22 | + public function setNodes(array $nodes) : void |
|
| 23 | + { |
|
| 24 | + foreach ($nodes as $node) { |
|
| 25 | + if (!$node instanceof Node) { |
|
| 26 | + throw new InvalidArrayException(\sprintf("The nodes array must contain only %s objects", Node::class)); |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | + $this->nodes = $nodes; |
|
| 30 | + } |
|
| 31 | + public function getNodes() : array |
|
| 32 | + { |
|
| 33 | + return $this->nodes; |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -16,8 +16,7 @@ |
||
| 16 | 16 | |
| 17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Node; |
| 18 | 18 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\Exception\InvalidArrayException; |
| 19 | -trait SelectorTrait |
|
| 20 | -{ |
|
| 19 | +trait SelectorTrait { |
|
| 21 | 20 | protected array $nodes = []; |
| 22 | 21 | public function setNodes(array $nodes) : void |
| 23 | 22 | { |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Selector; |
| 16 | 16 | |
| 17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Node; |
@@ -22,49 +22,49 @@ |
||
| 22 | 22 | use function sprintf; |
| 23 | 23 | class SimpleNodePool implements NodePoolInterface |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - protected $nodes = []; |
|
| 29 | - /** |
|
| 30 | - * @var SelectorInterface |
|
| 31 | - */ |
|
| 32 | - protected $selector; |
|
| 33 | - /** |
|
| 34 | - * @var ResurrectInterface |
|
| 35 | - */ |
|
| 36 | - protected $resurrect; |
|
| 37 | - public function __construct(SelectorInterface $selector, ResurrectInterface $resurrect) |
|
| 38 | - { |
|
| 39 | - $this->selector = $selector; |
|
| 40 | - $this->resurrect = $resurrect; |
|
| 41 | - } |
|
| 42 | - public function setHosts(array $hosts) : self |
|
| 43 | - { |
|
| 44 | - $this->nodes = []; |
|
| 45 | - foreach ($hosts as $host) { |
|
| 46 | - $this->nodes[] = new Node($host); |
|
| 47 | - } |
|
| 48 | - shuffle($this->nodes); |
|
| 49 | - // randomize for use different hosts on each execution |
|
| 50 | - $this->selector->setNodes($this->nodes); |
|
| 51 | - return $this; |
|
| 52 | - } |
|
| 53 | - public function nextNode() : Node |
|
| 54 | - { |
|
| 55 | - $totNodes = count($this->nodes); |
|
| 56 | - $dead = 0; |
|
| 57 | - while ($dead < $totNodes) { |
|
| 58 | - $next = $this->selector->nextNode(); |
|
| 59 | - if ($next->isAlive()) { |
|
| 60 | - return $next; |
|
| 61 | - } |
|
| 62 | - if ($this->resurrect->ping($next)) { |
|
| 63 | - $next->markAlive(\true); |
|
| 64 | - return $next; |
|
| 65 | - } |
|
| 66 | - $dead++; |
|
| 67 | - } |
|
| 68 | - throw new NoNodeAvailableException(sprintf('No alive nodes. All the %d nodes seem to be down.', $totNodes)); |
|
| 69 | - } |
|
| 25 | + /** |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + protected $nodes = []; |
|
| 29 | + /** |
|
| 30 | + * @var SelectorInterface |
|
| 31 | + */ |
|
| 32 | + protected $selector; |
|
| 33 | + /** |
|
| 34 | + * @var ResurrectInterface |
|
| 35 | + */ |
|
| 36 | + protected $resurrect; |
|
| 37 | + public function __construct(SelectorInterface $selector, ResurrectInterface $resurrect) |
|
| 38 | + { |
|
| 39 | + $this->selector = $selector; |
|
| 40 | + $this->resurrect = $resurrect; |
|
| 41 | + } |
|
| 42 | + public function setHosts(array $hosts) : self |
|
| 43 | + { |
|
| 44 | + $this->nodes = []; |
|
| 45 | + foreach ($hosts as $host) { |
|
| 46 | + $this->nodes[] = new Node($host); |
|
| 47 | + } |
|
| 48 | + shuffle($this->nodes); |
|
| 49 | + // randomize for use different hosts on each execution |
|
| 50 | + $this->selector->setNodes($this->nodes); |
|
| 51 | + return $this; |
|
| 52 | + } |
|
| 53 | + public function nextNode() : Node |
|
| 54 | + { |
|
| 55 | + $totNodes = count($this->nodes); |
|
| 56 | + $dead = 0; |
|
| 57 | + while ($dead < $totNodes) { |
|
| 58 | + $next = $this->selector->nextNode(); |
|
| 59 | + if ($next->isAlive()) { |
|
| 60 | + return $next; |
|
| 61 | + } |
|
| 62 | + if ($this->resurrect->ping($next)) { |
|
| 63 | + $next->markAlive(\true); |
|
| 64 | + return $next; |
|
| 65 | + } |
|
| 66 | + $dead++; |
|
| 67 | + } |
|
| 68 | + throw new NoNodeAvailableException(sprintf('No alive nodes. All the %d nodes seem to be down.', $totNodes)); |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * Elasticsearch B.V licenses this file to you under the MIT License. |
| 12 | 12 | * See the LICENSE file in the project root for more information. |
| 13 | 13 | */ |
| 14 | -declare (strict_types=1); |
|
| 14 | +declare(strict_types=1); |
|
| 15 | 15 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool; |
| 16 | 16 | |
| 17 | 17 | use OCA\FullTextSearch_Elasticsearch\Vendor\Elastic\Transport\NodePool\Resurrect\ResurrectInterface; |
@@ -20,8 +20,7 @@ |
||
| 20 | 20 | use function count; |
| 21 | 21 | use function shuffle; |
| 22 | 22 | use function sprintf; |
| 23 | -class SimpleNodePool implements NodePoolInterface |
|
| 24 | -{ |
|
| 23 | +class SimpleNodePool implements NodePoolInterface { |
|
| 25 | 24 | /** |
| 26 | 25 | * @var array |
| 27 | 26 | */ |