3
3
import com .xxdb .data .BasicInt ;
4
4
import org .slf4j .Logger ;
5
5
import org .slf4j .LoggerFactory ;
6
-
7
6
import java .io .IOException ;
8
7
import java .util .ArrayList ;
9
8
import java .util .Objects ;
@@ -97,12 +96,8 @@ protected class SimpleDBConnectionPoolImpl {
97
96
try {
98
97
for (int i = 0 ; i < initialPoolSize ; i ++) {
99
98
PoolEntry poolEntry = new PoolEntry (useSSL , compress , usePython , String .format ("DolphinDBConnection_%d" , i + 1 ));
100
- if (poolEntry .connect (hostName , port , userId , password , initialScript , enableHighAvailability , highAvailabilitySites , reconnect , loadBalance )) {
101
- poolEntry .isFirstConnect = false ;
102
- poolEntry .isFirstLogin = false ;
103
- }else {
99
+ if (!poolEntry .entryConnect (hostName , port , userId , password , initialScript , enableHighAvailability , highAvailabilitySites , reconnect , loadBalance ))
104
100
log .error (String .format ("Connection %s connect failure." , poolEntry .connectionName ));
105
- }
106
101
poolEntryArrayList .add (poolEntry );
107
102
}
108
103
poolEntries = new CopyOnWriteArrayList <>(poolEntryArrayList );
@@ -161,19 +156,13 @@ boolean isClosed() {
161
156
162
157
class PoolEntry extends DBConnection {
163
158
AtomicBoolean inUse = new AtomicBoolean (false );
164
- volatile boolean isFirstConnect = true ;
165
- volatile boolean isFirstLogin = true ;
166
159
String connectionName ;
167
160
168
161
PoolEntry (boolean useSSL , boolean compress , boolean usePython , String connectionName ) {
169
162
super (false , useSSL , compress , usePython );
170
163
this .connectionName = connectionName ;
171
164
}
172
165
173
- String getConnectionName () {
174
- return connectionName ;
175
- }
176
-
177
166
boolean isIdle () {
178
167
return !this .inUse .get ();
179
168
}
@@ -183,20 +172,18 @@ public void setLoadBalance(boolean loadBalance) {
183
172
throw new RuntimeException ("The loadBalance configuration of connection in connection pool can only be set in SimpleDBConnectionPoolConfig." );
184
173
}
185
174
175
+ private boolean entryConnect (String hostName , int port , String userId , String password , String initialScript , boolean enableHighAvailability , String [] highAvailabilitySites , boolean reconnect , boolean enableLoadBalance ) throws IOException {
176
+ return super .connect (hostName , port , userId , password , initialScript , enableHighAvailability , highAvailabilitySites , reconnect , enableLoadBalance );
177
+ }
178
+
186
179
@ Override
187
180
public boolean connect (String hostName , int port , String userId , String password , String initialScript , boolean enableHighAvailability , String [] highAvailabilitySites , boolean reconnect , boolean enableLoadBalance ) throws IOException {
188
- if (isFirstConnect )
189
- return super .connect (hostName , port , userId , password , initialScript , enableHighAvailability , highAvailabilitySites , reconnect , enableLoadBalance );
190
- else
191
- throw new RuntimeException ("The connection in connection pool can only connect by pool." );
181
+ throw new RuntimeException ("The connection in connection pool can only connect by pool." );
192
182
}
193
183
194
184
@ Override
195
185
public void login (String userId , String password , boolean enableEncryption ) throws IOException {
196
- if (isFirstLogin )
197
- super .login (userId , password , enableEncryption );
198
- else
199
- throw new RuntimeException ("The connection in connection pool can only login by pool." );
186
+ throw new RuntimeException ("The connection in connection pool can only login by pool." );
200
187
}
201
188
202
189
@ Override
0 commit comments