-
Notifications
You must be signed in to change notification settings - Fork 145
Implement configurable connection timeouts on the DefaultHttpProvider #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement configurable connection timeouts on the DefaultHttpProvider #190
Conversation
|
Could you guys take a look at this and see if it makes sense. |
1aea835 to
9a1d3e9
Compare
c0d4da4 to
a73cdb8
Compare
.gitignore
Outdated
| .idea | ||
|
|
||
| # Output | ||
| /out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert changes to this file.
| /** | ||
| * Default connection read timeout | ||
| */ | ||
| private static final int DEFAULT_READ_TIMEOUT_MS = 30_000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove final, by keeping it final it can never be changed and the value will be always 30 _000.
| /** | ||
| * Default connect timeout | ||
| */ | ||
| private static final int DEFAULT_CONNECT_TIMEOUT_MS = 30_000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove final, by keeping it final it can never be changed and the value will be always 30 _000.
| public int getConnectTimeout() { | ||
| return DEFAULT_CONNECT_TIMEOUT_MS; | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide setter for DEFAULT_CONNECT_TIMEOUT_MS.
| @Override | ||
| public int getReadTimeout() { | ||
| return DEFAULT_READ_TIMEOUT_MS; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide setter for DEFAULT_READ_TIMEOUT_MS.
| * @return the timeout in milliseconds | ||
| */ | ||
| int getReadTimeout(); | ||
| } No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide void setReadTimeout(); so that change of DEFAULT_READ_TIMEOUT_MS is possible.
| /** | ||
| * The connection config | ||
| */ | ||
| private final IConnectionConfig connectionConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove final from here, so that any class implementing IConnectionConfig can be used rather depending on fixed DefaultConnectionConfig.
| * The connection config | ||
| */ | ||
| private final IConnectionConfig connectionConfig; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide getter and setter for connectionConfig in DefaultHttpProvider and IHttpProvider.
| final IExecutors executors, | ||
| final ILogger logger, | ||
| final IConnectionConfig connectionConfig | ||
| ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a new constructor is not required.
| final URL requestUrl = request.getRequestUrl(); | ||
| logger.logDebug("Starting to send request, URL " + requestUrl.toString()); | ||
| final IConnection connection = connectionFactory.createFromRequest(request); | ||
| connection.setConnectTimeout(connectionConfig.getConnectTimeout()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use this
if(this.connectionConfig == null) {
this.connectionConfig = new DefaultConnectionConfig();
}
So, that default values are only used when config is null.
This connection.setConnectTimeout(connectionConfig.getConnectTimeout()); is fine.
| logger.logDebug("Starting to send request, URL " + requestUrl.toString()); | ||
| final IConnection connection = connectionFactory.createFromRequest(request); | ||
| connection.setConnectTimeout(connectionConfig.getConnectTimeout()); | ||
| connection.setReadTimeout(connectionConfig.getReadTimeout()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine.
|
Hi, DefaultConnectionConfig will contain the values of timeout which can be changed using set and get. This config will be passed using getter and setter in DefaultHttpProvider to change value of IConnectionConfig connectionConfig. Timeout and connectionConfig cannot be made final as they can be changed. |
|
We have fixed the issue using PR: #216 |
Currently there is no way to configure the connection timeouts to custom values as they are hard coded. This change allows connection timeouts to be configured.