PoolOption.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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\Pool;
  12. use Hyperf\Contract\PoolOptionInterface;
  13. class PoolOption implements PoolOptionInterface
  14. {
  15. /**
  16. * Min connections of pool.
  17. * This means the pool will create $minConnections connections when
  18. * pool initialization.
  19. */
  20. private int $minConnections;
  21. /**
  22. * Max connections of pool.
  23. */
  24. private int $maxConnections;
  25. /**
  26. * The timeout of connect the connection.
  27. * Default value is 10 seconds.
  28. */
  29. private float $connectTimeout;
  30. /**
  31. * The timeout of pop a connection.
  32. * Default value is 3 seconds.
  33. */
  34. private float $waitTimeout;
  35. /**
  36. * Heartbeat of connection.
  37. * If the value is 10, then means 10 seconds.
  38. * If the value is -1, then means does not need the heartbeat.
  39. * Default value is -1.
  40. */
  41. private float $heartbeat;
  42. /**
  43. * The max idle time for connection.
  44. */
  45. private float $maxIdleTime;
  46. /**
  47. * The events which will be triggered by releasing connection and so on.
  48. * @var array<int, string>
  49. */
  50. private array $events;
  51. public function __construct(
  52. int $minConnections = 1,
  53. int $maxConnections = 10,
  54. float $connectTimeout = 10.0,
  55. float $waitTimeout = 3.0,
  56. float $heartbeat = -1,
  57. float $maxIdleTime = 60.0,
  58. array $events = [],
  59. ) {
  60. $this->minConnections = $minConnections;
  61. $this->maxConnections = $maxConnections;
  62. $this->connectTimeout = $connectTimeout;
  63. $this->waitTimeout = $waitTimeout;
  64. $this->heartbeat = $heartbeat;
  65. $this->maxIdleTime = $maxIdleTime;
  66. $this->events = $events;
  67. }
  68. public function getMaxConnections(): int
  69. {
  70. return $this->maxConnections;
  71. }
  72. public function setMaxConnections(int $maxConnections): static
  73. {
  74. $this->maxConnections = $maxConnections;
  75. return $this;
  76. }
  77. public function getMinConnections(): int
  78. {
  79. return $this->minConnections;
  80. }
  81. public function setMinConnections(int $minConnections): static
  82. {
  83. $this->minConnections = $minConnections;
  84. return $this;
  85. }
  86. public function getConnectTimeout(): float
  87. {
  88. return $this->connectTimeout;
  89. }
  90. public function setConnectTimeout(float $connectTimeout): static
  91. {
  92. $this->connectTimeout = $connectTimeout;
  93. return $this;
  94. }
  95. public function getHeartbeat(): float
  96. {
  97. return $this->heartbeat;
  98. }
  99. public function setHeartbeat(float $heartbeat): static
  100. {
  101. $this->heartbeat = $heartbeat;
  102. return $this;
  103. }
  104. public function getWaitTimeout(): float
  105. {
  106. return $this->waitTimeout;
  107. }
  108. public function setWaitTimeout(float $waitTimeout): static
  109. {
  110. $this->waitTimeout = $waitTimeout;
  111. return $this;
  112. }
  113. public function getMaxIdleTime(): float
  114. {
  115. return $this->maxIdleTime;
  116. }
  117. public function setMaxIdleTime(float $maxIdleTime): static
  118. {
  119. $this->maxIdleTime = $maxIdleTime;
  120. return $this;
  121. }
  122. public function getEvents(): array
  123. {
  124. return $this->events;
  125. }
  126. public function setEvents(array $events): static
  127. {
  128. $this->events = $events;
  129. return $this;
  130. }
  131. }