Skip to content

Commit 8a9b904

Browse files
committed
Add maxRetries & retryIntervalMs mangement in HTTP calls
1 parent 9f6a29f commit 8a9b904

File tree

8 files changed

+117
-13
lines changed

8 files changed

+117
-13
lines changed

.settings/org.eclipse.jdt.core.prefs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
5+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6+
org.eclipse.jdt.core.compiler.compliance=1.8
7+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
12+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
13+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
14+
org.eclipse.jdt.core.compiler.release=disabled
15+
org.eclipse.jdt.core.compiler.source=1.8

src/main/java/com/aceql/jdbc/commons/ConnectionInfo.java

+32-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public class ConnectionInfo {
6767
private Map<String, String> requestProperties = new HashMap<>();
6868
private String clobReadCharset;
6969
private String clobWriteCharset;
70+
71+
private int maxRetries;
72+
private int retryIntervalMs;
7073

7174
/**
7275
* Package protected constructor, Driver users can not instantiate the class.
@@ -87,6 +90,9 @@ public class ConnectionInfo {
8790
this.requestProperties = connectionInfoHolder.getRequestProperties();
8891
this.clobReadCharset = connectionInfoHolder.getClobReadCharset();
8992
this.clobWriteCharset = connectionInfoHolder.getClobWriteCharset();
93+
94+
this.maxRetries = connectionInfoHolder.getMaxRetries();
95+
this.retryIntervalMs = connectionInfoHolder.getRetryIntervalMs();
9096
}
9197

9298
// /**
@@ -275,8 +281,29 @@ public Instant getCreationDateTime() {
275281
return creationDateTime;
276282
}
277283

278-
@Override
279-
public String toString() {
284+
285+
/**
286+
* Gets the maximum number of retries for failed requests.
287+
* @return the maximum number of retries for failed requests.
288+
*/
289+
public int getMaxRetries() {
290+
return maxRetries;
291+
}
292+
293+
void setMaxRetries(int maxRetries) {
294+
this.maxRetries = maxRetries;
295+
}
296+
297+
/**
298+
* Gets the interval between retries in milliseconds.
299+
* @return the interval between retries in milliseconds.
300+
*/
301+
public int getRetryIntervalMs() {
302+
return retryIntervalMs;
303+
}
304+
305+
//@Override
306+
public String _toString() {
280307

281308
String username = authentication.getUserName();
282309
String proxyUsername = proxyAuthentication != null ? proxyAuthentication.getUserName() : null;
@@ -285,8 +312,11 @@ public String toString() {
285312
+ ", creationDateTime=" + creationDateTime + ", passwordIsSessionId=" + passwordIsSessionId + ", proxy="
286313
+ proxy + ", proxyAuthentication=" + proxyUsername + ", connectTimeout=" + connectTimeout
287314
+ ", readTimeout=" + readTimeout + ", gzipResult=" + gzipResult
315+
+ ", maxRetries=" + maxRetries + ", retryIntervalMs=" + retryIntervalMs
288316
+ ", resultSetMetaDataPolicy=" + resultSetMetaDataPolicy + ", requestProperties=" + requestProperties
289317
+ ", clobReadCharset=" + clobReadCharset + ", clobWriteCharset=" + clobWriteCharset + "]";
290318
}
319+
320+
291321

292322
}

src/main/java/com/aceql/jdbc/commons/ConnectionInfoHolder.java

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class ConnectionInfoHolder {
2828
// New 9.4
2929
private int maxRetries = 0;
3030
private int retryIntervalMs = 0;
31+
3132
public String getUrl() {
3233
return url;
3334
}

src/main/java/com/aceql/jdbc/commons/InternalWrapper.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@
2121
import java.io.File;
2222
import java.io.InputStream;
2323
import java.io.UnsupportedEncodingException;
24-
import java.net.PasswordAuthentication;
25-
import java.net.Proxy;
2624
import java.sql.SQLException;
27-
import java.util.Map;
25+
import java.time.Instant;
2826

2927
import com.aceql.jdbc.commons.main.http.AceQLHttpApi;
3028
import com.aceql.jdbc.commons.main.metadata.dto.DatabaseInfoDto;
3129
import com.aceql.jdbc.commons.main.metadata.dto.LimitsInfoDto;
32-
import com.aceql.jdbc.commons.metadata.ResultSetMetaDataPolicy;
3330

3431
/**
3532
* A internal wrapper for Java package protected calls. <br>
@@ -81,6 +78,9 @@ public static ConnectionInfo connectionInfoBuilder(ConnectionInfoHolder Connecti
8178
return new ConnectionInfo(ConnectionInfoHolder);
8279
}
8380

81+
public static void setCreationDateTime(ConnectionInfo connectionInfo, Instant instant) {
82+
connectionInfo.setCreationDateTime(instant);
83+
}
8484

8585
public static DatabaseInfo databaseInfoBuilder(AceQLHttpApi aceQLHttpApi) throws AceQLException {
8686
DatabaseInfoDto databaseInfoDto = aceQLHttpApi.getDatabaseInfoDto();

src/main/java/com/aceql/jdbc/commons/driver/util/DriverPropertyInfoBuilder.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ public class DriverPropertyInfoBuilder {
2121
public static final String GZIP_RESULT = "Boolean to say if the ResultSet is Gzipped before download. Defaults to true.";
2222
public static final String CLOB_CHARSET = "Name of the charset to use when reading a CLOB content with the ResultSet methods. Defaults to null.";
2323

24-
2524
public static final String DEFINES_THE_RESULT_SET_META_DATA_POLICY = "Defines the ResultSet MetaData policy. Says if the ResultSet MetaData is to be downloaded along with the ResultSet. Possible values are \"on\" and \"off\". Defaults to \"on\".";
2625
private static final String CLOB_WRITE_CHARSET = "Name of the charset to use when writing a CLOB content with the PreparedStatement streaming methods. Defaults to \"UTF-8\".";
2726

27+
public static final String MAX_RETRIES = "Maximum number of retries for connecting to the remote server. Defaults to 3.";
28+
public static final String RETRY_DELAY = "Delay in milliseconds between retries. Defaults to 3000.";
29+
30+
2831
/**
2932
* Build a new DriverPropertyInfo with the passed property
3033
*
@@ -122,6 +125,18 @@ public List<DriverPropertyInfo> build(Properties info) {
122125
driverPropertyInfo.required = false;
123126
driverPropertyInfoList.add(driverPropertyInfo);
124127

128+
driverPropertyInfo = getNewDriverPropertyInfo("maxRetries", info);
129+
driverPropertyInfo.description = MAX_RETRIES;
130+
driverPropertyInfo.required = false;
131+
driverPropertyInfo.value = "3";
132+
driverPropertyInfoList.add(driverPropertyInfo);
133+
134+
driverPropertyInfo = getNewDriverPropertyInfo("retryIntervalMs", info);
135+
driverPropertyInfo.description = RETRY_DELAY;
136+
driverPropertyInfo.required = false;
137+
driverPropertyInfo.value = "3000";
138+
driverPropertyInfoList.add(driverPropertyInfo);
139+
125140
List<String> list = new ArrayList<>();
126141
list.add("on");
127142
list.add("off");

src/main/java/com/aceql/jdbc/commons/driver/util/DriverUtil.java

+39
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,45 @@ public static Map<String, String> getQueryMap(String query) {
211211
return map;
212212
}
213213

214+
/**
215+
* Return the value of a property, taking into account the request properties
216+
* @param info the properties
217+
* @return the value of the property or null if not found
218+
* @throws SQLException
219+
*/
220+
public static int getMaxRetries(Properties info) throws SQLException {
221+
String maxRetriesStr = info.getProperty("maxRetries");
222+
if (maxRetriesStr == null) {
223+
return 0;
224+
}
225+
226+
int maxRetries = 0;
227+
try {
228+
maxRetries = Integer.parseInt(maxRetriesStr);
229+
} catch (NumberFormatException e) {
230+
throw new SQLException(Tag.PRODUCT + " Invalid maxRetries, is not numeric: " + maxRetries);
231+
}
232+
233+
return maxRetries;
234+
}
235+
236+
public static int getIntervalRetryMs(Properties info) throws SQLException {
237+
String intervalRetryMsStr = info.getProperty("intervalRetryMs");
238+
if (intervalRetryMsStr == null) {
239+
return 0;
240+
}
241+
242+
int intervalRetryMs = 0;
243+
try {
244+
intervalRetryMs = Integer.parseInt(intervalRetryMsStr);
245+
} catch (NumberFormatException e) {
246+
throw new SQLException(Tag.PRODUCT + " Invalid intervalRetryMs, is not numeric: " + intervalRetryMsStr);
247+
}
248+
249+
return intervalRetryMs;
250+
251+
}
252+
214253
/**
215254
* Copy a set of properties from one Property to another.
216255
* <p>

src/main/java/com/aceql/jdbc/commons/main/http/HttpManager.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ public PasswordAuthentication getPasswordAuthentication() {
141141
public InputStream callWithGetReturnStream(String url)
142142
throws MalformedURLException, IOException, UnsupportedEncodingException {
143143

144-
int maxRetries = 3;
145-
int retryIntervalMs = 1000;
144+
int maxRetries = this.connectionInfo.getMaxRetries();
145+
int retryIntervalMs = this.connectionInfo.getRetryIntervalMs();
146146

147147
/*
148148
* if (httpVersion == 1) { return callWithGetInputStreamHttp11(url); } else {
@@ -241,8 +241,8 @@ public String callWithGet(String url)
241241
public InputStream callWithPost(URL theUrl, Map<String, String> parameters)
242242
throws IOException, ProtocolException, SocketTimeoutException, UnsupportedEncodingException {
243243

244-
int maxRetries = 3;
245-
int retryIntervalMs = 1000;
244+
int maxRetries = this.connectionInfo.getMaxRetries();
245+
int retryIntervalMs = this.connectionInfo.getRetryIntervalMs();
246246

247247
/*
248248
* if (httpVersion == 1) { return callWithGetInputStreamHttp11(url); } else {

src/main/java/com/aceql/jdbc/driver/free/AceQLDriver.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ public Connection connect(String url, Properties info) throws SQLException {
263263
passwordIsSessionId = true;
264264
}
265265

266+
int maxRetries= DriverUtil.getMaxRetries(info);
267+
int retryIntervalMs = DriverUtil.getIntervalRetryMs(info);
266268

267269
ConnectionInfoHolder connectionInfoHolder = new ConnectionInfoHolder();
268270
connectionInfoHolder.setAuthentication(authentication);
@@ -271,15 +273,17 @@ public Connection connect(String url, Properties info) throws SQLException {
271273
connectionInfoHolder.setConnectTimeout(connectTimeout);
272274
connectionInfoHolder.setDatabase(database);
273275
connectionInfoHolder.setGzipResult(gzipResult);
274-
connectionInfoHolder.setMaxRetries(3);
275276
connectionInfoHolder.setPasswordIsSessionId(passwordIsSessionId);
276277
connectionInfoHolder.setProxy(proxy);
278+
connectionInfoHolder.setProxyAuthentication(proxyAuthentication);
277279
connectionInfoHolder.setReadTimeout(readTimeout);
278280
connectionInfoHolder.setRequestProperties(requestProperties);
279281
connectionInfoHolder.setResultSetMetaDataPolicy(resultSetMetaDataPolicy);
280-
connectionInfoHolder.setRetryIntervalMs(1000);
281282
connectionInfoHolder.setUrl(url);
282283

284+
connectionInfoHolder.setMaxRetries(maxRetries);
285+
connectionInfoHolder.setRetryIntervalMs(retryIntervalMs);
286+
283287
ConnectionInfo connectionInfo = InternalWrapper.connectionInfoBuilder(connectionInfoHolder);
284288
AceQLConnection connection = InternalWrapper.connectionBuilder(connectionInfo);
285289

0 commit comments

Comments
 (0)