diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:15:42 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:44:51 +0100 |
commit | a1789ddde42033f1b05cc4929491214ee6e79383 (patch) | |
tree | 63615735c4ddffaaabf2428946bb26f90899f7bf /vendor/ruflin/elastica/lib/Elastica/Connection/ConnectionPool.php | |
parent | 9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff) |
Update to MediaWiki 1.26.0
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Connection/ConnectionPool.php')
-rw-r--r-- | vendor/ruflin/elastica/lib/Elastica/Connection/ConnectionPool.php | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Connection/ConnectionPool.php b/vendor/ruflin/elastica/lib/Elastica/Connection/ConnectionPool.php new file mode 100644 index 00000000..b5fa681d --- /dev/null +++ b/vendor/ruflin/elastica/lib/Elastica/Connection/ConnectionPool.php @@ -0,0 +1,122 @@ +<?php +namespace Elastica\Connection; + +use Elastica\Client; +use Elastica\Connection; +use Elastica\Connection\Strategy\StrategyInterface; +use Exception; + +/** + * Description of ConnectionPool. + * + * @author chabior + */ +class ConnectionPool +{ + /** + * @var array|\Elastica\Connection[] Connections array + */ + protected $_connections; + + /** + * @var \Elastica\Connection\Strategy\StrategyInterface Strategy for connection + */ + protected $_strategy; + + /** + * @var callback Function called on connection fail + */ + protected $_callback; + + /** + * @param array $connections + * @param \Elastica\Connection\Strategy\StrategyInterface $strategy + * @param callback $callback + */ + public function __construct(array $connections, StrategyInterface $strategy, $callback = null) + { + $this->_connections = $connections; + + $this->_strategy = $strategy; + + $this->_callback = $callback; + } + + /** + * @param \Elastica\Connection $connection + * + * @return $this + */ + public function addConnection(Connection $connection) + { + $this->_connections[] = $connection; + + return $this; + } + + /** + * @param array|\Elastica\Connection[] $connections + * + * @return $this + */ + public function setConnections(array $connections) + { + $this->_connections = $connections; + + return $this; + } + + /** + * @return bool + */ + public function hasConnection() + { + foreach ($this->_connections as $connection) { + if ($connection->isEnabled()) { + return true; + } + } + + return false; + } + + /** + * @return array + */ + public function getConnections() + { + return $this->_connections; + } + + /** + * @throws \Elastica\Exception\ClientException + * + * @return \Elastica\Connection + */ + public function getConnection() + { + return $this->_strategy->getConnection($this->getConnections()); + } + + /** + * @param \Elastica\Connection $connection + * @param \Exception $e + * @param Client $client + */ + public function onFail(Connection $connection, Exception $e, Client $client) + { + $connection->setEnabled(false); + + if ($this->_callback) { + call_user_func($this->_callback, $connection, $e, $client); + } + } + + /** + * @return \Elastica\Connection\Strategy\StrategyInterface + */ + public function getStrategy() + { + return $this->_strategy; + } +} |