Skip to content

Commit 05eead9

Browse files
committed
refactor:simplified the returning of connection from push client
1 parent 0bc55b2 commit 05eead9

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

client/src/main/java/com/orientechnologies/orient/client/remote/ORemoteConnectionManager.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,36 @@ public void remove(final OChannelBinaryAsynchClient conn) {
155155

156156
pool.getPool().remove(conn);
157157

158+
try {
159+
conn.close();
160+
} catch (Exception e) {
161+
OLogManager.instance().debug(this, "Cannot close connection", e);
162+
}
163+
158164
try {
159165
conn.unlock();
160166
} catch (Exception e) {
161167
OLogManager.instance().debug(this, "Cannot unlock connection lock", e);
162168
}
169+
}
170+
171+
public void removeIfPresent(final OChannelBinaryAsynchClient conn) {
172+
if (conn == null) return;
173+
174+
final ORemoteConnectionPool pool = connections.get(conn.getServerURL());
175+
if (pool == null) return;
176+
pool.getPool().remove(conn);
163177

164178
try {
165179
conn.close();
166180
} catch (Exception e) {
167181
OLogManager.instance().debug(this, "Cannot close connection", e);
168182
}
183+
try {
184+
conn.unlock();
185+
} catch (Exception e) {
186+
OLogManager.instance().debug(this, "Cannot unlock connection lock", e);
187+
}
169188
}
170189

171190
public Set<String> getURLs() {

client/src/main/java/com/orientechnologies/orient/client/remote/ORemoteConnectionPool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
public class ORemoteConnectionPool
1414
implements OResourcePoolListener<String, OChannelBinaryAsynchClient> {
1515

16-
private OResourcePool<String, OChannelBinaryAsynchClient> pool;
16+
private final OResourcePool<String, OChannelBinaryAsynchClient> pool;
1717

1818
public ORemoteConnectionPool(int iMaxResources) {
1919
pool = new OResourcePool<>(iMaxResources, this);

client/src/main/java/com/orientechnologies/orient/client/remote/OStorageRemote.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,10 +2349,7 @@ public void onPushReconnect(String host) {
23492349
}
23502350

23512351
public void onPushDisconnect(OChannelBinary network, Exception e) {
2352-
if (this.connectionManager.getPool(((OChannelBinaryAsynchClient) network).getServerURL())
2353-
!= null) {
2354-
this.connectionManager.remove((OChannelBinaryAsynchClient) network);
2355-
}
2352+
this.connectionManager.removeIfPresent((OChannelBinaryAsynchClient) network);
23562353
if (e instanceof InterruptedException) {
23572354
for (OLiveQueryClientListener liveListener : liveQueryListener.values()) {
23582355
liveListener.onEnd();

0 commit comments

Comments
 (0)