Skip to content

Commit f6a89a3

Browse files
Set difference to find closed connections
1 parent 5d8ba14 commit f6a89a3

File tree

3 files changed

+14
-35
lines changed

3 files changed

+14
-35
lines changed

java/src/main/java/com/genexus/internet/CustomPoolingHttpClientConnectionManager.java

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class CustomPoolingHttpClientConnectionManager extends PoolingHttpClientConnectionManager {
1919
private final List<IConnectionObserver> observers = new ArrayList<>();
2020

21-
public CustomPoolingHttpClientConnectionManager(Registry<ConnectionSocketFactory> socketFactoryRegistry){
21+
public CustomPoolingHttpClientConnectionManager(Registry<ConnectionSocketFactory> socketFactoryRegistry) {
2222
super(socketFactoryRegistry);
2323
}
2424

@@ -50,39 +50,24 @@ public HttpClientConnection get(long timeout, TimeUnit tunit) throws Interrupted
5050

5151
@Override
5252
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());
6154
super.closeExpiredConnections();
62-
super.enumAvailable(entry -> afterClosing.add(entry.getRoute()));
63-
beforeClosing.removeAll(afterClosing);
55+
Set<HttpRoute> afterClosing = this.getRoutes();
6456

6557
for (HttpRoute route : beforeClosing)
66-
notifyConnectionDestroyed(route);
58+
if (!afterClosing.contains(route))
59+
notifyConnectionDestroyed(route);
6760
}
6861

6962
@Override
7063
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());
8065
super.closeIdleConnections(idletime, tunit);
81-
super.enumAvailable(entry -> afterClosing.add(entry.getRoute()));
82-
beforeClosing.removeAll(afterClosing);
66+
Set<HttpRoute> afterClosing = this.getRoutes();
8367

8468
for (HttpRoute route : beforeClosing)
85-
notifyConnectionDestroyed(route);
69+
if (!afterClosing.contains(route))
70+
notifyConnectionDestroyed(route);
8671
}
8772

8873
private void notifyConnectionCreated(HttpRoute route) {
@@ -94,12 +79,6 @@ private void notifyConnectionDestroyed(HttpRoute route) {
9479
for (IConnectionObserver observer : observers)
9580
observer.onConnectionDestroyed(route);
9681
}
97-
98-
@Override
99-
protected void finalize() throws Throwable {
100-
super.finalize();
101-
scheduler.shutdown();
102-
}
10382
}
10483

10584

java/src/main/java/com/genexus/management/HTTPConnectionJMX.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static public void CreateHTTPConnectionJMX(HttpRoute connection) {
1717
try {
1818
MBeanUtils.createMBean(connection);
1919
}
20-
catch(Exception e) {
20+
catch (Exception e) {
2121
log.error("Failed to register HTTP connection MBean.", e);
2222
}
2323
}
@@ -26,7 +26,7 @@ static public void DestroyHTTPConnectionJMX(HttpRoute connection) {
2626
try {
2727
MBeanUtils.destroyMBean(connection);
2828
}
29-
catch(Exception e) {
29+
catch (Exception e) {
3030
log.error("Failed to destroy HTTP connection MBean.", e);
3131
}
3232
}

java/src/main/java/com/genexus/management/MBeanUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ public static void createMBean(PoolingHttpClientConnectionManager connectionPool
138138
if (mbs == null)
139139
return;
140140
HTTPPoolJMX mbean = new HTTPPoolJMX(connectionPool);
141-
registerBean(mbean, "com.genexus.management:type=GeneXusApplicationServer.HTTPPool,ApplicationName=Http connection pool");
141+
registerBean(mbean, "com.genexus.management:type=GeneXusApplicationServer.HTTPPool,ApplicationName=Http connection pool, Http connection pool id =" + connectionPool.hashCode());
142142
}
143143

144144
public static void createMBean(HttpRoute httpRoute) {
145145
MBeanServer mbs = getMBeanServer();
146146
if (mbs == null)
147147
return;
148148
HTTPConnectionJMX mbean = new HTTPConnectionJMX(httpRoute);
149-
registerBean(mbean, "com.genexus.management:type=GeneXusApplicationServer.HTTPPool.HTTPConnection,ApplicationName=" + httpRoute.getTargetHost().getHostName() + ",Port=" + httpRoute.getTargetHost().getPort() + ",name=Http connection");
149+
registerBean(mbean, "com.genexus.management:type=GeneXusApplicationServer.HTTPPool.HTTPConnection,ApplicationName=" + httpRoute.getTargetHost().getHostName() + ",Port=" + httpRoute.getTargetHost().getPort() + ",Http connection id=" + httpRoute.hashCode());
150150
}
151151

152152
public static void createMBean(GXConnection connection)
@@ -266,7 +266,7 @@ public static void destroyMBean(HttpRoute httpRoute) {
266266
return;
267267

268268
try {
269-
ObjectName name = new ObjectName("com.genexus.management:type=GeneXusApplicationServer.HTTPPool.HTTPConnection,ApplicationName=" + httpRoute.getTargetHost().getHostName() + ",Port=" + httpRoute.getTargetHost().getPort() + ",name=Http connection");
269+
ObjectName name = new ObjectName("com.genexus.management:type=GeneXusApplicationServer.HTTPPool.HTTPConnection,ApplicationName=" + httpRoute.getTargetHost().getHostName() + ",Port=" + httpRoute.getTargetHost().getPort() + ",Http connection id=" + httpRoute.hashCode());
270270
registeredObjects.removeElement(name);
271271

272272
mbs.unregisterMBean(name);

0 commit comments

Comments
 (0)