You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/09/03 04:40:01 UTC
[shardingsphere] branch master updated: Optimize code (#12187)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 2bdbb14 Optimize code (#12187)
2bdbb14 is described below
commit 2bdbb14941f5011e2694bba2b63f151faf3df508
Author: Dachuan J <46...@users.noreply.github.com>
AuthorDate: Fri Sep 3 12:39:26 2021 +0800
Optimize code (#12187)
---
.../agent/core/config/yaml/YamlAgentConfiguration.java | 9 +++++----
.../core/config/yaml/swapper/YamlAgentConfigurationSwapper.java | 8 +++++---
.../agent/core/plugin/PluginBootServiceManager.java | 6 +++---
3 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java
index 1f03965..82e0cad 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java
@@ -17,12 +17,13 @@
package org.apache.shardingsphere.agent.core.config.yaml;
-import java.util.HashMap;
+import lombok.Getter;
+import lombok.Setter;
+
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
-import lombok.Getter;
-import lombok.Setter;
/**
* YAML agent configuration.
@@ -35,5 +36,5 @@ public final class YamlAgentConfiguration {
private Set<String> ignoredPluginNames = new HashSet<>();
- private Map<String, YamlPluginConfiguration> plugins = new HashMap<>();
+ private Map<String, YamlPluginConfiguration> plugins = new LinkedHashMap<>();
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java
index e45e2f1..1906909 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java
@@ -24,9 +24,8 @@ import org.apache.shardingsphere.agent.config.PluginConfiguration;
import org.apache.shardingsphere.agent.core.config.yaml.YamlAgentConfiguration;
import org.apache.shardingsphere.agent.core.config.yaml.YamlPluginConfiguration;
+import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
/**
* YAML agent configuration swapper.
@@ -41,7 +40,10 @@ public final class YamlAgentConfigurationSwapper {
* @return agent configuration
*/
public static AgentConfiguration swap(final YamlAgentConfiguration yamlConfig) {
- Map<String, PluginConfiguration> configurationMap = yamlConfig.getPlugins().entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> transform(entry.getValue())));
+ Map<String, PluginConfiguration> configurationMap = new LinkedHashMap<>();
+ for (Map.Entry<String, YamlPluginConfiguration> entry : yamlConfig.getPlugins().entrySet()) {
+ configurationMap.put(entry.getKey(), transform(entry.getValue()));
+ }
return new AgentConfiguration(yamlConfig.getApplicationName(), yamlConfig.getIgnoredPluginNames(), configurationMap);
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginBootServiceManager.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginBootServiceManager.java
index 13ac091..fb4aba8 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginBootServiceManager.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/PluginBootServiceManager.java
@@ -45,11 +45,11 @@ public final class PluginBootServiceManager {
public static void startAllServices(final Map<String, PluginConfiguration> pluginConfigurationMap) {
Set<String> ignoredPluginNames = AgentConfigurationRegistry.INSTANCE.get(AgentConfiguration.class).getIgnoredPluginNames();
for (Entry<String, PluginConfiguration> entry: pluginConfigurationMap.entrySet()) {
+ if (!ignoredPluginNames.isEmpty() && ignoredPluginNames.contains(entry.getKey())) {
+ continue;
+ }
AgentTypedSPIRegistry.getRegisteredServiceOptional(PluginBootService.class, entry.getKey()).ifPresent(pluginBootService -> {
try {
- if (!ignoredPluginNames.isEmpty() && ignoredPluginNames.contains(pluginBootService.getType())) {
- return;
- }
log.info("Start plugin: {}", pluginBootService.getType());
pluginBootService.start(entry.getValue());
// CHECKSTYLE:OFF