diff --git a/app/src/Infrastructure/Api/Database/ConnectionPoolInterface.php b/app/src/Infrastructure/Api/Database/ConnectionPoolInterface.php index 18754e7..4b614d8 100644 --- a/app/src/Infrastructure/Api/Database/ConnectionPoolInterface.php +++ b/app/src/Infrastructure/Api/Database/ConnectionPoolInterface.php @@ -2,11 +2,40 @@ namespace Slovocast\Infrastructure\Api\Database; +use Exception; + interface ConnectionPoolInterface { - public function getFreeConnectionsCount(): int; - public function getActiveConnectionsCount(): int; - public function hasFreeConnection(): bool; - public function getConnection(): ConnectionInterface; - public function releaseConnection(ConnectionInterface $connection): void; + public function getTotalIdleConnections(): int; + public function getTotalActiveConnections(): int; + + /** + * If there is at least one idle connection waiting to be used. + * + * @return bool + */ + public function hasIdleConnection(): bool; + public function setWaitTimeout(int $seconds): void; + public function getWaitTimeout(): int; + public function getConnectionLimit(): int; + + /** + * This method will grab a connection from the Idle list, push it into the Active list and returns that same + * connection to the caller. If there is no active connections, the method will wait based on the `waitTimeout` + * value (in seconds) and throw an exception when the timeout has been reached. + * + * @throws Exception When the Wait Timeout is surpassed waiting for an idle connection + * @return PooledConnectionInterface + */ + public function getConnection(): PooledConnectionInterface; + + /** + * This method will return a connection from the Active list into the Idle list. + * + * @param PooledConnectionInterface $connection + * @return void + */ + public function releaseConnection(PooledConnectionInterface $connection): void; + + } diff --git a/app/src/Infrastructure/Api/Database/ConnectionInterface.php b/app/src/Infrastructure/Api/Database/PooledConnectionInterface.php similarity index 100% rename from app/src/Infrastructure/Api/Database/ConnectionInterface.php rename to app/src/Infrastructure/Api/Database/PooledConnectionInterface.php diff --git a/app/src/Infrastructure/Database/ConnectionPool.php b/app/src/Infrastructure/Database/ConnectionPool.php new file mode 100644 index 0000000..534343f --- /dev/null +++ b/app/src/Infrastructure/Database/ConnectionPool.php @@ -0,0 +1,56 @@ +port; + } + + public function getPoolWaitTimeout(): int + { + return $this->poolWaitTimeout; + } +}