Optimize code format

pull/639/head
chen.ma 3 years ago
parent b8059899ad
commit 89cd0ba420

@ -53,12 +53,14 @@ public class JSONUtilTest {
@Test
public void assertParseObjectTypeReference() {
Assert.assertNull(JSONUtil.parseObject(null, new TypeReference<List<Foo>>() {}));
Assert.assertNull(JSONUtil.parseObject(" ", new TypeReference<List<Foo>>() {}));
Assert.assertNull(JSONUtil.parseObject(null, new TypeReference<List<Foo>>() {
}));
Assert.assertNull(JSONUtil.parseObject(" ", new TypeReference<List<Foo>>() {
}));
Assert.assertEquals(
EXPECTED_FOO_ARRAY,
JSONUtil.parseObject(EXPECTED_FOO_JSON_ARRAY, new TypeReference<List<Foo>>() {})
);
JSONUtil.parseObject(EXPECTED_FOO_JSON_ARRAY, new TypeReference<List<Foo>>() {
}));
}
@Test
@ -67,8 +69,7 @@ public class JSONUtilTest {
Assert.assertNull(JSONUtil.parseArray(" ", Foo.class));
Assert.assertEquals(
EXPECTED_FOO_ARRAY,
JSONUtil.parseArray(EXPECTED_FOO_JSON_ARRAY, Foo.class)
);
JSONUtil.parseArray(EXPECTED_FOO_JSON_ARRAY, Foo.class));
}
@EqualsAndHashCode
@ -76,6 +77,7 @@ public class JSONUtilTest {
@NoArgsConstructor
@Data
private static class Foo {
private Integer id;
private String name;
private Foo foo;

@ -1,19 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>hippo4j-example</artifactId>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-example</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hippo4j-config-etcd-spring-boot-starter-example</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
<dependencies>
@ -45,5 +44,4 @@
<version>${revision}</version>
</dependency>
</dependencies>
</project>

@ -17,14 +17,13 @@
package cn.hippo4j.example.config.etcd.config;
import java.util.concurrent.ThreadPoolExecutor;
import cn.hippo4j.core.executor.DynamicThreadPool;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.ThreadPoolExecutor;
/**
* @author : wh
* @date : 2022/9/2 19:26
@ -33,7 +32,6 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class ThreadPoolConfig {
@Bean
@DynamicThreadPool
public ThreadPoolExecutor messageConsumeDynamicExecutor() {
@ -45,8 +43,4 @@ public class ThreadPoolConfig {
.build();
return messageConsumeDynamicExecutor;
}
}

@ -17,13 +17,13 @@
package cn.hippo4j.example.config.etcd.controller;
import java.util.concurrent.ThreadPoolExecutor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.ThreadPoolExecutor;
/**
* @author : wh
* @date : 2022/9/2 19:18
@ -33,14 +33,11 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping
public class TestController {
@Autowired
private ThreadPoolExecutor messageConsumeDynamicExecutor;
@GetMapping("test")
public void test() {
System.out.println(messageConsumeDynamicExecutor.getMaximumPoolSize());
}
}

@ -17,24 +17,18 @@
package cn.hippo4j.config.springboot.starter.refresher;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Objects;
import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.common.toolkit.StringUtil;
import io.etcd.jetcd.ByteSequence;
import io.etcd.jetcd.Client;
import io.etcd.jetcd.ClientBuilder;
import io.etcd.jetcd.KeyValue;
import io.etcd.jetcd.Watch;
import io.etcd.jetcd.*;
import io.etcd.jetcd.kv.GetResponse;
import io.etcd.jetcd.watch.WatchEvent;
import io.etcd.jetcd.watch.WatchResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Objects;
/**
* @author : wh
@ -44,8 +38,6 @@ import org.springframework.context.ApplicationContext;
@Slf4j
public class EtcdRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh {
private ApplicationContext applicationContext;
private Client client;
private static final String ENDPOINTS = "endpoints";
@ -69,7 +61,6 @@ public class EtcdRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh {
String authority = etcd.get(AUTHORITY);
String key = etcd.get(KEY);
Charset charset = StringUtil.isBlank(etcd.get(CHARSET)) ? StandardCharsets.UTF_8 : Charset.forName(etcd.get(CHARSET));
ClientBuilder clientBuilder = Client.builder().endpoints(endpoints.split(","));
// todo
if (Objects.isNull(client)) {
@ -77,7 +68,6 @@ public class EtcdRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh {
.password(ByteSequence.from(password, charset)).authority(authority)
.build() : clientBuilder.build();
}
// todo Currently only supports json
GetResponse getResponse = client.getKVClient().get(ByteSequence.from(key, charset)).get();
KeyValue keyValue = getResponse.getKvs().get(0);
@ -97,20 +87,17 @@ public class EtcdRefresherHandler extends AbstractCoreThreadPoolDynamicRefresh {
Map map = JSONUtil.parseObject(value, Map.class);
dynamicRefresh(keyValue1.getKey().toString(charset), map);
}
}
@Override
public void onError(Throwable throwable) {
log.error("dynamic thread pool etcd config watcher exception ", throwable);
log.error("Dynamic thread pool etcd config watcher exception ", throwable);
}
@Override
public void onCompleted() {
log.info("dynamic thread pool etcd config key refreshed, config key {}", key);
log.info("Dynamic thread pool etcd config key refreshed, config key {}", key);
}
});
}
}
Loading…
Cancel
Save