Add DI for TelegramFileDownloader, fix it for proxy usage

- add DI for TelegramFileDownloader
- replace volatile variables with final
This commit is contained in:
Eugene Kortov 2019-11-20 16:45:38 +04:00
parent 27649a99cf
commit ff96318fef

View File

@ -65,9 +65,9 @@ public abstract class DefaultAbsSender extends AbsSender {
protected final ExecutorService exe; protected final ExecutorService exe;
private final ObjectMapper objectMapper = new ObjectMapper(); private final ObjectMapper objectMapper = new ObjectMapper();
private final DefaultBotOptions options; private final DefaultBotOptions options;
private volatile CloseableHttpClient httpClient; private final CloseableHttpClient httpClient;
private volatile RequestConfig requestConfig; private final RequestConfig requestConfig;
private final TelegramFileDownloader telegramFileDownloader = new TelegramFileDownloader(this::getBotToken); private final TelegramFileDownloader telegramFileDownloader;
protected DefaultAbsSender(DefaultBotOptions options) { protected DefaultAbsSender(DefaultBotOptions options) {
super(); super();
@ -76,11 +76,14 @@ public abstract class DefaultAbsSender extends AbsSender {
this.options = options; this.options = options;
httpClient = TelegramHttpClientBuilder.build(options); httpClient = TelegramHttpClientBuilder.build(options);
this.telegramFileDownloader = new TelegramFileDownloader(httpClient, this::getBotToken);
configureHttpContext(); configureHttpContext();
requestConfig = options.getRequestConfig(); final RequestConfig configFromOptions = options.getRequestConfig();
if (requestConfig == null) { if (configFromOptions != null) {
requestConfig = RequestConfig.copy(RequestConfig.custom().build()) this.requestConfig = configFromOptions;
} else {
this.requestConfig = RequestConfig.copy(RequestConfig.custom().build())
.setSocketTimeout(SOCKET_TIMEOUT) .setSocketTimeout(SOCKET_TIMEOUT)
.setConnectTimeout(SOCKET_TIMEOUT) .setConnectTimeout(SOCKET_TIMEOUT)
.setConnectionRequestTimeout(SOCKET_TIMEOUT).build(); .setConnectionRequestTimeout(SOCKET_TIMEOUT).build();