Remove setIdleTimeout()

Moved to constructor argument.
This commit is contained in:
Aaron Piotrowski 2018-07-10 18:33:00 -05:00
parent 9130acd08c
commit 1d33364698
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
2 changed files with 13 additions and 15 deletions

View File

@ -41,7 +41,7 @@ abstract class AbstractPool implements Pool
private $pending = 0; private $pending = 0;
/** @var int */ /** @var int */
private $idleTimeout = Pool::DEFAULT_IDLE_TIMEOUT; private $idleTimeout;
/** @var string */ /** @var string */
private $timeoutWatcher; private $timeoutWatcher;
@ -98,15 +98,27 @@ abstract class AbstractPool implements Pool
*/ */
abstract protected function createTransaction(Transaction $transaction, callable $release): Transaction; abstract protected function createTransaction(Transaction $transaction, callable $release): Transaction;
/**
* @param ConnectionConfig $config
* @param int $maxConnections Maximum number of active connections in the pool.
* @param int $idleTimeout Number of seconds until idle connections are removed from the pool.
* @param Connector|null $connector
*/
public function __construct( public function __construct(
ConnectionConfig $config, ConnectionConfig $config,
int $maxConnections = Pool::DEFAULT_MAX_CONNECTIONS, int $maxConnections = Pool::DEFAULT_MAX_CONNECTIONS,
int $idleTimeout = Pool::DEFAULT_IDLE_TIMEOUT,
Connector $connector = null Connector $connector = null
) { ) {
$this->connector = $connector ?? $this->createDefaultConnector(); $this->connector = $connector ?? $this->createDefaultConnector();
$this->connectionConfig = $config; $this->connectionConfig = $config;
$this->idleTimeout = $idleTimeout;
if ($this->idleTimeout < 1) {
throw new \Error("The idle timeout must be 1 or greater");
}
$this->maxConnections = $maxConnections; $this->maxConnections = $maxConnections;
if ($this->maxConnections < 1) { if ($this->maxConnections < 1) {
throw new \Error("Pool must contain at least one connection"); throw new \Error("Pool must contain at least one connection");
@ -148,15 +160,6 @@ abstract class AbstractPool implements Pool
return $this->idleTimeout; return $this->idleTimeout;
} }
public function setIdleTimeout(int $timeout)
{
if ($timeout < 1) {
throw new \Error("Timeout must be greater than or equal to 1");
}
$this->idleTimeout = $timeout;
}
public function lastUsedAt(): int public function lastUsedAt(): int
{ {
// Simple implementation... can be improved if needed. // Simple implementation... can be improved if needed.

View File

@ -33,9 +33,4 @@ interface Pool extends Link
* @return int Number of seconds a connection may remain idle before it is automatically closed. * @return int Number of seconds a connection may remain idle before it is automatically closed.
*/ */
public function getIdleTimeout(): int; public function getIdleTimeout(): int;
/**
* @param int $timeout Number of seconds a connection may remain idle before it is automatically closed.
*/
public function setIdleTimeout(int $timeout);
} }