Merge pull request #804 from Chase22/configure-longpolling

Add timeout and limit for long-polling updates to DefaultBotOptions
This commit is contained in:
Ruben Bermudez 2020-10-21 19:34:23 +01:00 committed by GitHub
commit 02674a2a39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -26,6 +26,8 @@ public class DefaultBotOptions implements BotOptions {
private ProxyType proxyType;
private String proxyHost;
private int proxyPort;
private int getUpdatesTimeout;
private int getUpdatesLimit;
public enum ProxyType {
NO_PROXY,
@ -39,6 +41,8 @@ public class DefaultBotOptions implements BotOptions {
baseUrl = ApiConstants.BASE_URL;
httpContext = HttpClientContext.create();
proxyType = ProxyType.NO_PROXY;
getUpdatesLimit = ApiConstants.GETUPDATES_TIMEOUT;
getUpdatesLimit = 100;
}
@Override
@ -129,4 +133,20 @@ public class DefaultBotOptions implements BotOptions {
public void setProxyPort(int proxyPort) {
this.proxyPort = proxyPort;
}
public int getGetUpdatesTimeout() {
return getUpdatesTimeout;
}
public void setGetUpdatesTimeout(int getUpdatesTimeout) {
this.getUpdatesTimeout = getUpdatesTimeout;
}
public int getGetUpdatesLimit() {
return getUpdatesLimit;
}
public void setGetUpdatesLimit(int getUpdatesLimit) {
this.getUpdatesLimit = getUpdatesLimit;
}
}

View File

@ -236,8 +236,8 @@ public class DefaultBotSession implements BotSession {
private List<Update> getUpdatesFromServer() throws IOException {
GetUpdates request = new GetUpdates()
.setLimit(100)
.setTimeout(ApiConstants.GETUPDATES_TIMEOUT)
.setLimit(options.getGetUpdatesLimit())
.setTimeout(options.getGetUpdatesTimeout())
.setOffset(lastReceivedUpdate + 1);
if (options.getAllowedUpdates() != null) {