Skip to content

Commit

Permalink
Add maxRetries & retryIntervalMs mangement in HTTP calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ndepomereu committed Aug 12, 2024
1 parent 9f6a29f commit 8a9b904
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 13 deletions.
15 changes: 15 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
34 changes: 32 additions & 2 deletions src/main/java/com/aceql/jdbc/commons/ConnectionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public class ConnectionInfo {
private Map<String, String> requestProperties = new HashMap<>();
private String clobReadCharset;
private String clobWriteCharset;

private int maxRetries;
private int retryIntervalMs;

/**
* Package protected constructor, Driver users can not instantiate the class.
Expand All @@ -87,6 +90,9 @@ public class ConnectionInfo {
this.requestProperties = connectionInfoHolder.getRequestProperties();
this.clobReadCharset = connectionInfoHolder.getClobReadCharset();
this.clobWriteCharset = connectionInfoHolder.getClobWriteCharset();

this.maxRetries = connectionInfoHolder.getMaxRetries();
this.retryIntervalMs = connectionInfoHolder.getRetryIntervalMs();
}

// /**
Expand Down Expand Up @@ -275,8 +281,29 @@ public Instant getCreationDateTime() {
return creationDateTime;
}

@Override
public String toString() {

/**
* Gets the maximum number of retries for failed requests.
* @return the maximum number of retries for failed requests.
*/
public int getMaxRetries() {
return maxRetries;
}

void setMaxRetries(int maxRetries) {
this.maxRetries = maxRetries;
}

/**
* Gets the interval between retries in milliseconds.
* @return the interval between retries in milliseconds.
*/
public int getRetryIntervalMs() {
return retryIntervalMs;
}

//@Override
public String _toString() {

String username = authentication.getUserName();
String proxyUsername = proxyAuthentication != null ? proxyAuthentication.getUserName() : null;
Expand All @@ -285,8 +312,11 @@ public String toString() {
+ ", creationDateTime=" + creationDateTime + ", passwordIsSessionId=" + passwordIsSessionId + ", proxy="
+ proxy + ", proxyAuthentication=" + proxyUsername + ", connectTimeout=" + connectTimeout
+ ", readTimeout=" + readTimeout + ", gzipResult=" + gzipResult
+ ", maxRetries=" + maxRetries + ", retryIntervalMs=" + retryIntervalMs
+ ", resultSetMetaDataPolicy=" + resultSetMetaDataPolicy + ", requestProperties=" + requestProperties
+ ", clobReadCharset=" + clobReadCharset + ", clobWriteCharset=" + clobWriteCharset + "]";
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ConnectionInfoHolder {
// New 9.4
private int maxRetries = 0;
private int retryIntervalMs = 0;

public String getUrl() {
return url;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/aceql/jdbc/commons/InternalWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@
import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.PasswordAuthentication;
import java.net.Proxy;
import java.sql.SQLException;
import java.util.Map;
import java.time.Instant;

import com.aceql.jdbc.commons.main.http.AceQLHttpApi;
import com.aceql.jdbc.commons.main.metadata.dto.DatabaseInfoDto;
import com.aceql.jdbc.commons.main.metadata.dto.LimitsInfoDto;
import com.aceql.jdbc.commons.metadata.ResultSetMetaDataPolicy;

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

public static void setCreationDateTime(ConnectionInfo connectionInfo, Instant instant) {
connectionInfo.setCreationDateTime(instant);
}

public static DatabaseInfo databaseInfoBuilder(AceQLHttpApi aceQLHttpApi) throws AceQLException {
DatabaseInfoDto databaseInfoDto = aceQLHttpApi.getDatabaseInfoDto();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ public class DriverPropertyInfoBuilder {
public static final String GZIP_RESULT = "Boolean to say if the ResultSet is Gzipped before download. Defaults to true.";
public static final String CLOB_CHARSET = "Name of the charset to use when reading a CLOB content with the ResultSet methods. Defaults to null.";


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\".";
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\".";

public static final String MAX_RETRIES = "Maximum number of retries for connecting to the remote server. Defaults to 3.";
public static final String RETRY_DELAY = "Delay in milliseconds between retries. Defaults to 3000.";


/**
* Build a new DriverPropertyInfo with the passed property
*
Expand Down Expand Up @@ -122,6 +125,18 @@ public List<DriverPropertyInfo> build(Properties info) {
driverPropertyInfo.required = false;
driverPropertyInfoList.add(driverPropertyInfo);

driverPropertyInfo = getNewDriverPropertyInfo("maxRetries", info);
driverPropertyInfo.description = MAX_RETRIES;
driverPropertyInfo.required = false;
driverPropertyInfo.value = "3";
driverPropertyInfoList.add(driverPropertyInfo);

driverPropertyInfo = getNewDriverPropertyInfo("retryIntervalMs", info);
driverPropertyInfo.description = RETRY_DELAY;
driverPropertyInfo.required = false;
driverPropertyInfo.value = "3000";
driverPropertyInfoList.add(driverPropertyInfo);

List<String> list = new ArrayList<>();
list.add("on");
list.add("off");
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/aceql/jdbc/commons/driver/util/DriverUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,45 @@ public static Map<String, String> getQueryMap(String query) {
return map;
}

/**
* Return the value of a property, taking into account the request properties
* @param info the properties
* @return the value of the property or null if not found
* @throws SQLException
*/
public static int getMaxRetries(Properties info) throws SQLException {
String maxRetriesStr = info.getProperty("maxRetries");
if (maxRetriesStr == null) {
return 0;
}

int maxRetries = 0;
try {
maxRetries = Integer.parseInt(maxRetriesStr);
} catch (NumberFormatException e) {
throw new SQLException(Tag.PRODUCT + " Invalid maxRetries, is not numeric: " + maxRetries);
}

return maxRetries;
}

public static int getIntervalRetryMs(Properties info) throws SQLException {
String intervalRetryMsStr = info.getProperty("intervalRetryMs");
if (intervalRetryMsStr == null) {
return 0;
}

int intervalRetryMs = 0;
try {
intervalRetryMs = Integer.parseInt(intervalRetryMsStr);
} catch (NumberFormatException e) {
throw new SQLException(Tag.PRODUCT + " Invalid intervalRetryMs, is not numeric: " + intervalRetryMsStr);
}

return intervalRetryMs;

}

/**
* Copy a set of properties from one Property to another.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public PasswordAuthentication getPasswordAuthentication() {
public InputStream callWithGetReturnStream(String url)
throws MalformedURLException, IOException, UnsupportedEncodingException {

int maxRetries = 3;
int retryIntervalMs = 1000;
int maxRetries = this.connectionInfo.getMaxRetries();
int retryIntervalMs = this.connectionInfo.getRetryIntervalMs();

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

int maxRetries = 3;
int retryIntervalMs = 1000;
int maxRetries = this.connectionInfo.getMaxRetries();
int retryIntervalMs = this.connectionInfo.getRetryIntervalMs();

/*
* if (httpVersion == 1) { return callWithGetInputStreamHttp11(url); } else {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/aceql/jdbc/driver/free/AceQLDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ public Connection connect(String url, Properties info) throws SQLException {
passwordIsSessionId = true;
}

int maxRetries= DriverUtil.getMaxRetries(info);
int retryIntervalMs = DriverUtil.getIntervalRetryMs(info);

ConnectionInfoHolder connectionInfoHolder = new ConnectionInfoHolder();
connectionInfoHolder.setAuthentication(authentication);
Expand All @@ -271,15 +273,17 @@ public Connection connect(String url, Properties info) throws SQLException {
connectionInfoHolder.setConnectTimeout(connectTimeout);
connectionInfoHolder.setDatabase(database);
connectionInfoHolder.setGzipResult(gzipResult);
connectionInfoHolder.setMaxRetries(3);
connectionInfoHolder.setPasswordIsSessionId(passwordIsSessionId);
connectionInfoHolder.setProxy(proxy);
connectionInfoHolder.setProxyAuthentication(proxyAuthentication);
connectionInfoHolder.setReadTimeout(readTimeout);
connectionInfoHolder.setRequestProperties(requestProperties);
connectionInfoHolder.setResultSetMetaDataPolicy(resultSetMetaDataPolicy);
connectionInfoHolder.setRetryIntervalMs(1000);
connectionInfoHolder.setUrl(url);

connectionInfoHolder.setMaxRetries(maxRetries);
connectionInfoHolder.setRetryIntervalMs(retryIntervalMs);

ConnectionInfo connectionInfo = InternalWrapper.connectionInfoBuilder(connectionInfoHolder);
AceQLConnection connection = InternalWrapper.connectionBuilder(connectionInfo);

Expand Down

0 comments on commit 8a9b904

Please sign in to comment.