|
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,8 +189,21 @@ public void init(DockerClientConfig dockerClientConfig) { |
187 | 189 | configureProxy(clientConfig, protocol); |
188 | 190 | } |
189 | 191 |
|
190 | | - PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(getSchemeRegistry( |
191 | | - originalUri, sslContext)); |
| 192 | + connManager = new PoolingHttpClientConnectionManager(getSchemeRegistry( |
| 193 | + originalUri, sslContext)) { |
| 194 | + |
| 195 | + @Override |
| 196 | + public void close() { |
| 197 | + super.shutdown(); |
| 198 | + } |
| 199 | + |
| 200 | + @Override |
| 201 | + public void shutdown() { |
| 202 | + // Disable shutdown of the pool. This will be done later, when this factory is closed |
| 203 | + // This is a workaround for finalize method on jerseys ClientRuntime which |
| 204 | + // closes the client and shuts down the connection pool when it is garbage collected |
| 205 | + } |
| 206 | + }; |
192 | 207 |
|
193 | 208 | if (maxTotalConnections != null) { |
194 | 209 | connManager.setMaxTotal(maxTotalConnections); |
@@ -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