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

xiaoyu 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 226a9e2  Move LockStrategy spi load to LockContext (#8720)
226a9e2 is described below

commit 226a9e28b1f431d4e868696bd14a14f423d9149d
Author: Haoran Meng <[email protected]>
AuthorDate: Tue Dec 22 16:48:31 2020 +0800

    Move LockStrategy spi load to LockContext (#8720)
---
 .../org/apache/shardingsphere/infra/lock/LockContext.java   | 13 ++++++++++---
 .../apache/shardingsphere/infra/lock/LockContextTest.java   |  9 +--------
 .../initializer/impl/AbstractBootstrapInitializer.java      | 13 -------------
 .../initializer/impl/GovernanceBootstrapInitializer.java    |  5 ++---
 .../initializer/impl/StandardBootstrapInitializer.java      |  2 +-
 5 files changed, 14 insertions(+), 28 deletions(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockContext.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockContext.java
index 1846c2b..16a0f9b 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockContext.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/lock/LockContext.java
@@ -19,7 +19,10 @@ package org.apache.shardingsphere.infra.lock;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
 
+import java.util.Properties;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.concurrent.locks.Condition;
@@ -38,13 +41,17 @@ public final class LockContext {
     
     private static final Condition CONDITION = LOCK.newCondition();
     
+    static {
+        ShardingSphereServiceLoader.register(LockStrategy.class);
+    }
+    
     /**
      * Init lock strategy.
      *
-     * @param lockStrategy lock strategy
+     * @param lockStrategyType lock strategy type
      */
-    public static void init(final LockStrategy lockStrategy) {
-        LOCK_STRATEGY.set(lockStrategy);
+    public static void init(final LockStrategyType lockStrategyType) {
+        
LOCK_STRATEGY.set(TypedSPIRegistry.getRegisteredService(LockStrategy.class, 
lockStrategyType.name(), new Properties()));
     }
     
     /**
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/LockContextTest.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/LockContextTest.java
index fce1e2c..8b9f871 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/LockContextTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/lock/LockContextTest.java
@@ -17,12 +17,9 @@
 
 package org.apache.shardingsphere.infra.lock;
 
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.util.Properties;
 import java.util.concurrent.TimeUnit;
 
 import static org.junit.Assert.assertNotNull;
@@ -30,13 +27,9 @@ import static org.junit.Assert.assertTrue;
 
 public final class LockContextTest {
     
-    static {
-        ShardingSphereServiceLoader.register(LockStrategy.class);
-    }
-    
     @Before
     public void init() {
-        
LockContext.init(TypedSPIRegistry.getRegisteredService(LockStrategy.class, 
LockStrategyType.STANDARD.name(), new Properties()));
+        LockContext.init(LockStrategyType.STANDARD);
     }
     
     @Test
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
index f41e040..622e9bb 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
@@ -23,11 +23,7 @@ import 
org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
 import 
org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
 import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
 import 
org.apache.shardingsphere.infra.context.metadata.MetaDataContextsBuilder;
-import org.apache.shardingsphere.infra.lock.LockStrategy;
-import org.apache.shardingsphere.infra.lock.LockStrategyType;
 import 
org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
-import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
-import org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.factory.JDBCRawBackendDataSourceFactory;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
@@ -47,7 +43,6 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Optional;
-import java.util.Properties;
 import java.util.stream.Collectors;
 
 /**
@@ -58,10 +53,6 @@ public abstract class AbstractBootstrapInitializer 
implements BootstrapInitializ
     
     private final ShardingSphereProxy shardingSphereProxy = new 
ShardingSphereProxy();
     
-    static {
-        ShardingSphereServiceLoader.register(LockStrategy.class);
-    }
-    
     @Override
     public final void init(final YamlProxyConfiguration yamlConfig, final int 
port) throws SQLException {
         ProxyConfiguration proxyConfig = getProxyConfiguration(yamlConfig);
@@ -127,8 +118,4 @@ public abstract class AbstractBootstrapInitializer 
implements BootstrapInitializ
     protected abstract TransactionContexts 
decorateTransactionContexts(TransactionContexts transactionContexts, String 
xaTransactionMangerType);
     
     protected abstract void initLockContext();
-    
-    protected LockStrategy loadLockStrategy(final LockStrategyType 
lockStrategyType) {
-        return TypedSPIRegistry.getRegisteredService(LockStrategy.class, 
lockStrategyType.name(), new Properties());
-    }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
index 85eba9e..ec7b75a 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/GovernanceBootstrapInitializer.java
@@ -127,8 +127,7 @@ public final class GovernanceBootstrapInitializer extends 
AbstractBootstrapIniti
     
     @Override
     protected void initLockContext() {
-        GovernanceLockStrategy governanceLockStrategy = 
(GovernanceLockStrategy) loadLockStrategy(LockStrategyType.GOVERNANCE);
-        governanceLockStrategy.init(governanceFacade.getRegistryCenter());
-        LockContext.init(governanceLockStrategy);
+        LockContext.init(LockStrategyType.GOVERNANCE);
+        ((GovernanceLockStrategy) 
LockContext.getLockStrategy()).init(governanceFacade.getRegistryCenter());
     }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializer.java
 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializer.java
index d9fda32..6ecc167 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializer.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializer.java
@@ -47,6 +47,6 @@ public final class StandardBootstrapInitializer extends 
AbstractBootstrapInitial
     
     @Override
     protected void initLockContext() {
-        LockContext.init(loadLockStrategy(LockStrategyType.STANDARD));
+        LockContext.init(LockStrategyType.STANDARD);
     }
 }

Reply via email to