Skip to content

Commit

Permalink
Remove warning code of HttpSyncDataService.java (apache#2383)
Browse files Browse the repository at this point in the history
  • Loading branch information
JooKS-me authored Nov 17, 2021
1 parent 7df5d56 commit d39228c
Showing 1 changed file with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
/**
* HTTP long polling implementation.
*/
@SuppressWarnings("all")
public class HttpSyncDataService implements SyncDataService, AutoCloseable {

/**
Expand All @@ -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();
Expand Down Expand Up @@ -155,7 +151,7 @@ private void doFetchGroupConfig(final String server, final ConfigGroupEnum... gr
}
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) {
Expand Down Expand Up @@ -187,7 +183,6 @@ private boolean updateCacheWithJson(final String json) {
return factory.executor(data);
}

@SuppressWarnings("unchecked")
private void doLongPolling(final String server) {
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(8);
for (ConfigGroupEnum group : ConfigGroupEnum.values()) {
Expand All @@ -199,11 +194,11 @@ private void doLongPolling(final String server) {
}
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);
Expand All @@ -224,7 +219,7 @@ private void doLongPolling(final String server) {
}

@Override
public void close() throws Exception {
public void close() {
RUNNING.set(false);
if (Objects.nonNull(executor)) {
executor.shutdownNow();
Expand All @@ -235,9 +230,7 @@ public void close() throws Exception {

class HttpLongPollingTask implements Runnable {

private String server;

private final int retryTimes = 3;
private final String server;

HttpLongPollingTask(final String server) {
this.server = server;
Expand All @@ -246,6 +239,7 @@ class HttpLongPollingTask implements Runnable {
@Override
public void run() {
while (RUNNING.get()) {
int retryTimes = 3;
for (int time = 1; time <= retryTimes; time++) {
try {
doLongPolling(server);
Expand Down

0 comments on commit d39228c

Please sign in to comment.