Commit a1ac97b4 by 张乐 Committed by GitHub

Merge pull request #645 from nobodyiam/admin-service-address-locator

use RestTemplateFactory to create rest template
parents 8db5e264 0cddf9cf
......@@ -32,7 +32,6 @@ import javax.annotation.PostConstruct;
@Component
public class AdminServiceAddressLocator {
private static final int DEFAULT_TIMEOUT_MS = 1000;
private static final long NORMAL_REFRESH_INTERVAL = 5 * 60 * 1000;
private static final long OFFLINE_REFRESH_INTERVAL = 10 * 1000;
private static final int RETRY_TIMES = 3;
......@@ -48,24 +47,15 @@ public class AdminServiceAddressLocator {
private HttpMessageConverters httpMessageConverters;
@Autowired
private PortalSettings portalSettings;
@Autowired
private RestTemplateFactory restTemplateFactory;
@PostConstruct
public void init() {
allEnvs = portalSettings.getAllEnvs();
//init restTemplate
restTemplate = new RestTemplate(httpMessageConverters.getConverters());
if (restTemplate.getRequestFactory() instanceof SimpleClientHttpRequestFactory) {
SimpleClientHttpRequestFactory rf =
(SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
rf.setReadTimeout(DEFAULT_TIMEOUT_MS);
rf.setConnectTimeout(DEFAULT_TIMEOUT_MS);
} else if (restTemplate.getRequestFactory() instanceof HttpComponentsClientHttpRequestFactory) {
HttpComponentsClientHttpRequestFactory rf =
(HttpComponentsClientHttpRequestFactory) restTemplate.getRequestFactory();
rf.setReadTimeout(DEFAULT_TIMEOUT_MS);
rf.setConnectTimeout(DEFAULT_TIMEOUT_MS);
}
restTemplate = restTemplateFactory.getObject();
refreshServiceAddressService =
Executors.newScheduledThreadPool(1, ApolloThreadFactory.create("ServiceLocator", false));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment