Skip to content

Commit

Permalink
allow user to override default read timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
JW Wesson committed Oct 3, 2024
1 parent de9b074 commit cfe80b9
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/main/java/com/textkernel/tx/TxClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,24 @@ public TxClient(String accountId, String serviceKey, DataCenter dataCenter) {
* Create an SDK client to perform Tx API calls with the account information found at https://cloud.textkernel.com/tx/console
* @param accountId - The account id for your account
* @param serviceKey - The service key for your account
* @param dataCenter - The Data Center for your account. Either {@link DataCenter#US}, {@link DataCenter#EU} or {@link DataCenter#AU}
* @param dataCenter - The Data Center for your account. Either {@link DataCenter#US}, {@link DataCenter#EU}, or @link DataCenter#AU}
* @param trackingTags - Optional tags to use to track API usage for your account
* @throws IllegalArgumentException if the accountId, serviceKey, or dataCenter are null/empty
*/
public TxClient(String accountId, String serviceKey, DataCenter dataCenter, List<String> trackingTags) {
this(accountId, serviceKey, dataCenter, trackingTags, 30);
}

/**
* Create an SDK client to perform Tx API calls with the account information found at https://cloud.textkernel.com/tx/console
* @param accountId - The account id for your account
* @param serviceKey - The service key for your account
* @param dataCenter - The Data Center for your account. Either {@link DataCenter#US}, {@link DataCenter#EU} or {@link DataCenter#AU}
* @param trackingTags - Optional tags to use to track API usage for your account
* @param httpTimeoutSecs - Optional override for the OkHttp client read timeout (write and connect are 10 seconds, read is 30 seconds by default)
* @throws IllegalArgumentException if the accountId, serviceKey, or dataCenter are null/empty
*/
public TxClient(String accountId, String serviceKey, DataCenter dataCenter, List<String> trackingTags, long httpTimeoutSecs) {

if (accountId == null || accountId.length() == 0) {
throw new IllegalArgumentException("'accountId' must have a valid value");
Expand All @@ -141,6 +154,10 @@ public TxClient(String accountId, String serviceKey, DataCenter dataCenter, List
throw new IllegalArgumentException("'dataCenter' must not be null");
}

if (httpTimeoutSecs <= 0) {
throw new IllegalArgumentException("'httpTimeoutSecs' must be greater than 0");
}

_endpoints = new ApiEndpoints(dataCenter);

final String trackingTagsHeaderValue;//must be final to be passed into the interceptor below
Expand Down Expand Up @@ -184,7 +201,7 @@ public Response intercept(Interceptor.Chain chain) throws IOException {
})
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.readTimeout(httpTimeoutSecs, TimeUnit.SECONDS)
.build();
}

Expand Down

0 comments on commit cfe80b9

Please sign in to comment.