This is an automated email from the ASF dual-hosted git repository.

sunnianjun 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 aff02930792 Merge SPIPostProcessor and TypedSPI (#23739)
aff02930792 is described below

commit aff029307924ff06ff6159e782f11178a0f047c4
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Jan 27 13:50:30 2023 +0800

    Merge SPIPostProcessor and TypedSPI (#23739)
---
 .../infra/algorithm/ShardingSphereAlgorithm.java   |  3 +-
 .../infra/util/spi/lifecycle/SPIPostProcessor.java | 33 ----------------------
 .../infra/util/spi/type/typed/TypedSPI.java        |  9 ++++++
 .../util/spi/type/typed/TypedSPIRegistry.java      | 10 ++-----
 .../spi/type/typed/fixture/TypedSPIFixture.java    |  3 +-
 .../timeservice/spi/ShardingSphereTimeService.java |  3 +-
 .../standalone/StandalonePersistRepository.java    |  3 +-
 7 files changed, 15 insertions(+), 49 deletions(-)

diff --git 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/algorithm/ShardingSphereAlgorithm.java
 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/algorithm/ShardingSphereAlgorithm.java
index 6408c2fcba5..70fd4ca778f 100644
--- 
a/infra/common/src/main/java/org/apache/shardingsphere/infra/algorithm/ShardingSphereAlgorithm.java
+++ 
b/infra/common/src/main/java/org/apache/shardingsphere/infra/algorithm/ShardingSphereAlgorithm.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.infra.algorithm;
 
-import org.apache.shardingsphere.infra.util.spi.lifecycle.SPIPostProcessor;
 import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPI;
 
 import java.util.Properties;
@@ -25,7 +24,7 @@ import java.util.Properties;
 /**
  * ShardingSphere algorithm.
  */
-public interface ShardingSphereAlgorithm extends TypedSPI, SPIPostProcessor {
+public interface ShardingSphereAlgorithm extends TypedSPI {
     
     /**
      * Get properties.
diff --git 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/lifecycle/SPIPostProcessor.java
 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/lifecycle/SPIPostProcessor.java
deleted file mode 100644
index b340c441d66..00000000000
--- 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/lifecycle/SPIPostProcessor.java
+++ /dev/null
@@ -1,33 +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.infra.util.spi.lifecycle;
-
-import java.util.Properties;
-
-/**
- * SPI post processor.
- */
-public interface SPIPostProcessor {
-    
-    /**
-     * Initialize SPI.
-     * 
-     * @param props properties to be initialized
-     */
-    void init(Properties props);
-}
diff --git 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPI.java
 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPI.java
index 3180bf1de2d..882c37758d4 100644
--- 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPI.java
+++ 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPI.java
@@ -19,12 +19,21 @@ package org.apache.shardingsphere.infra.util.spi.type.typed;
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Properties;
 
 /**
  * Typed SPI.
  */
 public interface TypedSPI {
     
+    /**
+     * Initialize SPI.
+     *
+     * @param props properties to be initialized
+     */
+    default void init(Properties props) {
+    }
+    
     /**
      * Get type.
      * 
diff --git 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPIRegistry.java
 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPIRegistry.java
index f92a7bf716a..6f8c18099b4 100644
--- 
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPIRegistry.java
+++ 
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPIRegistry.java
@@ -21,7 +21,6 @@ import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
 import 
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
-import org.apache.shardingsphere.infra.util.spi.lifecycle.SPIPostProcessor;
 
 import java.util.Optional;
 import java.util.Properties;
@@ -73,10 +72,7 @@ public final class TypedSPIRegistry {
     public static <T extends TypedSPI> Optional<T> findService(final Class<T> 
spiClass, final String type, final Properties props) {
         for (T each : 
ShardingSphereServiceLoader.getServiceInstances(spiClass)) {
             if (matchesType(type, each)) {
-                Properties stringTypeProps = 
convertToStringTypedProperties(props);
-                if (each instanceof SPIPostProcessor) {
-                    ((SPIPostProcessor) each).init(stringTypeProps);
-                }
+                each.init(convertToStringTypedProperties(props));
                 return Optional.of(each);
             }
         }
@@ -126,9 +122,7 @@ public final class TypedSPIRegistry {
             if (!each.isDefault()) {
                 continue;
             }
-            if (each instanceof SPIPostProcessor) {
-                ((SPIPostProcessor) each).init(new Properties());
-            }
+            each.init(new Properties());
             return Optional.of(each);
         }
         return Optional.empty();
diff --git 
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/typed/fixture/TypedSPIFixture.java
 
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/typed/fixture/TypedSPIFixture.java
index c781355bf59..27fdcbc7252 100644
--- 
a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/typed/fixture/TypedSPIFixture.java
+++ 
b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/spi/type/typed/fixture/TypedSPIFixture.java
@@ -17,8 +17,7 @@
 
 package org.apache.shardingsphere.infra.util.spi.type.typed.fixture;
 
-import org.apache.shardingsphere.infra.util.spi.lifecycle.SPIPostProcessor;
 import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPI;
 
-public interface TypedSPIFixture extends TypedSPI, SPIPostProcessor {
+public interface TypedSPIFixture extends TypedSPI {
 }
diff --git 
a/kernel/time-service/api/src/main/java/org/apache/shardingsphere/timeservice/spi/ShardingSphereTimeService.java
 
b/kernel/time-service/api/src/main/java/org/apache/shardingsphere/timeservice/spi/ShardingSphereTimeService.java
index 037c03b7ef5..331bb46b810 100644
--- 
a/kernel/time-service/api/src/main/java/org/apache/shardingsphere/timeservice/spi/ShardingSphereTimeService.java
+++ 
b/kernel/time-service/api/src/main/java/org/apache/shardingsphere/timeservice/spi/ShardingSphereTimeService.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.timeservice.spi;
 
-import org.apache.shardingsphere.infra.util.spi.lifecycle.SPIPostProcessor;
 import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPI;
 
 import java.util.Date;
@@ -25,7 +24,7 @@ import java.util.Date;
 /**
  * ShardingSphere time service.
  */
-public interface ShardingSphereTimeService extends TypedSPI, SPIPostProcessor {
+public interface ShardingSphereTimeService extends TypedSPI {
     
     /**
      * Get datetime.
diff --git 
a/mode/type/standalone/repository/api/src/main/java/org/apache/shardingsphere/mode/repository/standalone/StandalonePersistRepository.java
 
b/mode/type/standalone/repository/api/src/main/java/org/apache/shardingsphere/mode/repository/standalone/StandalonePersistRepository.java
index 5f2779ac881..890351da221 100644
--- 
a/mode/type/standalone/repository/api/src/main/java/org/apache/shardingsphere/mode/repository/standalone/StandalonePersistRepository.java
+++ 
b/mode/type/standalone/repository/api/src/main/java/org/apache/shardingsphere/mode/repository/standalone/StandalonePersistRepository.java
@@ -17,11 +17,10 @@
 
 package org.apache.shardingsphere.mode.repository.standalone;
 
-import org.apache.shardingsphere.infra.util.spi.lifecycle.SPIPostProcessor;
 import org.apache.shardingsphere.mode.persist.PersistRepository;
 
 /**
  * Standalone persist repository.
  */
-public interface StandalonePersistRepository extends PersistRepository, 
SPIPostProcessor {
+public interface StandalonePersistRepository extends PersistRepository {
 }

Reply via email to