Skip to content

Commit

Permalink
[type:refactor] refactor springcloud plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunlongn committed Feb 13, 2025
1 parent 840002c commit 6e5bf92
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6e5bf92

Please sign in to comment.