Skip to content

Commit c4739db

Browse files
author
lucaijun
committed
AJ-542: add symbol connection pool
1 parent b193e00 commit c4739db

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

src/com/xxdb/SimpleDBConnectionPool.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.xxdb;
22

3+
import com.xxdb.data.BasicInt;
34
import org.slf4j.Logger;
45
import org.slf4j.LoggerFactory;
56

@@ -96,9 +97,10 @@ protected class SimpleDBConnectionPoolImpl {
9697
try {
9798
for (int i = 0; i < initialPoolSize; i++) {
9899
PoolEntry poolEntry = new PoolEntry(useSSL, compress, usePython, String.format("DolphinDBConnection_%d", i + 1));
99-
if (!poolEntry.connect(hostName, port, userId, password, initialScript, enableHighAvailability, highAvailabilitySites, reconnect, loadBalance)){
100+
if (!poolEntry.connect(hostName, port, userId, password, initialScript, enableHighAvailability, highAvailabilitySites, reconnect, loadBalance)) {
100101
log.error(String.format("Connection %s connect failure.", poolEntry.connectionName));
101-
};
102+
}
103+
;
102104
poolEntryArrayList.add(poolEntry);
103105
}
104106
poolEntries = new CopyOnWriteArrayList<>(poolEntryArrayList);
@@ -165,8 +167,17 @@ public boolean isIdle() {
165167
public void close() {
166168
if (isBusy())
167169
log.error("Cannot release the connection,is running now.");
168-
else
169-
inUse.compareAndSet(true, false);
170+
else {
171+
try {
172+
BasicInt ret = (BasicInt) run("1+1", true);
173+
if (!ret.isNull() && (ret.getInt() == 2))
174+
inUse.compareAndSet(true, false);
175+
else
176+
log.error("Cannot release memory,release connection failure.");
177+
} catch (Exception e) {
178+
log.error("Cannot release memory, because " + e.getMessage());
179+
}
180+
}
170181
}
171182

172183
private void release() {

src/com/xxdb/SimpleDBConnectionPoolConfig.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,11 @@ public class SimpleDBConnectionPoolConfig {
1010
private boolean compress = false;
1111
private boolean useSSL = false;
1212
private boolean usePython = false;
13-
private boolean loadBalance;
13+
private boolean loadBalance = false;
1414
private boolean enableHighAvailability = false;
1515
private String[] highAvailabilitySites = null;
1616

17-
public SimpleDBConnectionPoolConfig(String hostName, int port, String userId, String password, int initialPoolSize, String initialScript, boolean compress, boolean useSSL, boolean usePython, boolean loadBalance, boolean enableHighAvailability, String[] highAvailabilitySites) {
18-
this.hostName = hostName;
19-
this.port = port;
20-
this.userId = userId;
21-
this.password = password;
22-
this.initialPoolSize = initialPoolSize;
23-
this.initialScript = initialScript;
24-
this.compress = compress;
25-
this.useSSL = useSSL;
26-
this.usePython = usePython;
27-
this.loadBalance = loadBalance;
28-
this.enableHighAvailability = enableHighAvailability;
29-
this.highAvailabilitySites = highAvailabilitySites;
30-
}
31-
32-
public SimpleDBConnectionPoolConfig(String hostName, int port, String userId, String password, int initialPoolSize, boolean loadBalance) {
33-
this.hostName = hostName;
34-
this.port = port;
35-
this.userId = userId;
36-
this.password = password;
37-
this.initialPoolSize = initialPoolSize;
38-
this.loadBalance = loadBalance;
17+
public SimpleDBConnectionPoolConfig() {
3918
}
4019

4120
public String getHostName() {

0 commit comments

Comments
 (0)