22
22
import java .util .concurrent .ExecutorService ;
23
23
import java .util .concurrent .Executors ;
24
24
import java .util .function .Supplier ;
25
+ import org .apache .hc .client5 .http .impl .io .PoolingHttpClientConnectionManager ;
25
26
import org .apache .hc .client5 .http .io .HttpClientConnectionManager ;
26
- import org .apache .hc .core5 .io . CloseMode ;
27
+ import org .apache .hc .core5 .util . TimeValue ;
27
28
import org .slf4j .Logger ;
28
29
import org .slf4j .LoggerFactory ;
29
30
import software .amazon .awssdk .annotations .SdkInternalApi ;
@@ -38,7 +39,7 @@ public final class IdleConnectionReaper {
38
39
39
40
private static final IdleConnectionReaper INSTANCE = new IdleConnectionReaper ();
40
41
41
- private final Map <HttpClientConnectionManager , Long > connectionManagers ;
42
+ private final Map <PoolingHttpClientConnectionManager , Long > connectionManagers ;
42
43
43
44
private final Supplier <ExecutorService > executorServiceSupplier ;
44
45
@@ -64,7 +65,7 @@ private IdleConnectionReaper() {
64
65
}
65
66
66
67
@ SdkTestInternalApi
67
- IdleConnectionReaper (Map <HttpClientConnectionManager , Long > connectionManagers ,
68
+ IdleConnectionReaper (Map <PoolingHttpClientConnectionManager , Long > connectionManagers ,
68
69
Supplier <ExecutorService > executorServiceSupplier ,
69
70
long sleepPeriod ) {
70
71
@@ -81,7 +82,7 @@ private IdleConnectionReaper() {
81
82
* @return {@code true} If the connection manager was not previously registered with this reaper, {@code false}
82
83
* otherwise.
83
84
*/
84
- public synchronized boolean registerConnectionManager (HttpClientConnectionManager manager , long maxIdleTime ) {
85
+ public synchronized boolean registerConnectionManager (PoolingHttpClientConnectionManager manager , long maxIdleTime ) {
85
86
boolean notPreviouslyRegistered = connectionManagers .put (manager , maxIdleTime ) == null ;
86
87
setupExecutorIfNecessary ();
87
88
return notPreviouslyRegistered ;
@@ -133,12 +134,12 @@ private void cleanupExecutorIfNecessary() {
133
134
}
134
135
135
136
private static final class ReaperTask implements Runnable {
136
- private final Map <HttpClientConnectionManager , Long > connectionManagers ;
137
+ private final Map <PoolingHttpClientConnectionManager , Long > connectionManagers ;
137
138
private final long sleepPeriod ;
138
139
139
140
private volatile boolean stopping = false ;
140
141
141
- private ReaperTask (Map <HttpClientConnectionManager , Long > connectionManagers ,
142
+ private ReaperTask (Map <PoolingHttpClientConnectionManager , Long > connectionManagers ,
142
143
long sleepPeriod ) {
143
144
this .connectionManagers = connectionManagers ;
144
145
this .sleepPeriod = sleepPeriod ;
@@ -150,11 +151,9 @@ public void run() {
150
151
try {
151
152
Thread .sleep (sleepPeriod );
152
153
153
- for (Map .Entry <HttpClientConnectionManager , Long > entry : connectionManagers .entrySet ()) {
154
+ for (Map .Entry <PoolingHttpClientConnectionManager , Long > entry : connectionManagers .entrySet ()) {
154
155
try {
155
- entry .getKey ().close (CloseMode .GRACEFUL );
156
- // Set idle connections
157
- // entry.getKey().closeIdleConnections(entry.getValue(), TimeUnit.MILLISECONDS);
156
+ entry .getKey ().closeIdle (TimeValue .ofMilliseconds (entry .getValue ()));
158
157
} catch (Exception t ) {
159
158
log .warn ("Unable to close idle connections" , t );
160
159
}
0 commit comments