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