From 6e5bf92eeab95b56e4f7be4e011235844c60537f Mon Sep 17 00:00:00 2001 From: yunlongn Date: Thu, 13 Feb 2025 14:12:28 +0800 Subject: [PATCH] [type:refactor] refactor springcloud plugin. --- .../shenyu/admin/discovery/AbstractDiscoveryProcessor.java | 4 ++-- .../zookeeper/ZookeeperInstanceRegisterRepository.java | 2 +- .../starter/client/grpc/ShenyuGrpcDiscoveryConfiguration.java | 3 ++- .../ShenyuSpringWebSocketDiscoveryConfiguration.java | 4 +++- .../springmvc/ShenyuSpringMvcDiscoveryConfiguration.java | 3 ++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/discovery/AbstractDiscoveryProcessor.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/discovery/AbstractDiscoveryProcessor.java index 7bb9876cc087..9187e62406dc 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/discovery/AbstractDiscoveryProcessor.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/discovery/AbstractDiscoveryProcessor.java @@ -111,7 +111,7 @@ public void createDiscovery(final DiscoveryDO discoveryDO) { */ @Override public void removeDiscovery(final DiscoveryDO discoveryDO) { - ShenyuDiscoveryService shenyuDiscoveryService = discoveryServiceCache.remove(discoveryDO.getId()); + ShenyuInstanceRegisterRepository shenyuDiscoveryService = discoveryServiceCache.remove(discoveryDO.getId()); if (Objects.isNull(shenyuDiscoveryService)) { return; } @@ -253,7 +253,7 @@ public DataChangedEventListener getDiscoveryDataChangedEventListener(final Disco */ public void addDiscoverySyncDataListener(final DiscoveryHandlerDTO discoveryHandlerDTO, final ProxySelectorDTO proxySelectorDTO) { final DataChangedEventListener changedEventListener = this.getChangedEventListener(discoveryHandlerDTO.getDiscoveryId()); - if (changedEventListener != null) { + if (Objects.nonNull(changedEventListener)) { DiscoverySyncData discoverySyncData = new DiscoverySyncData(); discoverySyncData.setPluginName(proxySelectorDTO.getPluginName()); discoverySyncData.setSelectorName(proxySelectorDTO.getName()); diff --git a/shenyu-registry/shenyu-registry-zookeeper/src/main/java/org/apache/shenyu/registry/zookeeper/ZookeeperInstanceRegisterRepository.java b/shenyu-registry/shenyu-registry-zookeeper/src/main/java/org/apache/shenyu/registry/zookeeper/ZookeeperInstanceRegisterRepository.java index 313398146598..f21128399640 100644 --- a/shenyu-registry/shenyu-registry-zookeeper/src/main/java/org/apache/shenyu/registry/zookeeper/ZookeeperInstanceRegisterRepository.java +++ b/shenyu-registry/shenyu-registry-zookeeper/src/main/java/org/apache/shenyu/registry/zookeeper/ZookeeperInstanceRegisterRepository.java @@ -171,7 +171,7 @@ public void process(final WatchedEvent event) { @Override public boolean serviceExists(final String key) { try { - return null != client.get(key); + return Objects.nonNull(client.get(key)); } catch (Exception e) { throw new ShenyuException(e); } diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-grpc/src/main/java/org/apache/springboot/starter/client/grpc/ShenyuGrpcDiscoveryConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-grpc/src/main/java/org/apache/springboot/starter/client/grpc/ShenyuGrpcDiscoveryConfiguration.java index 4e0549b3bcf5..752d4917e603 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-grpc/src/main/java/org/apache/springboot/starter/client/grpc/ShenyuGrpcDiscoveryConfiguration.java +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-grpc/src/main/java/org/apache/springboot/starter/client/grpc/ShenyuGrpcDiscoveryConfiguration.java @@ -36,6 +36,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; +import java.util.Objects; import java.util.Optional; @Configuration @@ -66,7 +67,7 @@ public InstanceRegisterListener instanceRegisterListener(final ClientRegisterCon discoveryUpstreamData.setProtocol(Optional.ofNullable(shenyuDiscoveryConfig.getProtocol()).orElse(ShenyuClientConstants.HTTP)); discoveryUpstreamData.setNamespaceId(shenyuClientConfig.getNamespace()); final String appName = environment.getProperty("spring.application.name"); - if (StringUtils.isEmpty(shenyuDiscoveryConfig.getProps().getProperty("name")) && appName != null) { + if (StringUtils.isEmpty(shenyuDiscoveryConfig.getProps().getProperty("name")) && Objects.nonNull(appName)) { shenyuDiscoveryConfig.getProps().put("name", appName); } return new InstanceRegisterListener(discoveryUpstreamData, shenyuDiscoveryConfig); diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-spring-websocket/src/main/java/org/apache/shenyu/springboot/starter/client/spring/websocket/ShenyuSpringWebSocketDiscoveryConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-spring-websocket/src/main/java/org/apache/shenyu/springboot/starter/client/spring/websocket/ShenyuSpringWebSocketDiscoveryConfiguration.java index c9078405cd2a..59b8a85b8672 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-spring-websocket/src/main/java/org/apache/shenyu/springboot/starter/client/spring/websocket/ShenyuSpringWebSocketDiscoveryConfiguration.java +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-spring-websocket/src/main/java/org/apache/shenyu/springboot/starter/client/spring/websocket/ShenyuSpringWebSocketDiscoveryConfiguration.java @@ -37,6 +37,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; +import java.util.Objects; + @Configuration @ImportAutoConfiguration(ShenyuClientCommonBeanConfiguration.class) public class ShenyuSpringWebSocketDiscoveryConfiguration { @@ -84,7 +86,7 @@ public InstanceRegisterListener instanceRegisterListener(final SpringWebSocketCl discoveryUpstreamData.setUrl(eventListener.getHost() + ":" + eventListener.getPort()); discoveryUpstreamData.setNamespaceId(shenyuClientConfig.getNamespace()); final String appName = environment.getProperty("spring.application.name"); - if (StringUtils.isEmpty(shenyuDiscoveryConfig.getProps().getProperty("name")) && appName != null) { + if (StringUtils.isEmpty(shenyuDiscoveryConfig.getProps().getProperty("name")) && Objects.nonNull(appName)) { shenyuDiscoveryConfig.getProps().put("name", appName); } return new InstanceRegisterListener(discoveryUpstreamData, shenyuDiscoveryConfig); diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-springmvc/src/main/java/org/apache/shenyu/springboot/starter/client/springmvc/ShenyuSpringMvcDiscoveryConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-springmvc/src/main/java/org/apache/shenyu/springboot/starter/client/springmvc/ShenyuSpringMvcDiscoveryConfiguration.java index 84aab8ec16ba..3569772f4d22 100644 --- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-springmvc/src/main/java/org/apache/shenyu/springboot/starter/client/springmvc/ShenyuSpringMvcDiscoveryConfiguration.java +++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-springmvc/src/main/java/org/apache/shenyu/springboot/starter/client/springmvc/ShenyuSpringMvcDiscoveryConfiguration.java @@ -37,6 +37,7 @@ import org.springframework.context.annotation.Primary; import org.springframework.core.env.Environment; +import java.util.Objects; import java.util.Optional; @Configuration @@ -88,7 +89,7 @@ public InstanceRegisterListener instanceRegisterListener(final ClientRegisterCon discoveryUpstreamData.setProtocol(Optional.ofNullable(shenyuDiscoveryConfig.getProtocol()).orElse(ShenyuClientConstants.HTTP)); discoveryUpstreamData.setNamespaceId(shenyuClientConfig.getNamespace()); final String appName = environment.getProperty("spring.application.name"); - if (StringUtils.isEmpty(shenyuDiscoveryConfig.getProps().getProperty("name")) && appName != null) { + if (StringUtils.isEmpty(shenyuDiscoveryConfig.getProps().getProperty("name")) && Objects.nonNull(appName)) { shenyuDiscoveryConfig.getProps().put("name", appName); } return new InstanceRegisterListener(discoveryUpstreamData, shenyuDiscoveryConfig);