This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 31845af56b0 Refactor YamlLoggingRuleConfigurationSwapper (#33014)
31845af56b0 is described below
commit 31845af56b0abd29fd00b5e47d22972fe564ea6c
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Sep 26 22:50:05 2024 +0800
Refactor YamlLoggingRuleConfigurationSwapper (#33014)
---
.../YamlAppendersConfigurationConverter.java | 55 ----------------------
.../config/YamlLoggersConfigurationConverter.java | 55 ----------------------
.../YamlLoggingRuleConfigurationSwapper.java | 18 ++++---
3 files changed, 11 insertions(+), 117 deletions(-)
diff --git
a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/config/YamlAppendersConfigurationConverter.java
b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/config/YamlAppendersConfigurationConverter.java
deleted file mode 100644
index 0918b101cbf..00000000000
---
a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/config/YamlAppendersConfigurationConverter.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.logging.yaml.config;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.logging.logger.ShardingSphereAppender;
-import org.apache.shardingsphere.logging.yaml.swapper.YamlAppenderSwapper;
-
-import java.util.Collection;
-import java.util.stream.Collectors;
-
-/**
- * Configuration converter for YAML appenders content.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class YamlAppendersConfigurationConverter {
-
- private static final YamlAppenderSwapper SWAPPER = new
YamlAppenderSwapper();
-
- /**
- * Convert to YAML appender configurations.
- *
- * @param appenders ShardingSphere appenders
- * @return YAML appenders content
- */
- public static Collection<YamlAppenderConfiguration>
convertYamlAppenderConfigurations(final Collection<ShardingSphereAppender>
appenders) {
- return
appenders.stream().map(SWAPPER::swapToYamlConfiguration).collect(Collectors.toList());
- }
-
- /**
- * Convert to ShardingSphere appenders.
- *
- * @param appenders YAML appenders content
- * @return ShardingSphere appenders
- */
- public static Collection<ShardingSphereAppender>
convertShardingSphereAppender(final Collection<YamlAppenderConfiguration>
appenders) {
- return
appenders.stream().map(SWAPPER::swapToObject).collect(Collectors.toList());
- }
-}
diff --git
a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/config/YamlLoggersConfigurationConverter.java
b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/config/YamlLoggersConfigurationConverter.java
deleted file mode 100644
index ea5fa554379..00000000000
---
a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/config/YamlLoggersConfigurationConverter.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.logging.yaml.config;
-
-import org.apache.shardingsphere.logging.logger.ShardingSphereLogger;
-import org.apache.shardingsphere.logging.yaml.swapper.YamlLoggerSwapper;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-import java.util.Collection;
-import java.util.stream.Collectors;
-
-/**
- * Configuration converter for YAML loggers content.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class YamlLoggersConfigurationConverter {
-
- private static final YamlLoggerSwapper SWAPPER = new YamlLoggerSwapper();
-
- /**
- * Convert to YAML logger configurations.
- *
- * @param loggers ShardingSphere loggers
- * @return YAML loggers content
- */
- public static Collection<YamlLoggerConfiguration>
convertYamlLoggerConfigurations(final Collection<ShardingSphereLogger> loggers)
{
- return
loggers.stream().map(SWAPPER::swapToYamlConfiguration).collect(Collectors.toList());
- }
-
- /**
- * Convert to ShardingSphere loggers.
- *
- * @param loggers YAML loggers content
- * @return ShardingSphere loggers
- */
- public static Collection<ShardingSphereLogger>
convertShardingSphereLogger(final Collection<YamlLoggerConfiguration> loggers) {
- return
loggers.stream().map(SWAPPER::swapToObject).collect(Collectors.toList());
- }
-}
diff --git
a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/YamlLoggingRuleConfigurationSwapper.java
b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/YamlLoggingRuleConfigurationSwapper.java
index a9354579c75..a0be8d77015 100644
---
a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/YamlLoggingRuleConfigurationSwapper.java
+++
b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/YamlLoggingRuleConfigurationSwapper.java
@@ -17,31 +17,35 @@
package org.apache.shardingsphere.logging.yaml.swapper;
+import
org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper;
import org.apache.shardingsphere.logging.config.LoggingRuleConfiguration;
import org.apache.shardingsphere.logging.constant.LoggingOrder;
import
org.apache.shardingsphere.logging.rule.builder.DefaultLoggingRuleConfigurationBuilder;
-import
org.apache.shardingsphere.logging.yaml.config.YamlAppendersConfigurationConverter;
-import
org.apache.shardingsphere.logging.yaml.config.YamlLoggersConfigurationConverter;
import
org.apache.shardingsphere.logging.yaml.config.YamlLoggingRuleConfiguration;
-import
org.apache.shardingsphere.infra.yaml.config.swapper.rule.YamlRuleConfigurationSwapper;
+
+import java.util.stream.Collectors;
/**
* YAML logging rule configuration swapper.
*/
public final class YamlLoggingRuleConfigurationSwapper implements
YamlRuleConfigurationSwapper<YamlLoggingRuleConfiguration,
LoggingRuleConfiguration> {
+ private final YamlLoggerSwapper loggerSwapper = new YamlLoggerSwapper();
+
+ private final YamlAppenderSwapper appenderSwapper = new
YamlAppenderSwapper();
+
@Override
public YamlLoggingRuleConfiguration swapToYamlConfiguration(final
LoggingRuleConfiguration data) {
YamlLoggingRuleConfiguration result = new
YamlLoggingRuleConfiguration();
-
result.setLoggers(YamlLoggersConfigurationConverter.convertYamlLoggerConfigurations(data.getLoggers()));
-
result.setAppenders(YamlAppendersConfigurationConverter.convertYamlAppenderConfigurations(data.getAppenders()));
+
result.setLoggers(data.getLoggers().stream().map(loggerSwapper::swapToYamlConfiguration).collect(Collectors.toList()));
+
result.setAppenders(data.getAppenders().stream().map(appenderSwapper::swapToYamlConfiguration).collect(Collectors.toList()));
return result;
}
@Override
public LoggingRuleConfiguration swapToObject(final
YamlLoggingRuleConfiguration yamlConfig) {
- LoggingRuleConfiguration result = new
LoggingRuleConfiguration(YamlLoggersConfigurationConverter.convertShardingSphereLogger(yamlConfig.getLoggers()),
-
YamlAppendersConfigurationConverter.convertShardingSphereAppender(yamlConfig.getAppenders()));
+ LoggingRuleConfiguration result = new
LoggingRuleConfiguration(yamlConfig.getLoggers().stream().map(loggerSwapper::swapToObject).collect(Collectors.toList()),
+
yamlConfig.getAppenders().stream().map(appenderSwapper::swapToObject).collect(Collectors.toList()));
if (null == result.getLoggers()) {
result = getDefaultLoggingRuleConfiguration();
}