| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | namespace OpenSearch\ConnectionPool; |
| 23: | |
| 24: | use OpenSearch\Common\Exceptions\InvalidArgumentException; |
| 25: | use OpenSearch\ConnectionPool\Selectors\SelectorInterface; |
| 26: | use OpenSearch\Connections\ConnectionFactoryInterface; |
| 27: | use OpenSearch\Connections\ConnectionInterface; |
| 28: | |
| 29: | |
| 30: | @trigger_error(AbstractConnectionPool::class . ' is deprecated in 2.4.0 and will be removed in 3.0.0.', E_USER_DEPRECATED); |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | abstract class AbstractConnectionPool implements ConnectionPoolInterface |
| 36: | { |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | protected $connections; |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | protected $seedConnections; |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | protected $selector; |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | protected $connectionPoolParams; |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: | protected $connectionFactory; |
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: | |
| 73: | |
| 74: | |
| 75: | |
| 76: | public function __construct(array $connections, SelectorInterface $selector, ConnectionFactoryInterface $factory, array $connectionPoolParams) |
| 77: | { |
| 78: | $paramList = array('connections', 'selector', 'connectionPoolParams'); |
| 79: | foreach ($paramList as $param) { |
| 80: | if (isset($$param) === false) { |
| 81: | throw new InvalidArgumentException('`' . $param . '` parameter must not be null'); |
| 82: | } |
| 83: | } |
| 84: | |
| 85: | if (isset($connectionPoolParams['randomizeHosts']) === true |
| 86: | && $connectionPoolParams['randomizeHosts'] === true |
| 87: | ) { |
| 88: | shuffle($connections); |
| 89: | } |
| 90: | |
| 91: | $this->connections = $connections; |
| 92: | $this->seedConnections = $connections; |
| 93: | $this->selector = $selector; |
| 94: | $this->connectionPoolParams = $connectionPoolParams; |
| 95: | $this->connectionFactory = $factory; |
| 96: | } |
| 97: | |
| 98: | abstract public function nextConnection(bool $force = false): ConnectionInterface; |
| 99: | |
| 100: | abstract public function scheduleCheck(): void; |
| 101: | } |
| 102: | |