Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.lock
*.bak
/phpunit.xml
/.phpunit.result.cache
.idea
18 changes: 18 additions & 0 deletions src/Exception/NoNodesAvailableException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);
/**
* This file is part of jet.
*
* @link https://github.com/friendsofhyperf/jet
* @document https://github.com/friendsofhyperf/jet/blob/main/README.md
* @contact huangdijia@gmail.com
* @license https://github.com/friendsofhyperf/jet/blob/main/LICENSE
*/
namespace FriendsOfHyperf\Jet\Exception;

use RuntimeException;

class NoNodesAvailableException extends RuntimeException
{
}
4 changes: 3 additions & 1 deletion src/LoadBalancer/Random.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/
namespace FriendsOfHyperf\Jet\LoadBalancer;

use FriendsOfHyperf\Jet\Exception\NoNodesAvailableException;

class Random extends AbstractLoadBalancer
{
/**
Expand All @@ -19,7 +21,7 @@ class Random extends AbstractLoadBalancer
public function select(): Node
{
if (empty($this->nodes)) {
throw new \RuntimeException('Cannot select any node from load balancer.');
throw new NoNodesAvailableException('Cannot select any node from load balancer.');
}

$key = array_rand($this->nodes);
Expand Down
4 changes: 2 additions & 2 deletions src/LoadBalancer/RoundRobin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
namespace FriendsOfHyperf\Jet\LoadBalancer;

use RuntimeException;
use FriendsOfHyperf\Jet\Exception\NoNodesAvailableException;

class RoundRobin extends AbstractLoadBalancer
{
Expand All @@ -28,7 +28,7 @@ public function select(): Node
$count = count($this->nodes);

if ($count <= 0) {
throw new RuntimeException('Nodes missing.');
throw new NoNodesAvailableException('Nodes missing.');
}

$item = $this->nodes[self::$current % $count];
Expand Down
2 changes: 1 addition & 1 deletion src/Transporter/StreamSocketTransporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class StreamSocketTransporter extends AbstractTransporter
protected $client;

/**
* @var float
* @var int
*/
protected $timeout;

Expand Down