This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new d39228c Remove warning code of HttpSyncDataService.java (#2383)
d39228c is described below
commit d39228cfa4f38c899418169f8035104656522eb3
Author: Kunshuai Zhu <[email protected]>
AuthorDate: Wed Nov 17 15:54:29 2021 +0800
Remove warning code of HttpSyncDataService.java (#2383)
---
.../shenyu/sync/data/http/HttpSyncDataService.java | 26 +++++++++-------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git
a/shenyu-sync-data-center/shenyu-sync-data-http/src/main/java/org/apache/shenyu/sync/data/http/HttpSyncDataService.java
b/shenyu-sync-data-center/shenyu-sync-data-http/src/main/java/org/apache/shenyu/sync/data/http/HttpSyncDataService.java
index e6009b1..d4044d7 100644
---
a/shenyu-sync-data-center/shenyu-sync-data-http/src/main/java/org/apache/shenyu/sync/data/http/HttpSyncDataService.java
+++
b/shenyu-sync-data-center/shenyu-sync-data-http/src/main/java/org/apache/shenyu/sync/data/http/HttpSyncDataService.java
@@ -60,7 +60,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
/**
* HTTP long polling implementation.
*/
-@SuppressWarnings("all")
public class HttpSyncDataService implements SyncDataService, AutoCloseable {
/**
@@ -85,25 +84,22 @@ public class HttpSyncDataService implements
SyncDataService, AutoCloseable {
/**
* default: 10s.
*/
- private Duration connectionTimeout = Duration.ofSeconds(10);
+ private final Duration connectionTimeout = Duration.ofSeconds(10);
/**
* only use for http long polling.
*/
- private RestTemplate httpClient;
+ private final RestTemplate httpClient;
private ExecutorService executor;
- private HttpConfig httpConfig;
+ private final List<String> serverList;
- private List<String> serverList;
-
- private DataRefreshFactory factory;
+ private final DataRefreshFactory factory;
public HttpSyncDataService(final HttpConfig httpConfig, final
PluginDataSubscriber pluginDataSubscriber,
final List<MetaDataSubscriber>
metaDataSubscribers, final List<AuthDataSubscriber> authDataSubscribers) {
this.factory = new DataRefreshFactory(pluginDataSubscriber,
metaDataSubscribers, authDataSubscribers);
- this.httpConfig = httpConfig;
this.serverList =
Lists.newArrayList(Splitter.on(",").split(httpConfig.getUrl()));
this.httpClient = createRestTemplate();
this.start();
@@ -155,7 +151,7 @@ public class HttpSyncDataService implements
SyncDataService, AutoCloseable {
}
String url = server + SHENYU_ADMIN_PATH_CONFIGS_FETCH + "?" +
StringUtils.removeEnd(params.toString(), "&");
LOG.info("request configs: [{}]", url);
- String json = null;
+ String json;
try {
json = this.httpClient.getForObject(url, String.class);
} catch (RestClientException e) {
@@ -187,7 +183,6 @@ public class HttpSyncDataService implements
SyncDataService, AutoCloseable {
return factory.executor(data);
}
- @SuppressWarnings("unchecked")
private void doLongPolling(final String server) {
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(8);
for (ConfigGroupEnum group : ConfigGroupEnum.values()) {
@@ -199,11 +194,11 @@ public class HttpSyncDataService implements
SyncDataService, AutoCloseable {
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
- HttpEntity httpEntity = new HttpEntity(params, headers);
+ HttpEntity<MultiValueMap<String, String>> httpEntity = new
HttpEntity<>(params, headers);
String listenerUrl = server + SHENYU_ADMIN_PATH_CONFIGS_LISTENER;
LOG.debug("request listener configs: [{}]", listenerUrl);
- JsonArray groupJson = null;
+ JsonArray groupJson;
try {
String json = this.httpClient.postForEntity(listenerUrl,
httpEntity, String.class).getBody();
LOG.debug("listener result: [{}]", json);
@@ -224,7 +219,7 @@ public class HttpSyncDataService implements
SyncDataService, AutoCloseable {
}
@Override
- public void close() throws Exception {
+ public void close() {
RUNNING.set(false);
if (Objects.nonNull(executor)) {
executor.shutdownNow();
@@ -235,9 +230,7 @@ public class HttpSyncDataService implements
SyncDataService, AutoCloseable {
class HttpLongPollingTask implements Runnable {
- private String server;
-
- private final int retryTimes = 3;
+ private final String server;
HttpLongPollingTask(final String server) {
this.server = server;
@@ -246,6 +239,7 @@ public class HttpSyncDataService implements
SyncDataService, AutoCloseable {
@Override
public void run() {
while (RUNNING.get()) {
+ int retryTimes = 3;
for (int time = 1; time <= retryTimes; time++) {
try {
doLongPolling(server);