|
18 | 18 | import javax.ws.rs.client.WebTarget; |
19 | 19 |
|
20 | 20 | import com.github.dockerjava.api.command.UpdateContainerCmd; |
21 | | - |
22 | 21 | import com.github.dockerjava.core.SSLConfig; |
| 22 | + |
23 | 23 | import org.apache.http.config.RegistryBuilder; |
24 | 24 | import org.apache.http.conn.socket.ConnectionSocketFactory; |
25 | 25 | import org.apache.http.conn.socket.PlainConnectionSocketFactory; |
@@ -115,6 +115,8 @@ public class DockerCmdExecFactoryImpl implements DockerCmdExecFactory { |
115 | 115 |
|
116 | 116 | private DockerClientConfig dockerClientConfig; |
117 | 117 |
|
| 118 | + private PoolingHttpClientConnectionManager connManager = null; |
| 119 | + |
118 | 120 | @Override |
119 | 121 | public void init(DockerClientConfig dockerClientConfig) { |
120 | 122 | checkNotNull(dockerClientConfig, "config was not specified"); |
@@ -187,16 +189,29 @@ public void init(DockerClientConfig dockerClientConfig) { |
187 | 189 | configureProxy(clientConfig, protocol); |
188 | 190 | } |
189 | 191 |
|
190 | | - PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(getSchemeRegistry( |
191 | | - originalUri, sslContext)); |
192 | | - |
193 | 192 | if (maxTotalConnections != null) { |
194 | 193 | connManager.setMaxTotal(maxTotalConnections); |
195 | 194 | } |
196 | 195 | if (maxPerRouteConnections != null) { |
197 | 196 | connManager.setDefaultMaxPerRoute(maxPerRouteConnections); |
198 | 197 | } |
199 | 198 |
|
| 199 | + connManager = new PoolingHttpClientConnectionManager(getSchemeRegistry( |
| 200 | + originalUri, sslContext)) { |
| 201 | + |
| 202 | + @Override |
| 203 | + public void close() { |
| 204 | + super.shutdown(); |
| 205 | + } |
| 206 | + |
| 207 | + @Override |
| 208 | + public void shutdown() { |
| 209 | + // Disable shutdown of the pool. This will be done later, when this factory is closed |
| 210 | + // This is a workaround for finalize method on jerseys ClientRuntime which |
| 211 | + // closes the client and shuts down the connection pool when it is garbage collected |
| 212 | + } |
| 213 | + }; |
| 214 | + |
200 | 215 | clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, connManager); |
201 | 216 |
|
202 | 217 | // Configure connection pool timeout |
@@ -412,7 +427,6 @@ public KillContainerCmd.Exec createKillContainerCmdExec() { |
412 | 427 | return new KillContainerCmdExec(getBaseResource(), getDockerClientConfig()); |
413 | 428 | } |
414 | 429 |
|
415 | | - |
416 | 430 | @Override |
417 | 431 | public UpdateContainerCmd.Exec createUpdateContainerCmdExec() { |
418 | 432 | return new UpdateContainerCmdExec(getBaseResource(), getDockerClientConfig()); |
@@ -527,6 +541,7 @@ public DisconnectFromNetworkCmd.Exec createDisconnectFromNetworkCmdExec() { |
527 | 541 | public void close() throws IOException { |
528 | 542 | checkNotNull(client, "Factory not initialized. You probably forgot to call init()!"); |
529 | 543 | client.close(); |
| 544 | + connManager.close(); |
530 | 545 | } |
531 | 546 |
|
532 | 547 | public DockerCmdExecFactoryImpl withReadTimeout(Integer readTimeout) { |
|
0 commit comments