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 2022/05/07 12:24:13 UTC
[shardingsphere] branch master updated: Add SPIPropertiesAware (#17428)
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 4bf99241f34 Add SPIPropertiesAware (#17428)
4bf99241f34 is described below
commit 4bf99241f347083fd4914eecd26fa9ca76861f81
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat May 7 20:24:07 2022 +0800
Add SPIPropertiesAware (#17428)
---
.../ClassBasedShardingAlgorithmFactory.java | 4 ++--
.../config/algorithm/ShardingSphereAlgorithm.java | 3 ++-
.../AbstractAlgorithmProvidedBeanRegistry.java | 7 +++----
.../DataConsistencyCalculateAlgorithm.java | 4 ++--
.../mode/persist/PersistRepository.java | 4 ++--
.../SPIMetadataAware.java} | 6 +++---
.../SPIPropertiesAware.java} | 18 ++++--------------
.../spi/lifecycle/SPIPostProcessor.java | 19 -------------------
.../spi/type/typed/TypedSPIRegistry.java | 7 ++++---
9 files changed, 22 insertions(+), 50 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmFactory.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmFactory.java
index fa04e3d5f61..2165fc98903 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmFactory.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/classbased/ClassBasedShardingAlgorithmFactory.java
@@ -22,7 +22,7 @@ import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.sharding.spi.ShardingAlgorithm;
-import org.apache.shardingsphere.spi.lifecycle.SPIPostProcessor;
+import org.apache.shardingsphere.spi.aware.SPIPropertiesAware;
import java.util.Properties;
@@ -54,7 +54,7 @@ public final class ClassBasedShardingAlgorithmFactory {
return instance;
}
- private static <T extends SPIPostProcessor> void setProperties(final T instance, final Properties props) {
+ private static <T extends SPIPropertiesAware> void setProperties(final T instance, final Properties props) {
if (null == props) {
return;
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithm.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithm.java
index 0ec2830496a..16830310024 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithm.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/algorithm/ShardingSphereAlgorithm.java
@@ -17,11 +17,12 @@
package org.apache.shardingsphere.infra.config.algorithm;
+import org.apache.shardingsphere.spi.aware.SPIPropertiesAware;
import org.apache.shardingsphere.spi.lifecycle.SPIPostProcessor;
import org.apache.shardingsphere.spi.type.typed.TypedSPI;
/**
* ShardingSphere algorithm.
*/
-public interface ShardingSphereAlgorithm extends TypedSPI, SPIPostProcessor {
+public interface ShardingSphereAlgorithm extends TypedSPI, SPIPostProcessor, SPIPropertiesAware {
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/registry/AbstractAlgorithmProvidedBeanRegistry.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/registry/AbstractAlgorithmProvidedBeanRegistry.java
index 037b07e95e8..aa2e9ce98e8 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/registry/AbstractAlgorithmProvidedBeanRegistry.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/registry/AbstractAlgorithmProvidedBeanRegistry.java
@@ -22,7 +22,6 @@ import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm;
import org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.spi.lifecycle.SPIPostProcessor;
import org.apache.shardingsphere.spi.type.typed.TypedSPIRegistry;
import org.apache.shardingsphere.spring.boot.util.PropertyUtil;
import org.springframework.beans.factory.config.BeanPostProcessor;
@@ -94,9 +93,9 @@ public abstract class AbstractAlgorithmProvidedBeanRegistry<T extends ShardingSp
@Override
public final Object postProcessAfterInitialization(final Object bean, final String beanName) {
- if (bean instanceof SPIPostProcessor) {
- SPIPostProcessor postProcessor = (SPIPostProcessor) bean;
- postProcessor.init(postProcessor.getProps());
+ if (bean instanceof ShardingSphereAlgorithm) {
+ ShardingSphereAlgorithm algorithm = (ShardingSphereAlgorithm) bean;
+ algorithm.init(algorithm.getProps());
}
return bean;
}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/check/consistency/DataConsistencyCalculateAlgorithm.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/check/consistency/DataConsistencyCalculateAlgorithm.java
index fbcf494e54a..750810cd184 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/check/consistency/DataConsistencyCalculateAlgorithm.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-api/src/main/java/org/apache/shardingsphere/data/pipeline/spi/check/consistency/DataConsistencyCalculateAlgorithm.java
@@ -19,12 +19,12 @@ package org.apache.shardingsphere.data.pipeline.spi.check.consistency;
import org.apache.shardingsphere.data.pipeline.api.check.consistency.DataConsistencyCalculateParameter;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithm;
-import org.apache.shardingsphere.spi.type.typed.TypedSPIMetadataAware;
+import org.apache.shardingsphere.spi.aware.SPIMetadataAware;
/**
* Data consistency calculate algorithm.
*/
-public interface DataConsistencyCalculateAlgorithm extends ShardingSphereAlgorithm, TypedSPIMetadataAware {
+public interface DataConsistencyCalculateAlgorithm extends ShardingSphereAlgorithm, SPIMetadataAware {
/**
* Calculate data for consistency check.
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/persist/PersistRepository.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/persist/PersistRepository.java
index 1fb5c525ded..b30ac2ea4c0 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/persist/PersistRepository.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/persist/PersistRepository.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.mode.persist;
-import org.apache.shardingsphere.spi.lifecycle.SPIPostProcessor;
+import org.apache.shardingsphere.spi.aware.SPIPropertiesAware;
import org.apache.shardingsphere.spi.type.typed.TypedSPI;
import java.util.List;
@@ -25,7 +25,7 @@ import java.util.List;
/**
* Persist repository.
*/
-public interface PersistRepository extends TypedSPI, SPIPostProcessor {
+public interface PersistRepository extends TypedSPI, SPIPropertiesAware {
/**
* Path separator.
diff --git a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/typed/TypedSPIMetadataAware.java b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/aware/SPIMetadataAware.java
similarity index 90%
rename from shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/typed/TypedSPIMetadataAware.java
rename to shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/aware/SPIMetadataAware.java
index bbe8bc38d80..6c933a4b153 100644
--- a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/typed/TypedSPIMetadataAware.java
+++ b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/aware/SPIMetadataAware.java
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.spi.type.typed;
+package org.apache.shardingsphere.spi.aware;
import java.util.Collection;
/**
- * Typed sPI metadata aware.
+ * SPI metadata aware.
*/
-public interface TypedSPIMetadataAware {
+public interface SPIMetadataAware {
/**
* Get supported database types.
diff --git a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/lifecycle/SPIPostProcessor.java b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/aware/SPIPropertiesAware.java
similarity index 73%
copy from shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/lifecycle/SPIPostProcessor.java
copy to shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/aware/SPIPropertiesAware.java
index 39a3a93c0a0..99dac4c0c45 100644
--- a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/lifecycle/SPIPostProcessor.java
+++ b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/aware/SPIPropertiesAware.java
@@ -15,29 +15,20 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.spi.lifecycle;
+package org.apache.shardingsphere.spi.aware;
import java.util.Properties;
/**
- * SPI post processor.
+ * SPI properties aware.
*/
-public interface SPIPostProcessor {
-
- /**
- * Initialize SPI.
- *
- * @param props properties to be initialized
- */
- default void init(Properties props) {
- }
+public interface SPIPropertiesAware {
/**
* Get properties.
- *
+ *
* @return properties
*/
- // TODO consider about to remove it, for spring algorithm only for now
default Properties getProps() {
return new Properties();
}
@@ -47,7 +38,6 @@ public interface SPIPostProcessor {
*
* @param props properties
*/
- // TODO consider about to remove it, for spring algorithm only for now
default void setProps(Properties props) {
}
}
diff --git a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/lifecycle/SPIPostProcessor.java b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/lifecycle/SPIPostProcessor.java
index 39a3a93c0a0..9280409f159 100644
--- a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/lifecycle/SPIPostProcessor.java
+++ b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/lifecycle/SPIPostProcessor.java
@@ -31,23 +31,4 @@ public interface SPIPostProcessor {
*/
default void init(Properties props) {
}
-
- /**
- * Get properties.
- *
- * @return properties
- */
- // TODO consider about to remove it, for spring algorithm only for now
- default Properties getProps() {
- return new Properties();
- }
-
- /**
- * Set properties.
- *
- * @param props properties
- */
- // TODO consider about to remove it, for spring algorithm only for now
- default void setProps(Properties props) {
- }
}
diff --git a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistry.java b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistry.java
index 9e44d81debd..e7ee2e01b28 100644
--- a/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistry.java
+++ b/shardingsphere-spi/src/main/java/org/apache/shardingsphere/spi/type/typed/TypedSPIRegistry.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.spi.type.typed;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.aware.SPIPropertiesAware;
import org.apache.shardingsphere.spi.exception.ServiceProviderNotFoundException;
import org.apache.shardingsphere.spi.lifecycle.SPIPostProcessor;
@@ -64,8 +65,9 @@ public final class TypedSPIRegistry {
// TODO for contains judge only, should fix here
if (null != props && !props.isEmpty() && each instanceof SPIPostProcessor) {
init((SPIPostProcessor) each, props);
- } else if (each instanceof SPIPostProcessor) {
- ((SPIPostProcessor) each).setProps(new Properties());
+ }
+ if (each instanceof SPIPropertiesAware) {
+ ((SPIPropertiesAware) each).setProps(null == props ? new Properties() : props);
}
return Optional.of(each);
}
@@ -81,7 +83,6 @@ public final class TypedSPIRegistry {
Properties newProps = new Properties();
props.forEach((key, value) -> newProps.setProperty(key.toString(), null == value ? null : value.toString()));
spiPostProcessor.init(newProps);
- spiPostProcessor.setProps(newProps);
}
/**