18
18
public class CustomPoolingHttpClientConnectionManager extends PoolingHttpClientConnectionManager {
19
19
private final List <IConnectionObserver > observers = new ArrayList <>();
20
20
21
- public CustomPoolingHttpClientConnectionManager (Registry <ConnectionSocketFactory > socketFactoryRegistry ){
21
+ public CustomPoolingHttpClientConnectionManager (Registry <ConnectionSocketFactory > socketFactoryRegistry ) {
22
22
super (socketFactoryRegistry );
23
23
}
24
24
@@ -50,39 +50,24 @@ public HttpClientConnection get(long timeout, TimeUnit tunit) throws Interrupted
50
50
51
51
@ Override
52
52
public void closeExpiredConnections () {
53
- Set <HttpRoute > beforeClosing = new HashSet <>();
54
- Set <HttpRoute > afterClosing = new HashSet <>();
55
-
56
- super .enumAvailable (entry -> {
57
- if (entry .isExpired (System .currentTimeMillis ())) {
58
- beforeClosing .add (entry .getRoute ());
59
- }
60
- });
53
+ Set <HttpRoute > beforeClosing = new HashSet <>(this .getRoutes ());
61
54
super .closeExpiredConnections ();
62
- super .enumAvailable (entry -> afterClosing .add (entry .getRoute ()));
63
- beforeClosing .removeAll (afterClosing );
55
+ Set <HttpRoute > afterClosing = this .getRoutes ();
64
56
65
57
for (HttpRoute route : beforeClosing )
66
- notifyConnectionDestroyed (route );
58
+ if (!afterClosing .contains (route ))
59
+ notifyConnectionDestroyed (route );
67
60
}
68
61
69
62
@ Override
70
63
public void closeIdleConnections (long idletime , TimeUnit tunit ) {
71
- Set <HttpRoute > beforeClosing = new HashSet <>();
72
- Set <HttpRoute > afterClosing = new HashSet <>();
73
- long idleTimeoutMillis = tunit .toMillis (idletime );
74
-
75
- super .enumAvailable (entry -> {
76
- if (entry .getUpdated () + idleTimeoutMillis < System .currentTimeMillis ()) {
77
- beforeClosing .add (entry .getRoute ());
78
- }
79
- });
64
+ Set <HttpRoute > beforeClosing = new HashSet <>(this .getRoutes ());
80
65
super .closeIdleConnections (idletime , tunit );
81
- super .enumAvailable (entry -> afterClosing .add (entry .getRoute ()));
82
- beforeClosing .removeAll (afterClosing );
66
+ Set <HttpRoute > afterClosing = this .getRoutes ();
83
67
84
68
for (HttpRoute route : beforeClosing )
85
- notifyConnectionDestroyed (route );
69
+ if (!afterClosing .contains (route ))
70
+ notifyConnectionDestroyed (route );
86
71
}
87
72
88
73
private void notifyConnectionCreated (HttpRoute route ) {
@@ -94,12 +79,6 @@ private void notifyConnectionDestroyed(HttpRoute route) {
94
79
for (IConnectionObserver observer : observers )
95
80
observer .onConnectionDestroyed (route );
96
81
}
97
-
98
- @ Override
99
- protected void finalize () throws Throwable {
100
- super .finalize ();
101
- scheduler .shutdown ();
102
- }
103
82
}
104
83
105
84
0 commit comments