1 | <?php |
||
18 | class HttpClientPoolItem implements HttpClient, HttpAsyncClient |
||
19 | { |
||
20 | /** @var int Number of request this client is currently sending */ |
||
21 | private $sendingRequestCount = 0; |
||
22 | |||
23 | /** @var \DateTime|null Time when this client has been disabled or null if enable */ |
||
24 | private $disabledAt; |
||
25 | |||
26 | /** @var int|null Number of seconds after this client is reenable, by default null: never reenable this client */ |
||
27 | private $reenableAfter; |
||
28 | |||
29 | /** @var FlexibleHttpClient A http client responding to async and sync request */ |
||
30 | private $client; |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | * |
||
35 | * @param null|int $reenableAfter Number of seconds after this client is reenable |
||
36 | */ |
||
37 | 23 | public function __construct($client, $reenableAfter = null) |
|
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | 13 | public function sendRequest(RequestInterface $request) |
|
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | 8 | public function sendAsyncRequest(RequestInterface $request) |
|
88 | |||
89 | /** |
||
90 | * Whether this client is disabled or not. |
||
91 | * |
||
92 | * Will also reactivate this client if possible |
||
93 | * |
||
94 | * @return bool |
||
95 | */ |
||
96 | 21 | public function isDisabled() |
|
115 | |||
116 | /** |
||
117 | * Get current number of request that is send by the underlying http client. |
||
118 | * |
||
119 | * @return int |
||
120 | */ |
||
121 | 2 | public function getSendingRequestCount() |
|
125 | |||
126 | /** |
||
127 | * Return when this client has been disabled or null if it's enabled. |
||
128 | * |
||
129 | * @return \DateTime|null |
||
130 | */ |
||
131 | 21 | private function getDisabledAt() |
|
135 | |||
136 | /** |
||
137 | * Increment the request count. |
||
138 | */ |
||
139 | 21 | private function incrementRequestCount() |
|
143 | |||
144 | /** |
||
145 | * Decrement the request count. |
||
146 | */ |
||
147 | 16 | private function decrementRequestCount() |
|
151 | |||
152 | /** |
||
153 | * Enable the current client. |
||
154 | */ |
||
155 | 5 | private function enable() |
|
159 | |||
160 | /** |
||
161 | * Disable the current client. |
||
162 | */ |
||
163 | 10 | private function disable() |
|
167 | } |
||
168 |