LoadBalancerInterface.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\LoadBalancer;
  12. use Closure;
  13. use Hyperf\LoadBalancer\Exception\NoNodesAvailableException;
  14. interface LoadBalancerInterface
  15. {
  16. /**
  17. * Select an item via the load balancer.
  18. * @throws NoNodesAvailableException
  19. */
  20. public function select(array ...$parameters): Node;
  21. /**
  22. * @param Node[] $nodes
  23. */
  24. public function setNodes(array $nodes): static;
  25. /**
  26. * @return Node[] $nodes
  27. */
  28. public function getNodes(): array;
  29. /**
  30. * Remove a node from the node list.
  31. */
  32. public function removeNode(Node $node): bool;
  33. public function refresh(callable $callback, int $tickMs = 5000): void;
  34. public function isAutoRefresh(): bool;
  35. /**
  36. * Register a hook which will be executed after refresh nodes.
  37. */
  38. public function afterRefreshed(string $key, ?Closure $callback): void;
  39. /**
  40. * Clear all hooks which will be executed after refresh nodes.
  41. */
  42. public function clearAfterRefreshedCallbacks(): void;
  43. }